From 667abf580a6d042f94f8a1d70d2e0035089a820c Mon Sep 17 00:00:00 2001 From: tdakkota Date: Wed, 12 Jun 2024 00:21:33 +0300 Subject: [PATCH 1/4] revert: add support for Free-form Objects when a schema definitions only specifies type: object This reverts commit 9f4ab1949cf2c55754d76624251fb0f418587af7. --- gen/schema_gen.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/gen/schema_gen.go b/gen/schema_gen.go index 8e0ea538a..263164eb5 100644 --- a/gen/schema_gen.go +++ b/gen/schema_gen.go @@ -261,14 +261,12 @@ func (g *schemaGen) generate2(name string, schema *jsonschema.Schema) (ret *ir.T hasProps := len(schema.Properties) > 0 hasAdditionalProps := false denyAdditionalProps := false - hasPatternProps := len(schema.PatternProperties) > 0 - isPatternSingle := len(schema.PatternProperties) == 1 if p := schema.AdditionalProperties; p != nil { hasAdditionalProps = *p denyAdditionalProps = !*p - } else if !hasProps && !hasPatternProps { - hasAdditionalProps = true } + hasPatternProps := len(schema.PatternProperties) > 0 + isPatternSingle := len(schema.PatternProperties) == 1 if !hasProps { if (!hasAdditionalProps && isPatternSingle) || (hasAdditionalProps && !hasPatternProps) { From 3a90e1211045e637d91dfd702e30b4c99808fbee Mon Sep 17 00:00:00 2001 From: tdakkota Date: Wed, 12 Jun 2024 00:22:58 +0300 Subject: [PATCH 2/4] revert: add tests for generating Free-form Objects This reverts commit 91d393c889beeaa1f7df18aef71768587861e9a4. --- _testdata/positive/free_form.json | 42 --- internal/integration/generate.go | 1 - .../integration/test_free_form/oas_cfg_gen.go | 283 ------------------ .../test_free_form/oas_client_gen.go | 221 -------------- .../test_free_form/oas_handlers_gen.go | 202 ------------- .../test_free_form/oas_json_gen.go | 124 -------- .../test_free_form/oas_labeler_gen.go | 42 --- .../test_free_form/oas_middleware_gen.go | 10 - .../oas_request_decoders_gen.go | 3 - .../oas_request_encoders_gen.go | 3 - .../oas_response_decoders_gen.go | 107 ------- .../oas_response_encoders_gen.go | 66 ---- .../test_free_form/oas_router_gen.go | 256 ---------------- .../test_free_form/oas_schemas_gen.go | 81 ----- .../test_free_form/oas_server_gen.go | 38 --- .../test_free_form/oas_unimplemented_gen.go | 28 -- 16 files changed, 1507 deletions(-) delete mode 100644 _testdata/positive/free_form.json delete mode 100644 internal/integration/test_free_form/oas_cfg_gen.go delete mode 100644 internal/integration/test_free_form/oas_client_gen.go delete mode 100644 internal/integration/test_free_form/oas_handlers_gen.go delete mode 100644 internal/integration/test_free_form/oas_json_gen.go delete mode 100644 internal/integration/test_free_form/oas_labeler_gen.go delete mode 100644 internal/integration/test_free_form/oas_middleware_gen.go delete mode 100644 internal/integration/test_free_form/oas_request_decoders_gen.go delete mode 100644 internal/integration/test_free_form/oas_request_encoders_gen.go delete mode 100644 internal/integration/test_free_form/oas_response_decoders_gen.go delete mode 100644 internal/integration/test_free_form/oas_response_encoders_gen.go delete mode 100644 internal/integration/test_free_form/oas_router_gen.go delete mode 100644 internal/integration/test_free_form/oas_schemas_gen.go delete mode 100644 internal/integration/test_free_form/oas_server_gen.go delete mode 100644 internal/integration/test_free_form/oas_unimplemented_gen.go diff --git a/_testdata/positive/free_form.json b/_testdata/positive/free_form.json deleted file mode 100644 index 5aad2341b..000000000 --- a/_testdata/positive/free_form.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "openapi": "3.0.3", - "info": { - "version": "1.0.0", - "title": "Free-Form Object Example" - }, - "paths": { - "/path1": { - "get": { - "operationId": "Path1", - "responses": { - "default": { - "content": { - "application/json": { - "schema": { - "type": "object" - } - } - } - } - } - } - }, - "/path2": { - "get": { - "operationId": "Path2", - "responses": { - "default": { - "content": { - "application/json": { - "schema": { - "type": "object", - "additionalProperties": true - } - } - } - } - } - } - } - } -} \ No newline at end of file diff --git a/internal/integration/generate.go b/internal/integration/generate.go index e61d0cf21..39bd8e222 100644 --- a/internal/integration/generate.go +++ b/internal/integration/generate.go @@ -32,7 +32,6 @@ package integration // //go:generate go run ../../cmd/ogen -v --clean -target test_enum_naming ../../_testdata/positive/enum_naming.yml //go:generate go run ../../cmd/ogen -v --clean -target test_naming_extensions ../../_testdata/positive/naming_extensions.json -//go:generate go run ../../cmd/ogen -v --clean -target test_free_form ../../_testdata/positive/free_form.json // // Regression test. // diff --git a/internal/integration/test_free_form/oas_cfg_gen.go b/internal/integration/test_free_form/oas_cfg_gen.go deleted file mode 100644 index fc3ff3449..000000000 --- a/internal/integration/test_free_form/oas_cfg_gen.go +++ /dev/null @@ -1,283 +0,0 @@ -// Code generated by ogen, DO NOT EDIT. - -package api - -import ( - "net/http" - - "go.opentelemetry.io/otel" - "go.opentelemetry.io/otel/metric" - "go.opentelemetry.io/otel/trace" - - ht "github.com/ogen-go/ogen/http" - "github.com/ogen-go/ogen/middleware" - "github.com/ogen-go/ogen/ogenerrors" - "github.com/ogen-go/ogen/otelogen" -) - -var ( - // Allocate option closure once. - clientSpanKind = trace.WithSpanKind(trace.SpanKindClient) - // Allocate option closure once. - serverSpanKind = trace.WithSpanKind(trace.SpanKindServer) -) - -type ( - optionFunc[C any] func(*C) - otelOptionFunc func(*otelConfig) -) - -type otelConfig struct { - TracerProvider trace.TracerProvider - Tracer trace.Tracer - MeterProvider metric.MeterProvider - Meter metric.Meter -} - -func (cfg *otelConfig) initOTEL() { - if cfg.TracerProvider == nil { - cfg.TracerProvider = otel.GetTracerProvider() - } - if cfg.MeterProvider == nil { - cfg.MeterProvider = otel.GetMeterProvider() - } - cfg.Tracer = cfg.TracerProvider.Tracer(otelogen.Name, - trace.WithInstrumentationVersion(otelogen.SemVersion()), - ) - cfg.Meter = cfg.MeterProvider.Meter(otelogen.Name, - metric.WithInstrumentationVersion(otelogen.SemVersion()), - ) -} - -// ErrorHandler is error handler. -type ErrorHandler = ogenerrors.ErrorHandler - -type serverConfig struct { - otelConfig - NotFound http.HandlerFunc - MethodNotAllowed func(w http.ResponseWriter, r *http.Request, allowed string) - ErrorHandler ErrorHandler - Prefix string - Middleware Middleware - MaxMultipartMemory int64 -} - -// ServerOption is server config option. -type ServerOption interface { - applyServer(*serverConfig) -} - -var _ ServerOption = (optionFunc[serverConfig])(nil) - -func (o optionFunc[C]) applyServer(c *C) { - o(c) -} - -var _ ServerOption = (otelOptionFunc)(nil) - -func (o otelOptionFunc) applyServer(c *serverConfig) { - o(&c.otelConfig) -} - -func newServerConfig(opts ...ServerOption) serverConfig { - cfg := serverConfig{ - NotFound: http.NotFound, - MethodNotAllowed: func(w http.ResponseWriter, r *http.Request, allowed string) { - status := http.StatusMethodNotAllowed - if r.Method == "OPTIONS" { - w.Header().Set("Access-Control-Allow-Methods", allowed) - w.Header().Set("Access-Control-Allow-Headers", "Content-Type") - status = http.StatusNoContent - } else { - w.Header().Set("Allow", allowed) - } - w.WriteHeader(status) - }, - ErrorHandler: ogenerrors.DefaultErrorHandler, - Middleware: nil, - MaxMultipartMemory: 32 << 20, // 32 MB - } - for _, opt := range opts { - opt.applyServer(&cfg) - } - cfg.initOTEL() - return cfg -} - -type baseServer struct { - cfg serverConfig - requests metric.Int64Counter - errors metric.Int64Counter - duration metric.Float64Histogram -} - -func (s baseServer) notFound(w http.ResponseWriter, r *http.Request) { - s.cfg.NotFound(w, r) -} - -func (s baseServer) notAllowed(w http.ResponseWriter, r *http.Request, allowed string) { - s.cfg.MethodNotAllowed(w, r, allowed) -} - -func (cfg serverConfig) baseServer() (s baseServer, err error) { - s = baseServer{cfg: cfg} - if s.requests, err = otelogen.ServerRequestCountCounter(s.cfg.Meter); err != nil { - return s, err - } - if s.errors, err = otelogen.ServerErrorsCountCounter(s.cfg.Meter); err != nil { - return s, err - } - if s.duration, err = otelogen.ServerDurationHistogram(s.cfg.Meter); err != nil { - return s, err - } - return s, nil -} - -type clientConfig struct { - otelConfig - Client ht.Client -} - -// ClientOption is client config option. -type ClientOption interface { - applyClient(*clientConfig) -} - -var _ ClientOption = (optionFunc[clientConfig])(nil) - -func (o optionFunc[C]) applyClient(c *C) { - o(c) -} - -var _ ClientOption = (otelOptionFunc)(nil) - -func (o otelOptionFunc) applyClient(c *clientConfig) { - o(&c.otelConfig) -} - -func newClientConfig(opts ...ClientOption) clientConfig { - cfg := clientConfig{ - Client: http.DefaultClient, - } - for _, opt := range opts { - opt.applyClient(&cfg) - } - cfg.initOTEL() - return cfg -} - -type baseClient struct { - cfg clientConfig - requests metric.Int64Counter - errors metric.Int64Counter - duration metric.Float64Histogram -} - -func (cfg clientConfig) baseClient() (c baseClient, err error) { - c = baseClient{cfg: cfg} - if c.requests, err = otelogen.ClientRequestCountCounter(c.cfg.Meter); err != nil { - return c, err - } - if c.errors, err = otelogen.ClientErrorsCountCounter(c.cfg.Meter); err != nil { - return c, err - } - if c.duration, err = otelogen.ClientDurationHistogram(c.cfg.Meter); err != nil { - return c, err - } - return c, nil -} - -// Option is config option. -type Option interface { - ServerOption - ClientOption -} - -// WithTracerProvider specifies a tracer provider to use for creating a tracer. -// -// If none is specified, the global provider is used. -func WithTracerProvider(provider trace.TracerProvider) Option { - return otelOptionFunc(func(cfg *otelConfig) { - if provider != nil { - cfg.TracerProvider = provider - } - }) -} - -// WithMeterProvider specifies a meter provider to use for creating a meter. -// -// If none is specified, the otel.GetMeterProvider() is used. -func WithMeterProvider(provider metric.MeterProvider) Option { - return otelOptionFunc(func(cfg *otelConfig) { - if provider != nil { - cfg.MeterProvider = provider - } - }) -} - -// WithClient specifies http client to use. -func WithClient(client ht.Client) ClientOption { - return optionFunc[clientConfig](func(cfg *clientConfig) { - if client != nil { - cfg.Client = client - } - }) -} - -// WithNotFound specifies Not Found handler to use. -func WithNotFound(notFound http.HandlerFunc) ServerOption { - return optionFunc[serverConfig](func(cfg *serverConfig) { - if notFound != nil { - cfg.NotFound = notFound - } - }) -} - -// WithMethodNotAllowed specifies Method Not Allowed handler to use. -func WithMethodNotAllowed(methodNotAllowed func(w http.ResponseWriter, r *http.Request, allowed string)) ServerOption { - return optionFunc[serverConfig](func(cfg *serverConfig) { - if methodNotAllowed != nil { - cfg.MethodNotAllowed = methodNotAllowed - } - }) -} - -// WithErrorHandler specifies error handler to use. -func WithErrorHandler(h ErrorHandler) ServerOption { - return optionFunc[serverConfig](func(cfg *serverConfig) { - if h != nil { - cfg.ErrorHandler = h - } - }) -} - -// WithPathPrefix specifies server path prefix. -func WithPathPrefix(prefix string) ServerOption { - return optionFunc[serverConfig](func(cfg *serverConfig) { - cfg.Prefix = prefix - }) -} - -// WithMiddleware specifies middlewares to use. -func WithMiddleware(m ...Middleware) ServerOption { - return optionFunc[serverConfig](func(cfg *serverConfig) { - switch len(m) { - case 0: - cfg.Middleware = nil - case 1: - cfg.Middleware = m[0] - default: - cfg.Middleware = middleware.ChainMiddlewares(m...) - } - }) -} - -// WithMaxMultipartMemory specifies limit of memory for storing file parts. -// File parts which can't be stored in memory will be stored on disk in temporary files. -func WithMaxMultipartMemory(max int64) ServerOption { - return optionFunc[serverConfig](func(cfg *serverConfig) { - if max > 0 { - cfg.MaxMultipartMemory = max - } - }) -} diff --git a/internal/integration/test_free_form/oas_client_gen.go b/internal/integration/test_free_form/oas_client_gen.go deleted file mode 100644 index 68d3fc756..000000000 --- a/internal/integration/test_free_form/oas_client_gen.go +++ /dev/null @@ -1,221 +0,0 @@ -// Code generated by ogen, DO NOT EDIT. - -package api - -import ( - "context" - "net/url" - "strings" - "time" - - "github.com/go-faster/errors" - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/codes" - "go.opentelemetry.io/otel/metric" - semconv "go.opentelemetry.io/otel/semconv/v1.19.0" - "go.opentelemetry.io/otel/trace" - - ht "github.com/ogen-go/ogen/http" - "github.com/ogen-go/ogen/otelogen" - "github.com/ogen-go/ogen/uri" -) - -// Invoker invokes operations described by OpenAPI v3 specification. -type Invoker interface { - // Path1 invokes Path1 operation. - // - // GET /path1 - Path1(ctx context.Context) (*Path1DefStatusCode, error) - // Path2 invokes Path2 operation. - // - // GET /path2 - Path2(ctx context.Context) (*Path2DefStatusCode, error) -} - -// Client implements OAS client. -type Client struct { - serverURL *url.URL - baseClient -} - -var _ Handler = struct { - *Client -}{} - -func trimTrailingSlashes(u *url.URL) { - u.Path = strings.TrimRight(u.Path, "/") - u.RawPath = strings.TrimRight(u.RawPath, "/") -} - -// NewClient initializes new Client defined by OAS. -func NewClient(serverURL string, opts ...ClientOption) (*Client, error) { - u, err := url.Parse(serverURL) - if err != nil { - return nil, err - } - trimTrailingSlashes(u) - - c, err := newClientConfig(opts...).baseClient() - if err != nil { - return nil, err - } - return &Client{ - serverURL: u, - baseClient: c, - }, nil -} - -type serverURLKey struct{} - -// WithServerURL sets context key to override server URL. -func WithServerURL(ctx context.Context, u *url.URL) context.Context { - return context.WithValue(ctx, serverURLKey{}, u) -} - -func (c *Client) requestURL(ctx context.Context) *url.URL { - u, ok := ctx.Value(serverURLKey{}).(*url.URL) - if !ok { - return c.serverURL - } - return u -} - -// Path1 invokes Path1 operation. -// -// GET /path1 -func (c *Client) Path1(ctx context.Context) (*Path1DefStatusCode, error) { - res, err := c.sendPath1(ctx) - return res, err -} - -func (c *Client) sendPath1(ctx context.Context) (res *Path1DefStatusCode, err error) { - otelAttrs := []attribute.KeyValue{ - otelogen.OperationID("Path1"), - semconv.HTTPMethodKey.String("GET"), - semconv.HTTPRouteKey.String("/path1"), - } - - // Run stopwatch. - startTime := time.Now() - defer func() { - // Use floating point division here for higher precision (instead of Millisecond method). - elapsedDuration := time.Since(startTime) - c.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), metric.WithAttributes(otelAttrs...)) - }() - - // Increment request counter. - c.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) - - // Start a span for this request. - ctx, span := c.cfg.Tracer.Start(ctx, "Path1", - trace.WithAttributes(otelAttrs...), - clientSpanKind, - ) - // Track stage for error reporting. - var stage string - defer func() { - if err != nil { - span.RecordError(err) - span.SetStatus(codes.Error, stage) - c.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) - } - span.End() - }() - - stage = "BuildURL" - u := uri.Clone(c.requestURL(ctx)) - var pathParts [1]string - pathParts[0] = "/path1" - uri.AddPathParts(u, pathParts[:]...) - - stage = "EncodeRequest" - r, err := ht.NewRequest(ctx, "GET", u) - if err != nil { - return res, errors.Wrap(err, "create request") - } - - stage = "SendRequest" - resp, err := c.cfg.Client.Do(r) - if err != nil { - return res, errors.Wrap(err, "do request") - } - defer resp.Body.Close() - - stage = "DecodeResponse" - result, err := decodePath1Response(resp) - if err != nil { - return res, errors.Wrap(err, "decode response") - } - - return result, nil -} - -// Path2 invokes Path2 operation. -// -// GET /path2 -func (c *Client) Path2(ctx context.Context) (*Path2DefStatusCode, error) { - res, err := c.sendPath2(ctx) - return res, err -} - -func (c *Client) sendPath2(ctx context.Context) (res *Path2DefStatusCode, err error) { - otelAttrs := []attribute.KeyValue{ - otelogen.OperationID("Path2"), - semconv.HTTPMethodKey.String("GET"), - semconv.HTTPRouteKey.String("/path2"), - } - - // Run stopwatch. - startTime := time.Now() - defer func() { - // Use floating point division here for higher precision (instead of Millisecond method). - elapsedDuration := time.Since(startTime) - c.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), metric.WithAttributes(otelAttrs...)) - }() - - // Increment request counter. - c.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) - - // Start a span for this request. - ctx, span := c.cfg.Tracer.Start(ctx, "Path2", - trace.WithAttributes(otelAttrs...), - clientSpanKind, - ) - // Track stage for error reporting. - var stage string - defer func() { - if err != nil { - span.RecordError(err) - span.SetStatus(codes.Error, stage) - c.errors.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) - } - span.End() - }() - - stage = "BuildURL" - u := uri.Clone(c.requestURL(ctx)) - var pathParts [1]string - pathParts[0] = "/path2" - uri.AddPathParts(u, pathParts[:]...) - - stage = "EncodeRequest" - r, err := ht.NewRequest(ctx, "GET", u) - if err != nil { - return res, errors.Wrap(err, "create request") - } - - stage = "SendRequest" - resp, err := c.cfg.Client.Do(r) - if err != nil { - return res, errors.Wrap(err, "do request") - } - defer resp.Body.Close() - - stage = "DecodeResponse" - result, err := decodePath2Response(resp) - if err != nil { - return res, errors.Wrap(err, "decode response") - } - - return result, nil -} diff --git a/internal/integration/test_free_form/oas_handlers_gen.go b/internal/integration/test_free_form/oas_handlers_gen.go deleted file mode 100644 index 1c9fcafff..000000000 --- a/internal/integration/test_free_form/oas_handlers_gen.go +++ /dev/null @@ -1,202 +0,0 @@ -// Code generated by ogen, DO NOT EDIT. - -package api - -import ( - "context" - "net/http" - "time" - - "github.com/go-faster/errors" - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/codes" - "go.opentelemetry.io/otel/metric" - semconv "go.opentelemetry.io/otel/semconv/v1.19.0" - "go.opentelemetry.io/otel/trace" - - ht "github.com/ogen-go/ogen/http" - "github.com/ogen-go/ogen/middleware" - "github.com/ogen-go/ogen/otelogen" -) - -// handlePath1Request handles Path1 operation. -// -// GET /path1 -func (s *Server) handlePath1Request(args [0]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) { - otelAttrs := []attribute.KeyValue{ - otelogen.OperationID("Path1"), - semconv.HTTPMethodKey.String("GET"), - semconv.HTTPRouteKey.String("/path1"), - } - - // Start a span for this request. - ctx, span := s.cfg.Tracer.Start(r.Context(), "Path1", - trace.WithAttributes(otelAttrs...), - serverSpanKind, - ) - defer span.End() - - // Add Labeler to context. - labeler := &Labeler{attrs: otelAttrs} - ctx = contextWithLabeler(ctx, labeler) - - // Run stopwatch. - startTime := time.Now() - defer func() { - elapsedDuration := time.Since(startTime) - attrOpt := metric.WithAttributeSet(labeler.AttributeSet()) - - // Increment request counter. - s.requests.Add(ctx, 1, attrOpt) - - // Use floating point division here for higher precision (instead of Millisecond method). - s.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), attrOpt) - }() - - var ( - recordError = func(stage string, err error) { - span.RecordError(err) - span.SetStatus(codes.Error, stage) - s.errors.Add(ctx, 1, metric.WithAttributeSet(labeler.AttributeSet())) - } - err error - ) - - var response *Path1DefStatusCode - if m := s.cfg.Middleware; m != nil { - mreq := middleware.Request{ - Context: ctx, - OperationName: "Path1", - OperationSummary: "", - OperationID: "Path1", - Body: nil, - Params: middleware.Parameters{}, - Raw: r, - } - - type ( - Request = struct{} - Params = struct{} - Response = *Path1DefStatusCode - ) - response, err = middleware.HookMiddleware[ - Request, - Params, - Response, - ]( - m, - mreq, - nil, - func(ctx context.Context, request Request, params Params) (response Response, err error) { - response, err = s.h.Path1(ctx) - return response, err - }, - ) - } else { - response, err = s.h.Path1(ctx) - } - if err != nil { - defer recordError("Internal", err) - s.cfg.ErrorHandler(ctx, w, r, err) - return - } - - if err := encodePath1Response(response, w, span); err != nil { - defer recordError("EncodeResponse", err) - if !errors.Is(err, ht.ErrInternalServerErrorResponse) { - s.cfg.ErrorHandler(ctx, w, r, err) - } - return - } -} - -// handlePath2Request handles Path2 operation. -// -// GET /path2 -func (s *Server) handlePath2Request(args [0]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) { - otelAttrs := []attribute.KeyValue{ - otelogen.OperationID("Path2"), - semconv.HTTPMethodKey.String("GET"), - semconv.HTTPRouteKey.String("/path2"), - } - - // Start a span for this request. - ctx, span := s.cfg.Tracer.Start(r.Context(), "Path2", - trace.WithAttributes(otelAttrs...), - serverSpanKind, - ) - defer span.End() - - // Add Labeler to context. - labeler := &Labeler{attrs: otelAttrs} - ctx = contextWithLabeler(ctx, labeler) - - // Run stopwatch. - startTime := time.Now() - defer func() { - elapsedDuration := time.Since(startTime) - attrOpt := metric.WithAttributeSet(labeler.AttributeSet()) - - // Increment request counter. - s.requests.Add(ctx, 1, attrOpt) - - // Use floating point division here for higher precision (instead of Millisecond method). - s.duration.Record(ctx, float64(float64(elapsedDuration)/float64(time.Millisecond)), attrOpt) - }() - - var ( - recordError = func(stage string, err error) { - span.RecordError(err) - span.SetStatus(codes.Error, stage) - s.errors.Add(ctx, 1, metric.WithAttributeSet(labeler.AttributeSet())) - } - err error - ) - - var response *Path2DefStatusCode - if m := s.cfg.Middleware; m != nil { - mreq := middleware.Request{ - Context: ctx, - OperationName: "Path2", - OperationSummary: "", - OperationID: "Path2", - Body: nil, - Params: middleware.Parameters{}, - Raw: r, - } - - type ( - Request = struct{} - Params = struct{} - Response = *Path2DefStatusCode - ) - response, err = middleware.HookMiddleware[ - Request, - Params, - Response, - ]( - m, - mreq, - nil, - func(ctx context.Context, request Request, params Params) (response Response, err error) { - response, err = s.h.Path2(ctx) - return response, err - }, - ) - } else { - response, err = s.h.Path2(ctx) - } - if err != nil { - defer recordError("Internal", err) - s.cfg.ErrorHandler(ctx, w, r, err) - return - } - - if err := encodePath2Response(response, w, span); err != nil { - defer recordError("EncodeResponse", err) - if !errors.Is(err, ht.ErrInternalServerErrorResponse) { - s.cfg.ErrorHandler(ctx, w, r, err) - } - return - } -} diff --git a/internal/integration/test_free_form/oas_json_gen.go b/internal/integration/test_free_form/oas_json_gen.go deleted file mode 100644 index 4a2eb40a0..000000000 --- a/internal/integration/test_free_form/oas_json_gen.go +++ /dev/null @@ -1,124 +0,0 @@ -// Code generated by ogen, DO NOT EDIT. - -package api - -import ( - "github.com/go-faster/errors" - "github.com/go-faster/jx" -) - -// Encode implements json.Marshaler. -func (s Path1Def) Encode(e *jx.Encoder) { - e.ObjStart() - s.encodeFields(e) - e.ObjEnd() -} - -// encodeFields implements json.Marshaler. -func (s Path1Def) encodeFields(e *jx.Encoder) { - for k, elem := range s { - e.FieldStart(k) - - if len(elem) != 0 { - e.Raw(elem) - } - } -} - -// Decode decodes Path1Def from json. -func (s *Path1Def) Decode(d *jx.Decoder) error { - if s == nil { - return errors.New("invalid: unable to decode Path1Def to nil") - } - m := s.init() - if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { - var elem jx.Raw - if err := func() error { - v, err := d.RawAppend(nil) - elem = jx.Raw(v) - if err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrapf(err, "decode field %q", k) - } - m[string(k)] = elem - return nil - }); err != nil { - return errors.Wrap(err, "decode Path1Def") - } - - return nil -} - -// MarshalJSON implements stdjson.Marshaler. -func (s Path1Def) MarshalJSON() ([]byte, error) { - e := jx.Encoder{} - s.Encode(&e) - return e.Bytes(), nil -} - -// UnmarshalJSON implements stdjson.Unmarshaler. -func (s *Path1Def) UnmarshalJSON(data []byte) error { - d := jx.DecodeBytes(data) - return s.Decode(d) -} - -// Encode implements json.Marshaler. -func (s Path2Def) Encode(e *jx.Encoder) { - e.ObjStart() - s.encodeFields(e) - e.ObjEnd() -} - -// encodeFields implements json.Marshaler. -func (s Path2Def) encodeFields(e *jx.Encoder) { - for k, elem := range s { - e.FieldStart(k) - - if len(elem) != 0 { - e.Raw(elem) - } - } -} - -// Decode decodes Path2Def from json. -func (s *Path2Def) Decode(d *jx.Decoder) error { - if s == nil { - return errors.New("invalid: unable to decode Path2Def to nil") - } - m := s.init() - if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { - var elem jx.Raw - if err := func() error { - v, err := d.RawAppend(nil) - elem = jx.Raw(v) - if err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrapf(err, "decode field %q", k) - } - m[string(k)] = elem - return nil - }); err != nil { - return errors.Wrap(err, "decode Path2Def") - } - - return nil -} - -// MarshalJSON implements stdjson.Marshaler. -func (s Path2Def) MarshalJSON() ([]byte, error) { - e := jx.Encoder{} - s.Encode(&e) - return e.Bytes(), nil -} - -// UnmarshalJSON implements stdjson.Unmarshaler. -func (s *Path2Def) UnmarshalJSON(data []byte) error { - d := jx.DecodeBytes(data) - return s.Decode(d) -} diff --git a/internal/integration/test_free_form/oas_labeler_gen.go b/internal/integration/test_free_form/oas_labeler_gen.go deleted file mode 100644 index 7e519e84e..000000000 --- a/internal/integration/test_free_form/oas_labeler_gen.go +++ /dev/null @@ -1,42 +0,0 @@ -// Code generated by ogen, DO NOT EDIT. - -package api - -import ( - "context" - - "go.opentelemetry.io/otel/attribute" -) - -// Labeler is used to allow adding custom attributes to the server request metrics. -type Labeler struct { - attrs []attribute.KeyValue -} - -// Add attributes to the Labeler. -func (l *Labeler) Add(attrs ...attribute.KeyValue) { - l.attrs = append(l.attrs, attrs...) -} - -// AttributeSet returns the attributes added to the Labeler as an attribute.Set. -func (l *Labeler) AttributeSet() attribute.Set { - return attribute.NewSet(l.attrs...) -} - -type labelerContextKey struct{} - -// LabelerFromContext retrieves the Labeler from the provided context, if present. -// -// If no Labeler was found in the provided context a new, empty Labeler is returned and the second -// return value is false. In this case it is safe to use the Labeler but any attributes added to -// it will not be used. -func LabelerFromContext(ctx context.Context) (*Labeler, bool) { - if l, ok := ctx.Value(labelerContextKey{}).(*Labeler); ok { - return l, true - } - return &Labeler{}, false -} - -func contextWithLabeler(ctx context.Context, l *Labeler) context.Context { - return context.WithValue(ctx, labelerContextKey{}, l) -} diff --git a/internal/integration/test_free_form/oas_middleware_gen.go b/internal/integration/test_free_form/oas_middleware_gen.go deleted file mode 100644 index 6f58a1a79..000000000 --- a/internal/integration/test_free_form/oas_middleware_gen.go +++ /dev/null @@ -1,10 +0,0 @@ -// Code generated by ogen, DO NOT EDIT. - -package api - -import ( - "github.com/ogen-go/ogen/middleware" -) - -// Middleware is middleware type. -type Middleware = middleware.Middleware diff --git a/internal/integration/test_free_form/oas_request_decoders_gen.go b/internal/integration/test_free_form/oas_request_decoders_gen.go deleted file mode 100644 index ae379a2db..000000000 --- a/internal/integration/test_free_form/oas_request_decoders_gen.go +++ /dev/null @@ -1,3 +0,0 @@ -// Code generated by ogen, DO NOT EDIT. - -package api diff --git a/internal/integration/test_free_form/oas_request_encoders_gen.go b/internal/integration/test_free_form/oas_request_encoders_gen.go deleted file mode 100644 index ae379a2db..000000000 --- a/internal/integration/test_free_form/oas_request_encoders_gen.go +++ /dev/null @@ -1,3 +0,0 @@ -// Code generated by ogen, DO NOT EDIT. - -package api diff --git a/internal/integration/test_free_form/oas_response_decoders_gen.go b/internal/integration/test_free_form/oas_response_decoders_gen.go deleted file mode 100644 index 65748a6e7..000000000 --- a/internal/integration/test_free_form/oas_response_decoders_gen.go +++ /dev/null @@ -1,107 +0,0 @@ -// Code generated by ogen, DO NOT EDIT. - -package api - -import ( - "io" - "mime" - "net/http" - - "github.com/go-faster/errors" - "github.com/go-faster/jx" - - "github.com/ogen-go/ogen/ogenerrors" - "github.com/ogen-go/ogen/validate" -) - -func decodePath1Response(resp *http.Response) (res *Path1DefStatusCode, _ error) { - // Default response. - res, err := func() (res *Path1DefStatusCode, err error) { - ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) - if err != nil { - return res, errors.Wrap(err, "parse media type") - } - switch { - case ct == "application/json": - buf, err := io.ReadAll(resp.Body) - if err != nil { - return res, err - } - d := jx.DecodeBytes(buf) - - var response Path1Def - if err := func() error { - if err := response.Decode(d); err != nil { - return err - } - if err := d.Skip(); err != io.EOF { - return errors.New("unexpected trailing data") - } - return nil - }(); err != nil { - err = &ogenerrors.DecodeBodyError{ - ContentType: ct, - Body: buf, - Err: err, - } - return res, err - } - return &Path1DefStatusCode{ - StatusCode: resp.StatusCode, - Response: response, - }, nil - default: - return res, validate.InvalidContentType(ct) - } - }() - if err != nil { - return res, errors.Wrapf(err, "default (code %d)", resp.StatusCode) - } - return res, nil -} - -func decodePath2Response(resp *http.Response) (res *Path2DefStatusCode, _ error) { - // Default response. - res, err := func() (res *Path2DefStatusCode, err error) { - ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) - if err != nil { - return res, errors.Wrap(err, "parse media type") - } - switch { - case ct == "application/json": - buf, err := io.ReadAll(resp.Body) - if err != nil { - return res, err - } - d := jx.DecodeBytes(buf) - - var response Path2Def - if err := func() error { - if err := response.Decode(d); err != nil { - return err - } - if err := d.Skip(); err != io.EOF { - return errors.New("unexpected trailing data") - } - return nil - }(); err != nil { - err = &ogenerrors.DecodeBodyError{ - ContentType: ct, - Body: buf, - Err: err, - } - return res, err - } - return &Path2DefStatusCode{ - StatusCode: resp.StatusCode, - Response: response, - }, nil - default: - return res, validate.InvalidContentType(ct) - } - }() - if err != nil { - return res, errors.Wrapf(err, "default (code %d)", resp.StatusCode) - } - return res, nil -} diff --git a/internal/integration/test_free_form/oas_response_encoders_gen.go b/internal/integration/test_free_form/oas_response_encoders_gen.go deleted file mode 100644 index 0c0d9c253..000000000 --- a/internal/integration/test_free_form/oas_response_encoders_gen.go +++ /dev/null @@ -1,66 +0,0 @@ -// Code generated by ogen, DO NOT EDIT. - -package api - -import ( - "net/http" - - "github.com/go-faster/errors" - "github.com/go-faster/jx" - "go.opentelemetry.io/otel/codes" - "go.opentelemetry.io/otel/trace" - - ht "github.com/ogen-go/ogen/http" -) - -func encodePath1Response(response *Path1DefStatusCode, w http.ResponseWriter, span trace.Span) error { - w.Header().Set("Content-Type", "application/json; charset=utf-8") - code := response.StatusCode - if code == 0 { - // Set default status code. - code = http.StatusOK - } - w.WriteHeader(code) - if st := http.StatusText(code); code >= http.StatusBadRequest { - span.SetStatus(codes.Error, st) - } else { - span.SetStatus(codes.Ok, st) - } - - e := new(jx.Encoder) - response.Response.Encode(e) - if _, err := e.WriteTo(w); err != nil { - return errors.Wrap(err, "write") - } - - if code >= http.StatusInternalServerError { - return errors.Wrapf(ht.ErrInternalServerErrorResponse, "code: %d, message: %s", code, http.StatusText(code)) - } - return nil -} - -func encodePath2Response(response *Path2DefStatusCode, w http.ResponseWriter, span trace.Span) error { - w.Header().Set("Content-Type", "application/json; charset=utf-8") - code := response.StatusCode - if code == 0 { - // Set default status code. - code = http.StatusOK - } - w.WriteHeader(code) - if st := http.StatusText(code); code >= http.StatusBadRequest { - span.SetStatus(codes.Error, st) - } else { - span.SetStatus(codes.Ok, st) - } - - e := new(jx.Encoder) - response.Response.Encode(e) - if _, err := e.WriteTo(w); err != nil { - return errors.Wrap(err, "write") - } - - if code >= http.StatusInternalServerError { - return errors.Wrapf(ht.ErrInternalServerErrorResponse, "code: %d, message: %s", code, http.StatusText(code)) - } - return nil -} diff --git a/internal/integration/test_free_form/oas_router_gen.go b/internal/integration/test_free_form/oas_router_gen.go deleted file mode 100644 index b652d21a2..000000000 --- a/internal/integration/test_free_form/oas_router_gen.go +++ /dev/null @@ -1,256 +0,0 @@ -// Code generated by ogen, DO NOT EDIT. - -package api - -import ( - "net/http" - "net/url" - "strings" - - "github.com/ogen-go/ogen/uri" -) - -func (s *Server) cutPrefix(path string) (string, bool) { - prefix := s.cfg.Prefix - if prefix == "" { - return path, true - } - if !strings.HasPrefix(path, prefix) { - // Prefix doesn't match. - return "", false - } - // Cut prefix from the path. - return strings.TrimPrefix(path, prefix), true -} - -// ServeHTTP serves http request as defined by OpenAPI v3 specification, -// calling handler that matches the path or returning not found error. -func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { - elem := r.URL.Path - elemIsEscaped := false - if rawPath := r.URL.RawPath; rawPath != "" { - if normalized, ok := uri.NormalizeEscapedPath(rawPath); ok { - elem = normalized - elemIsEscaped = strings.ContainsRune(elem, '%') - } - } - - elem, ok := s.cutPrefix(elem) - if !ok || len(elem) == 0 { - s.notFound(w, r) - return - } - - // Static code generated router with unwrapped path search. - switch { - default: - if len(elem) == 0 { - break - } - switch elem[0] { - case '/': // Prefix: "/path" - origElem := elem - if l := len("/path"); len(elem) >= l && elem[0:l] == "/path" { - elem = elem[l:] - } else { - break - } - - if len(elem) == 0 { - break - } - switch elem[0] { - case '1': // Prefix: "1" - origElem := elem - if l := len("1"); len(elem) >= l && elem[0:l] == "1" { - elem = elem[l:] - } else { - break - } - - if len(elem) == 0 { - // Leaf node. - switch r.Method { - case "GET": - s.handlePath1Request([0]string{}, elemIsEscaped, w, r) - default: - s.notAllowed(w, r, "GET") - } - - return - } - - elem = origElem - case '2': // Prefix: "2" - origElem := elem - if l := len("2"); len(elem) >= l && elem[0:l] == "2" { - elem = elem[l:] - } else { - break - } - - if len(elem) == 0 { - // Leaf node. - switch r.Method { - case "GET": - s.handlePath2Request([0]string{}, elemIsEscaped, w, r) - default: - s.notAllowed(w, r, "GET") - } - - return - } - - elem = origElem - } - - elem = origElem - } - } - s.notFound(w, r) -} - -// Route is route object. -type Route struct { - name string - summary string - operationID string - pathPattern string - count int - args [0]string -} - -// Name returns ogen operation name. -// -// It is guaranteed to be unique and not empty. -func (r Route) Name() string { - return r.name -} - -// Summary returns OpenAPI summary. -func (r Route) Summary() string { - return r.summary -} - -// OperationID returns OpenAPI operationId. -func (r Route) OperationID() string { - return r.operationID -} - -// PathPattern returns OpenAPI path. -func (r Route) PathPattern() string { - return r.pathPattern -} - -// Args returns parsed arguments. -func (r Route) Args() []string { - return r.args[:r.count] -} - -// FindRoute finds Route for given method and path. -// -// Note: this method does not unescape path or handle reserved characters in path properly. Use FindPath instead. -func (s *Server) FindRoute(method, path string) (Route, bool) { - return s.FindPath(method, &url.URL{Path: path}) -} - -// FindPath finds Route for given method and URL. -func (s *Server) FindPath(method string, u *url.URL) (r Route, _ bool) { - var ( - elem = u.Path - args = r.args - ) - if rawPath := u.RawPath; rawPath != "" { - if normalized, ok := uri.NormalizeEscapedPath(rawPath); ok { - elem = normalized - } - defer func() { - for i, arg := range r.args[:r.count] { - if unescaped, err := url.PathUnescape(arg); err == nil { - r.args[i] = unescaped - } - } - }() - } - - elem, ok := s.cutPrefix(elem) - if !ok { - return r, false - } - - // Static code generated router with unwrapped path search. - switch { - default: - if len(elem) == 0 { - break - } - switch elem[0] { - case '/': // Prefix: "/path" - origElem := elem - if l := len("/path"); len(elem) >= l && elem[0:l] == "/path" { - elem = elem[l:] - } else { - break - } - - if len(elem) == 0 { - break - } - switch elem[0] { - case '1': // Prefix: "1" - origElem := elem - if l := len("1"); len(elem) >= l && elem[0:l] == "1" { - elem = elem[l:] - } else { - break - } - - if len(elem) == 0 { - // Leaf node. - switch method { - case "GET": - r.name = "Path1" - r.summary = "" - r.operationID = "Path1" - r.pathPattern = "/path1" - r.args = args - r.count = 0 - return r, true - default: - return - } - } - - elem = origElem - case '2': // Prefix: "2" - origElem := elem - if l := len("2"); len(elem) >= l && elem[0:l] == "2" { - elem = elem[l:] - } else { - break - } - - if len(elem) == 0 { - // Leaf node. - switch method { - case "GET": - r.name = "Path2" - r.summary = "" - r.operationID = "Path2" - r.pathPattern = "/path2" - r.args = args - r.count = 0 - return r, true - default: - return - } - } - - elem = origElem - } - - elem = origElem - } - } - return r, false -} diff --git a/internal/integration/test_free_form/oas_schemas_gen.go b/internal/integration/test_free_form/oas_schemas_gen.go deleted file mode 100644 index b3dbb605f..000000000 --- a/internal/integration/test_free_form/oas_schemas_gen.go +++ /dev/null @@ -1,81 +0,0 @@ -// Code generated by ogen, DO NOT EDIT. - -package api - -import ( - "github.com/go-faster/jx" -) - -type Path1Def map[string]jx.Raw - -func (s *Path1Def) init() Path1Def { - m := *s - if m == nil { - m = map[string]jx.Raw{} - *s = m - } - return m -} - -// Path1DefStatusCode wraps Path1Def with StatusCode. -type Path1DefStatusCode struct { - StatusCode int - Response Path1Def -} - -// GetStatusCode returns the value of StatusCode. -func (s *Path1DefStatusCode) GetStatusCode() int { - return s.StatusCode -} - -// GetResponse returns the value of Response. -func (s *Path1DefStatusCode) GetResponse() Path1Def { - return s.Response -} - -// SetStatusCode sets the value of StatusCode. -func (s *Path1DefStatusCode) SetStatusCode(val int) { - s.StatusCode = val -} - -// SetResponse sets the value of Response. -func (s *Path1DefStatusCode) SetResponse(val Path1Def) { - s.Response = val -} - -type Path2Def map[string]jx.Raw - -func (s *Path2Def) init() Path2Def { - m := *s - if m == nil { - m = map[string]jx.Raw{} - *s = m - } - return m -} - -// Path2DefStatusCode wraps Path2Def with StatusCode. -type Path2DefStatusCode struct { - StatusCode int - Response Path2Def -} - -// GetStatusCode returns the value of StatusCode. -func (s *Path2DefStatusCode) GetStatusCode() int { - return s.StatusCode -} - -// GetResponse returns the value of Response. -func (s *Path2DefStatusCode) GetResponse() Path2Def { - return s.Response -} - -// SetStatusCode sets the value of StatusCode. -func (s *Path2DefStatusCode) SetStatusCode(val int) { - s.StatusCode = val -} - -// SetResponse sets the value of Response. -func (s *Path2DefStatusCode) SetResponse(val Path2Def) { - s.Response = val -} diff --git a/internal/integration/test_free_form/oas_server_gen.go b/internal/integration/test_free_form/oas_server_gen.go deleted file mode 100644 index b57f5bb77..000000000 --- a/internal/integration/test_free_form/oas_server_gen.go +++ /dev/null @@ -1,38 +0,0 @@ -// Code generated by ogen, DO NOT EDIT. - -package api - -import ( - "context" -) - -// Handler handles operations described by OpenAPI v3 specification. -type Handler interface { - // Path1 implements Path1 operation. - // - // GET /path1 - Path1(ctx context.Context) (*Path1DefStatusCode, error) - // Path2 implements Path2 operation. - // - // GET /path2 - Path2(ctx context.Context) (*Path2DefStatusCode, error) -} - -// Server implements http server based on OpenAPI v3 specification and -// calls Handler to handle requests. -type Server struct { - h Handler - baseServer -} - -// NewServer creates new Server. -func NewServer(h Handler, opts ...ServerOption) (*Server, error) { - s, err := newServerConfig(opts...).baseServer() - if err != nil { - return nil, err - } - return &Server{ - h: h, - baseServer: s, - }, nil -} diff --git a/internal/integration/test_free_form/oas_unimplemented_gen.go b/internal/integration/test_free_form/oas_unimplemented_gen.go deleted file mode 100644 index 8fc4b1273..000000000 --- a/internal/integration/test_free_form/oas_unimplemented_gen.go +++ /dev/null @@ -1,28 +0,0 @@ -// Code generated by ogen, DO NOT EDIT. - -package api - -import ( - "context" - - ht "github.com/ogen-go/ogen/http" -) - -// UnimplementedHandler is no-op Handler which returns http.ErrNotImplemented. -type UnimplementedHandler struct{} - -var _ Handler = UnimplementedHandler{} - -// Path1 implements Path1 operation. -// -// GET /path1 -func (UnimplementedHandler) Path1(ctx context.Context) (r *Path1DefStatusCode, _ error) { - return r, ht.ErrNotImplemented -} - -// Path2 implements Path2 operation. -// -// GET /path2 -func (UnimplementedHandler) Path2(ctx context.Context) (r *Path2DefStatusCode, _ error) { - return r, ht.ErrNotImplemented -} From 1455ee995002619309fa3409462c0aee2f3dcb2a Mon Sep 17 00:00:00 2001 From: tdakkota Date: Wed, 12 Jun 2024 00:23:39 +0300 Subject: [PATCH 3/4] chore: commit generated files --- examples/ex_firecracker/oas_client_gen.go | 12 +- examples/ex_firecracker/oas_faker_gen.go | 45 -- examples/ex_firecracker/oas_handlers_gen.go | 4 +- examples/ex_firecracker/oas_json_gen.go | 170 +----- .../oas_request_decoders_gen.go | 20 +- .../oas_request_encoders_gen.go | 16 +- examples/ex_firecracker/oas_schemas_gen.go | 126 +--- examples/ex_firecracker/oas_server_gen.go | 4 +- .../oas_test_examples_gen_test.go | 6 - .../ex_firecracker/oas_unimplemented_gen.go | 4 +- examples/ex_github/oas_faker_gen.go | 41 +- examples/ex_github/oas_json_gen.go | 178 ++---- examples/ex_github/oas_schemas_gen.go | 98 +--- .../ex_github/oas_test_examples_gen_test.go | 10 - examples/ex_gotd/oas_faker_gen.go | 46 +- examples/ex_gotd/oas_json_gen.go | 156 ++--- examples/ex_gotd/oas_schemas_gen.go | 129 +---- .../ex_gotd/oas_test_examples_gen_test.go | 4 - examples/ex_k8s/oas_faker_gen.go | 144 +---- examples/ex_k8s/oas_json_gen.go | 540 ++++-------------- examples/ex_k8s/oas_schemas_gen.go | 426 ++------------ examples/ex_k8s/oas_test_examples_gen_test.go | 16 - examples/ex_openai/oas_json_gen.go | 524 ++++++----------- examples/ex_openai/oas_schemas_gen.go | 520 +++++++---------- examples/ex_telegram/oas_faker_gen.go | 43 +- examples/ex_telegram/oas_json_gen.go | 156 ++--- examples/ex_telegram/oas_schemas_gen.go | 129 +---- .../ex_telegram/oas_test_examples_gen_test.go | 4 - examples/ex_test_format/oas_client_gen.go | 22 +- examples/ex_test_format/oas_faker_gen.go | 31 - examples/ex_test_format/oas_handlers_gen.go | 12 +- examples/ex_test_format/oas_json_gen.go | 142 ++--- .../oas_request_decoders_gen.go | 14 +- .../oas_request_encoders_gen.go | 10 +- .../oas_response_decoders_gen.go | 4 +- .../oas_response_encoders_gen.go | 2 +- examples/ex_test_format/oas_schemas_gen.go | 79 +-- examples/ex_test_format/oas_server_gen.go | 6 +- .../oas_test_examples_gen_test.go | 6 - .../ex_test_format/oas_unimplemented_gen.go | 8 +- examples/ex_tinkoff/oas_faker_gen.go | 10 - examples/ex_tinkoff/oas_json_gen.go | 34 +- examples/ex_tinkoff/oas_schemas_gen.go | 12 +- .../ex_tinkoff/oas_test_examples_gen_test.go | 2 - .../integration/sample_api/oas_faker_gen.go | 20 +- .../integration/sample_api/oas_json_gen.go | 78 +-- .../integration/sample_api/oas_schemas_gen.go | 69 +-- .../sample_api/oas_test_examples_gen_test.go | 2 - .../integration/sample_api_nc/oas_json_gen.go | 78 +-- .../sample_api_nc/oas_schemas_gen.go | 69 +-- .../sample_api_no_otel/oas_json_gen.go | 78 +-- .../sample_api_no_otel/oas_schemas_gen.go | 69 +-- .../integration/sample_api_ns/oas_json_gen.go | 78 +-- .../sample_api_ns/oas_schemas_gen.go | 69 +-- .../sample_api_nsnc/oas_json_gen.go | 78 +-- .../sample_api_nsnc/oas_schemas_gen.go | 69 +-- 56 files changed, 964 insertions(+), 3758 deletions(-) diff --git a/examples/ex_firecracker/oas_client_gen.go b/examples/ex_firecracker/oas_client_gen.go index 970e51f46..cf7b9df49 100644 --- a/examples/ex_firecracker/oas_client_gen.go +++ b/examples/ex_firecracker/oas_client_gen.go @@ -91,13 +91,13 @@ type Invoker interface { // Updates the MMDS data store. // // PATCH /mmds - MmdsPatch(ctx context.Context, request OptMmdsPatchReq) (MmdsPatchRes, error) + MmdsPatch(ctx context.Context, request *MmdsPatchReq) (MmdsPatchRes, error) // MmdsPut invokes PUT /mmds operation. // // Creates a MMDS (Microvm Metadata Service) data store. // // PUT /mmds - MmdsPut(ctx context.Context, request OptMmdsPutReq) (MmdsPutRes, error) + MmdsPut(ctx context.Context, request *MmdsPutReq) (MmdsPutRes, error) // PatchBalloon invokes patchBalloon operation. // // Updates an existing balloon device, before or after machine startup. Will fail if update is not @@ -985,12 +985,12 @@ func (c *Client) sendMmdsGet(ctx context.Context) (res MmdsGetRes, err error) { // Updates the MMDS data store. // // PATCH /mmds -func (c *Client) MmdsPatch(ctx context.Context, request OptMmdsPatchReq) (MmdsPatchRes, error) { +func (c *Client) MmdsPatch(ctx context.Context, request *MmdsPatchReq) (MmdsPatchRes, error) { res, err := c.sendMmdsPatch(ctx, request) return res, err } -func (c *Client) sendMmdsPatch(ctx context.Context, request OptMmdsPatchReq) (res MmdsPatchRes, err error) { +func (c *Client) sendMmdsPatch(ctx context.Context, request *MmdsPatchReq) (res MmdsPatchRes, err error) { otelAttrs := []attribute.KeyValue{ semconv.HTTPMethodKey.String("PATCH"), semconv.HTTPRouteKey.String("/mmds"), @@ -1059,12 +1059,12 @@ func (c *Client) sendMmdsPatch(ctx context.Context, request OptMmdsPatchReq) (re // Creates a MMDS (Microvm Metadata Service) data store. // // PUT /mmds -func (c *Client) MmdsPut(ctx context.Context, request OptMmdsPutReq) (MmdsPutRes, error) { +func (c *Client) MmdsPut(ctx context.Context, request *MmdsPutReq) (MmdsPutRes, error) { res, err := c.sendMmdsPut(ctx, request) return res, err } -func (c *Client) sendMmdsPut(ctx context.Context, request OptMmdsPutReq) (res MmdsPutRes, err error) { +func (c *Client) sendMmdsPut(ctx context.Context, request *MmdsPutReq) (res MmdsPutRes, err error) { otelAttrs := []attribute.KeyValue{ semconv.HTTPMethodKey.String("PUT"), semconv.HTTPRouteKey.String("/mmds"), diff --git a/examples/ex_firecracker/oas_faker_gen.go b/examples/ex_firecracker/oas_faker_gen.go index d9351bf6e..f9893f534 100644 --- a/examples/ex_firecracker/oas_faker_gen.go +++ b/examples/ex_firecracker/oas_faker_gen.go @@ -2,12 +2,6 @@ package api -import ( - "fmt" - - "github.com/go-faster/jx" -) - // SetFake set fake values. func (s *Balloon) SetFake() { { @@ -375,35 +369,14 @@ func (s *MmdsConfig) SetFake() { // SetFake set fake values. func (s *MmdsGetOK) SetFake() { - var ( - elem jx.Raw - m map[string]jx.Raw = s.init() - ) - for i := 0; i < 0; i++ { - m[fmt.Sprintf("fake%d", i)] = elem - } } // SetFake set fake values. func (s *MmdsPatchReq) SetFake() { - var ( - elem jx.Raw - m map[string]jx.Raw = s.init() - ) - for i := 0; i < 0; i++ { - m[fmt.Sprintf("fake%d", i)] = elem - } } // SetFake set fake values. func (s *MmdsPutReq) SetFake() { - var ( - elem jx.Raw - m map[string]jx.Raw = s.init() - ) - for i := 0; i < 0; i++ { - m[fmt.Sprintf("fake%d", i)] = elem - } } // SetFake set fake values. @@ -539,24 +512,6 @@ func (s *OptMmdsConfig) SetFake() { s.SetTo(elem) } -// SetFake set fake values. -func (s *OptMmdsPatchReq) SetFake() { - var elem MmdsPatchReq - { - elem.SetFake() - } - s.SetTo(elem) -} - -// SetFake set fake values. -func (s *OptMmdsPutReq) SetFake() { - var elem MmdsPutReq - { - elem.SetFake() - } - s.SetTo(elem) -} - // SetFake set fake values. func (s *OptRateLimiter) SetFake() { var elem RateLimiter diff --git a/examples/ex_firecracker/oas_handlers_gen.go b/examples/ex_firecracker/oas_handlers_gen.go index c8ab8bfc0..edb0a8929 100644 --- a/examples/ex_firecracker/oas_handlers_gen.go +++ b/examples/ex_firecracker/oas_handlers_gen.go @@ -1213,7 +1213,7 @@ func (s *Server) handleMmdsPatchRequest(args [0]string, argsEscaped bool, w http } type ( - Request = OptMmdsPatchReq + Request = *MmdsPatchReq Params = struct{} Response = MmdsPatchRes ) @@ -1335,7 +1335,7 @@ func (s *Server) handleMmdsPutRequest(args [0]string, argsEscaped bool, w http.R } type ( - Request = OptMmdsPutReq + Request = *MmdsPutReq Params = struct{} Response = MmdsPutRes ) diff --git a/examples/ex_firecracker/oas_json_gen.go b/examples/ex_firecracker/oas_json_gen.go index 416d72a94..5a035494e 100644 --- a/examples/ex_firecracker/oas_json_gen.go +++ b/examples/ex_firecracker/oas_json_gen.go @@ -2145,43 +2145,29 @@ func (s *MmdsConfig) UnmarshalJSON(data []byte) error { } // Encode implements json.Marshaler. -func (s MmdsGetOK) Encode(e *jx.Encoder) { +func (s *MmdsGetOK) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } -// encodeFields implements json.Marshaler. -func (s MmdsGetOK) encodeFields(e *jx.Encoder) { - for k, elem := range s { - e.FieldStart(k) - - if len(elem) != 0 { - e.Raw(elem) - } - } +// encodeFields encodes fields. +func (s *MmdsGetOK) encodeFields(e *jx.Encoder) { } +var jsonFieldsNameOfMmdsGetOK = [0]string{} + // Decode decodes MmdsGetOK from json. func (s *MmdsGetOK) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode MmdsGetOK to nil") } - m := s.init() + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { - var elem jx.Raw - if err := func() error { - v, err := d.RawAppend(nil) - elem = jx.Raw(v) - if err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrapf(err, "decode field %q", k) + switch string(k) { + default: + return d.Skip() } - m[string(k)] = elem - return nil }); err != nil { return errors.Wrap(err, "decode MmdsGetOK") } @@ -2190,7 +2176,7 @@ func (s *MmdsGetOK) Decode(d *jx.Decoder) error { } // MarshalJSON implements stdjson.Marshaler. -func (s MmdsGetOK) MarshalJSON() ([]byte, error) { +func (s *MmdsGetOK) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil @@ -2203,43 +2189,29 @@ func (s *MmdsGetOK) UnmarshalJSON(data []byte) error { } // Encode implements json.Marshaler. -func (s MmdsPatchReq) Encode(e *jx.Encoder) { +func (s *MmdsPatchReq) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } -// encodeFields implements json.Marshaler. -func (s MmdsPatchReq) encodeFields(e *jx.Encoder) { - for k, elem := range s { - e.FieldStart(k) - - if len(elem) != 0 { - e.Raw(elem) - } - } +// encodeFields encodes fields. +func (s *MmdsPatchReq) encodeFields(e *jx.Encoder) { } +var jsonFieldsNameOfMmdsPatchReq = [0]string{} + // Decode decodes MmdsPatchReq from json. func (s *MmdsPatchReq) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode MmdsPatchReq to nil") } - m := s.init() + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { - var elem jx.Raw - if err := func() error { - v, err := d.RawAppend(nil) - elem = jx.Raw(v) - if err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrapf(err, "decode field %q", k) + switch string(k) { + default: + return d.Skip() } - m[string(k)] = elem - return nil }); err != nil { return errors.Wrap(err, "decode MmdsPatchReq") } @@ -2248,7 +2220,7 @@ func (s *MmdsPatchReq) Decode(d *jx.Decoder) error { } // MarshalJSON implements stdjson.Marshaler. -func (s MmdsPatchReq) MarshalJSON() ([]byte, error) { +func (s *MmdsPatchReq) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil @@ -2261,43 +2233,29 @@ func (s *MmdsPatchReq) UnmarshalJSON(data []byte) error { } // Encode implements json.Marshaler. -func (s MmdsPutReq) Encode(e *jx.Encoder) { +func (s *MmdsPutReq) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } -// encodeFields implements json.Marshaler. -func (s MmdsPutReq) encodeFields(e *jx.Encoder) { - for k, elem := range s { - e.FieldStart(k) - - if len(elem) != 0 { - e.Raw(elem) - } - } +// encodeFields encodes fields. +func (s *MmdsPutReq) encodeFields(e *jx.Encoder) { } +var jsonFieldsNameOfMmdsPutReq = [0]string{} + // Decode decodes MmdsPutReq from json. func (s *MmdsPutReq) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode MmdsPutReq to nil") } - m := s.init() + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { - var elem jx.Raw - if err := func() error { - v, err := d.RawAppend(nil) - elem = jx.Raw(v) - if err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrapf(err, "decode field %q", k) + switch string(k) { + default: + return d.Skip() } - m[string(k)] = elem - return nil }); err != nil { return errors.Wrap(err, "decode MmdsPutReq") } @@ -2306,7 +2264,7 @@ func (s *MmdsPutReq) Decode(d *jx.Decoder) error { } // MarshalJSON implements stdjson.Marshaler. -func (s MmdsPutReq) MarshalJSON() ([]byte, error) { +func (s *MmdsPutReq) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil @@ -2868,74 +2826,6 @@ func (s *OptMmdsConfig) UnmarshalJSON(data []byte) error { return s.Decode(d) } -// Encode encodes MmdsPatchReq as json. -func (o OptMmdsPatchReq) Encode(e *jx.Encoder) { - if !o.Set { - return - } - o.Value.Encode(e) -} - -// Decode decodes MmdsPatchReq from json. -func (o *OptMmdsPatchReq) Decode(d *jx.Decoder) error { - if o == nil { - return errors.New("invalid: unable to decode OptMmdsPatchReq to nil") - } - o.Set = true - o.Value = make(MmdsPatchReq) - if err := o.Value.Decode(d); err != nil { - return err - } - return nil -} - -// MarshalJSON implements stdjson.Marshaler. -func (s OptMmdsPatchReq) MarshalJSON() ([]byte, error) { - e := jx.Encoder{} - s.Encode(&e) - return e.Bytes(), nil -} - -// UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptMmdsPatchReq) UnmarshalJSON(data []byte) error { - d := jx.DecodeBytes(data) - return s.Decode(d) -} - -// Encode encodes MmdsPutReq as json. -func (o OptMmdsPutReq) Encode(e *jx.Encoder) { - if !o.Set { - return - } - o.Value.Encode(e) -} - -// Decode decodes MmdsPutReq from json. -func (o *OptMmdsPutReq) Decode(d *jx.Decoder) error { - if o == nil { - return errors.New("invalid: unable to decode OptMmdsPutReq to nil") - } - o.Set = true - o.Value = make(MmdsPutReq) - if err := o.Value.Decode(d); err != nil { - return err - } - return nil -} - -// MarshalJSON implements stdjson.Marshaler. -func (s OptMmdsPutReq) MarshalJSON() ([]byte, error) { - e := jx.Encoder{} - s.Encode(&e) - return e.Bytes(), nil -} - -// UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptMmdsPutReq) UnmarshalJSON(data []byte) error { - d := jx.DecodeBytes(data) - return s.Decode(d) -} - // Encode encodes RateLimiter as json. func (o OptRateLimiter) Encode(e *jx.Encoder) { if !o.Set { diff --git a/examples/ex_firecracker/oas_request_decoders_gen.go b/examples/ex_firecracker/oas_request_decoders_gen.go index dbd174f6c..554abfe55 100644 --- a/examples/ex_firecracker/oas_request_decoders_gen.go +++ b/examples/ex_firecracker/oas_request_decoders_gen.go @@ -284,7 +284,7 @@ func (s *Server) decodeMmdsConfigPutRequest(r *http.Request) ( } func (s *Server) decodeMmdsPatchRequest(r *http.Request) ( - req OptMmdsPatchReq, + req *MmdsPatchReq, close func() error, rerr error, ) { @@ -326,12 +326,14 @@ func (s *Server) decodeMmdsPatchRequest(r *http.Request) ( d := jx.DecodeBytes(buf) - var request OptMmdsPatchReq + var request *MmdsPatchReq if err := func() error { - request.Reset() - if err := request.Decode(d); err != nil { + request = nil + var elem MmdsPatchReq + if err := elem.Decode(d); err != nil { return err } + request = &elem if err := d.Skip(); err != io.EOF { return errors.New("unexpected trailing data") } @@ -351,7 +353,7 @@ func (s *Server) decodeMmdsPatchRequest(r *http.Request) ( } func (s *Server) decodeMmdsPutRequest(r *http.Request) ( - req OptMmdsPutReq, + req *MmdsPutReq, close func() error, rerr error, ) { @@ -393,12 +395,14 @@ func (s *Server) decodeMmdsPutRequest(r *http.Request) ( d := jx.DecodeBytes(buf) - var request OptMmdsPutReq + var request *MmdsPutReq if err := func() error { - request.Reset() - if err := request.Decode(d); err != nil { + request = nil + var elem MmdsPutReq + if err := elem.Decode(d); err != nil { return err } + request = &elem if err := d.Skip(); err != io.EOF { return errors.New("unexpected trailing data") } diff --git a/examples/ex_firecracker/oas_request_encoders_gen.go b/examples/ex_firecracker/oas_request_encoders_gen.go index 5c2331180..b4d914075 100644 --- a/examples/ex_firecracker/oas_request_encoders_gen.go +++ b/examples/ex_firecracker/oas_request_encoders_gen.go @@ -68,17 +68,13 @@ func encodeMmdsConfigPutRequest( } func encodeMmdsPatchRequest( - req OptMmdsPatchReq, + req *MmdsPatchReq, r *http.Request, ) error { const contentType = "application/json" - if !req.Set { - // Keep request with empty body if value is not set. - return nil - } e := new(jx.Encoder) { - if req.Set { + if req != nil { req.Encode(e) } } @@ -88,17 +84,13 @@ func encodeMmdsPatchRequest( } func encodeMmdsPutRequest( - req OptMmdsPutReq, + req *MmdsPutReq, r *http.Request, ) error { const contentType = "application/json" - if !req.Set { - // Keep request with empty body if value is not set. - return nil - } e := new(jx.Encoder) { - if req.Set { + if req != nil { req.Encode(e) } } diff --git a/examples/ex_firecracker/oas_schemas_gen.go b/examples/ex_firecracker/oas_schemas_gen.go index a89eb424d..f00ded829 100644 --- a/examples/ex_firecracker/oas_schemas_gen.go +++ b/examples/ex_firecracker/oas_schemas_gen.go @@ -6,7 +6,6 @@ import ( "fmt" "github.com/go-faster/errors" - "github.com/go-faster/jx" ) func (s *ErrorStatusCode) Error() string { @@ -1009,16 +1008,7 @@ type MmdsConfigPutNoContent struct{} func (*MmdsConfigPutNoContent) mmdsConfigPutRes() {} -type MmdsGetOK map[string]jx.Raw - -func (s *MmdsGetOK) init() MmdsGetOK { - m := *s - if m == nil { - m = map[string]jx.Raw{} - *s = m - } - return m -} +type MmdsGetOK struct{} func (*MmdsGetOK) mmdsGetRes() {} @@ -1027,32 +1017,14 @@ type MmdsPatchNoContent struct{} func (*MmdsPatchNoContent) mmdsPatchRes() {} -type MmdsPatchReq map[string]jx.Raw - -func (s *MmdsPatchReq) init() MmdsPatchReq { - m := *s - if m == nil { - m = map[string]jx.Raw{} - *s = m - } - return m -} +type MmdsPatchReq struct{} // MmdsPutNoContent is response for MmdsPut operation. type MmdsPutNoContent struct{} func (*MmdsPutNoContent) mmdsPutRes() {} -type MmdsPutReq map[string]jx.Raw - -func (s *MmdsPutReq) init() MmdsPutReq { - m := *s - if m == nil { - m = map[string]jx.Raw{} - *s = m - } - return m -} +type MmdsPutReq struct{} // Defines a network interface. // Ref: #/components/schemas/NetworkInterface @@ -1636,98 +1608,6 @@ func (o OptMmdsConfig) Or(d MmdsConfig) MmdsConfig { return d } -// NewOptMmdsPatchReq returns new OptMmdsPatchReq with value set to v. -func NewOptMmdsPatchReq(v MmdsPatchReq) OptMmdsPatchReq { - return OptMmdsPatchReq{ - Value: v, - Set: true, - } -} - -// OptMmdsPatchReq is optional MmdsPatchReq. -type OptMmdsPatchReq struct { - Value MmdsPatchReq - Set bool -} - -// IsSet returns true if OptMmdsPatchReq was set. -func (o OptMmdsPatchReq) IsSet() bool { return o.Set } - -// Reset unsets value. -func (o *OptMmdsPatchReq) Reset() { - var v MmdsPatchReq - o.Value = v - o.Set = false -} - -// SetTo sets value to v. -func (o *OptMmdsPatchReq) SetTo(v MmdsPatchReq) { - o.Set = true - o.Value = v -} - -// Get returns value and boolean that denotes whether value was set. -func (o OptMmdsPatchReq) Get() (v MmdsPatchReq, ok bool) { - if !o.Set { - return v, false - } - return o.Value, true -} - -// Or returns value if set, or given parameter if does not. -func (o OptMmdsPatchReq) Or(d MmdsPatchReq) MmdsPatchReq { - if v, ok := o.Get(); ok { - return v - } - return d -} - -// NewOptMmdsPutReq returns new OptMmdsPutReq with value set to v. -func NewOptMmdsPutReq(v MmdsPutReq) OptMmdsPutReq { - return OptMmdsPutReq{ - Value: v, - Set: true, - } -} - -// OptMmdsPutReq is optional MmdsPutReq. -type OptMmdsPutReq struct { - Value MmdsPutReq - Set bool -} - -// IsSet returns true if OptMmdsPutReq was set. -func (o OptMmdsPutReq) IsSet() bool { return o.Set } - -// Reset unsets value. -func (o *OptMmdsPutReq) Reset() { - var v MmdsPutReq - o.Value = v - o.Set = false -} - -// SetTo sets value to v. -func (o *OptMmdsPutReq) SetTo(v MmdsPutReq) { - o.Set = true - o.Value = v -} - -// Get returns value and boolean that denotes whether value was set. -func (o OptMmdsPutReq) Get() (v MmdsPutReq, ok bool) { - if !o.Set { - return v, false - } - return o.Value, true -} - -// Or returns value if set, or given parameter if does not. -func (o OptMmdsPutReq) Or(d MmdsPutReq) MmdsPutReq { - if v, ok := o.Get(); ok { - return v - } - return d -} - // NewOptRateLimiter returns new OptRateLimiter with value set to v. func NewOptRateLimiter(v RateLimiter) OptRateLimiter { return OptRateLimiter{ diff --git a/examples/ex_firecracker/oas_server_gen.go b/examples/ex_firecracker/oas_server_gen.go index b0160052b..5c59d8b0a 100644 --- a/examples/ex_firecracker/oas_server_gen.go +++ b/examples/ex_firecracker/oas_server_gen.go @@ -76,13 +76,13 @@ type Handler interface { // Updates the MMDS data store. // // PATCH /mmds - MmdsPatch(ctx context.Context, req OptMmdsPatchReq) (MmdsPatchRes, error) + MmdsPatch(ctx context.Context, req *MmdsPatchReq) (MmdsPatchRes, error) // MmdsPut implements PUT /mmds operation. // // Creates a MMDS (Microvm Metadata Service) data store. // // PUT /mmds - MmdsPut(ctx context.Context, req OptMmdsPutReq) (MmdsPutRes, error) + MmdsPut(ctx context.Context, req *MmdsPutReq) (MmdsPutRes, error) // PatchBalloon implements patchBalloon operation. // // Updates an existing balloon device, before or after machine startup. Will fail if update is not diff --git a/examples/ex_firecracker/oas_test_examples_gen_test.go b/examples/ex_firecracker/oas_test_examples_gen_test.go index 30ba91127..4313b2cd4 100644 --- a/examples/ex_firecracker/oas_test_examples_gen_test.go +++ b/examples/ex_firecracker/oas_test_examples_gen_test.go @@ -229,7 +229,6 @@ func TestMmdsConfig_EncodeDecode(t *testing.T) { } func TestMmdsGetOK_EncodeDecode(t *testing.T) { var typ MmdsGetOK - typ = make(MmdsGetOK) typ.SetFake() e := jx.Encoder{} @@ -238,12 +237,10 @@ func TestMmdsGetOK_EncodeDecode(t *testing.T) { require.True(t, std.Valid(data), "Encoded: %s", data) var typ2 MmdsGetOK - typ2 = make(MmdsGetOK) require.NoError(t, typ2.Decode(jx.DecodeBytes(data))) } func TestMmdsPatchReq_EncodeDecode(t *testing.T) { var typ MmdsPatchReq - typ = make(MmdsPatchReq) typ.SetFake() e := jx.Encoder{} @@ -252,12 +249,10 @@ func TestMmdsPatchReq_EncodeDecode(t *testing.T) { require.True(t, std.Valid(data), "Encoded: %s", data) var typ2 MmdsPatchReq - typ2 = make(MmdsPatchReq) require.NoError(t, typ2.Decode(jx.DecodeBytes(data))) } func TestMmdsPutReq_EncodeDecode(t *testing.T) { var typ MmdsPutReq - typ = make(MmdsPutReq) typ.SetFake() e := jx.Encoder{} @@ -266,7 +261,6 @@ func TestMmdsPutReq_EncodeDecode(t *testing.T) { require.True(t, std.Valid(data), "Encoded: %s", data) var typ2 MmdsPutReq - typ2 = make(MmdsPutReq) require.NoError(t, typ2.Decode(jx.DecodeBytes(data))) } func TestNetworkInterface_EncodeDecode(t *testing.T) { diff --git a/examples/ex_firecracker/oas_unimplemented_gen.go b/examples/ex_firecracker/oas_unimplemented_gen.go index 17da7a54e..314748b5a 100644 --- a/examples/ex_firecracker/oas_unimplemented_gen.go +++ b/examples/ex_firecracker/oas_unimplemented_gen.go @@ -111,7 +111,7 @@ func (UnimplementedHandler) MmdsGet(ctx context.Context) (r MmdsGetRes, _ error) // Updates the MMDS data store. // // PATCH /mmds -func (UnimplementedHandler) MmdsPatch(ctx context.Context, req OptMmdsPatchReq) (r MmdsPatchRes, _ error) { +func (UnimplementedHandler) MmdsPatch(ctx context.Context, req *MmdsPatchReq) (r MmdsPatchRes, _ error) { return r, ht.ErrNotImplemented } @@ -120,7 +120,7 @@ func (UnimplementedHandler) MmdsPatch(ctx context.Context, req OptMmdsPatchReq) // Creates a MMDS (Microvm Metadata Service) data store. // // PUT /mmds -func (UnimplementedHandler) MmdsPut(ctx context.Context, req OptMmdsPutReq) (r MmdsPutRes, _ error) { +func (UnimplementedHandler) MmdsPut(ctx context.Context, req *MmdsPutReq) (r MmdsPutRes, _ error) { return r, ht.ErrNotImplemented } diff --git a/examples/ex_github/oas_faker_gen.go b/examples/ex_github/oas_faker_gen.go index 97ca87887..1463ce9b8 100644 --- a/examples/ex_github/oas_faker_gen.go +++ b/examples/ex_github/oas_faker_gen.go @@ -158,13 +158,6 @@ func (s *APIOverviewSSHKeyFingerprints) SetFake() { // SetFake set fake values. func (s *Accepted) SetFake() { - var ( - elem jx.Raw - m map[string]jx.Raw = s.init() - ) - for i := 0; i < 0; i++ { - m[fmt.Sprintf("fake%d", i)] = elem - } } // SetFake set fake values. @@ -2699,8 +2692,8 @@ func (s *AuthenticationToken) SetFake() { } } { - { - s.Permissions.SetFake() + { // Keep pointer nil to prevent infinite recursion. + s.Permissions = nil } } { @@ -2729,13 +2722,6 @@ func (s *AuthenticationToken) SetFake() { // SetFake set fake values. func (s *AuthenticationTokenPermissions) SetFake() { - var ( - elem jx.Raw - m map[string]jx.Raw = s.init() - ) - for i := 0; i < 0; i++ { - m[fmt.Sprintf("fake%d", i)] = elem - } } // SetFake set fake values. @@ -7501,13 +7487,6 @@ func (s *EnterpriseAdminUpdateAttributeForEnterpriseGroupReqOperationsItemValue) // SetFake set fake values. func (s *EnterpriseAdminUpdateAttributeForEnterpriseGroupReqOperationsItemValue1) SetFake() { - var ( - elem jx.Raw - m map[string]jx.Raw = s.init() - ) - for i := 0; i < 0; i++ { - m[fmt.Sprintf("fake%d", i)] = elem - } } // SetFake set fake values. @@ -7540,13 +7519,6 @@ func (s *EnterpriseAdminUpdateAttributeForEnterpriseUserReq) SetFake() { // SetFake set fake values. func (s *EnterpriseAdminUpdateAttributeForEnterpriseUserReqOperationsItem) SetFake() { - var ( - elem jx.Raw - m map[string]jx.Raw = s.init() - ) - for i := 0; i < 0; i++ { - m[fmt.Sprintf("fake%d", i)] = elem - } } // SetFake set fake values. @@ -17842,15 +17814,6 @@ func (s *OptAuditLogEventData) SetFake() { s.SetTo(elem) } -// SetFake set fake values. -func (s *OptAuthenticationTokenPermissions) SetFake() { - var elem AuthenticationTokenPermissions - { - elem.SetFake() - } - s.SetTo(elem) -} - // SetFake set fake values. func (s *OptAuthenticationTokenRepositorySelection) SetFake() { var elem AuthenticationTokenRepositorySelection diff --git a/examples/ex_github/oas_json_gen.go b/examples/ex_github/oas_json_gen.go index cda17f024..c617fc31e 100644 --- a/examples/ex_github/oas_json_gen.go +++ b/examples/ex_github/oas_json_gen.go @@ -514,43 +514,29 @@ func (s *APIOverviewSSHKeyFingerprints) UnmarshalJSON(data []byte) error { } // Encode implements json.Marshaler. -func (s Accepted) Encode(e *jx.Encoder) { +func (s *Accepted) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } -// encodeFields implements json.Marshaler. -func (s Accepted) encodeFields(e *jx.Encoder) { - for k, elem := range s { - e.FieldStart(k) - - if len(elem) != 0 { - e.Raw(elem) - } - } +// encodeFields encodes fields. +func (s *Accepted) encodeFields(e *jx.Encoder) { } +var jsonFieldsNameOfAccepted = [0]string{} + // Decode decodes Accepted from json. func (s *Accepted) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode Accepted to nil") } - m := s.init() + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { - var elem jx.Raw - if err := func() error { - v, err := d.RawAppend(nil) - elem = jx.Raw(v) - if err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrapf(err, "decode field %q", k) + switch string(k) { + default: + return d.Skip() } - m[string(k)] = elem - return nil }); err != nil { return errors.Wrap(err, "decode Accepted") } @@ -559,7 +545,7 @@ func (s *Accepted) Decode(d *jx.Decoder) error { } // MarshalJSON implements stdjson.Marshaler. -func (s Accepted) MarshalJSON() ([]byte, error) { +func (s *Accepted) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil @@ -13606,7 +13592,7 @@ func (s *AuthenticationToken) encodeFields(e *jx.Encoder) { json.EncodeDateTime(e, s.ExpiresAt) } { - if s.Permissions.Set { + if s.Permissions != nil { e.FieldStart("permissions") s.Permissions.Encode(e) } @@ -13679,10 +13665,12 @@ func (s *AuthenticationToken) Decode(d *jx.Decoder) error { } case "permissions": if err := func() error { - s.Permissions.Reset() - if err := s.Permissions.Decode(d); err != nil { + s.Permissions = nil + var elem AuthenticationTokenPermissions + if err := elem.Decode(d); err != nil { return err } + s.Permissions = &elem return nil }(); err != nil { return errors.Wrap(err, "decode field \"permissions\"") @@ -13781,43 +13769,29 @@ func (s *AuthenticationToken) UnmarshalJSON(data []byte) error { } // Encode implements json.Marshaler. -func (s AuthenticationTokenPermissions) Encode(e *jx.Encoder) { +func (s *AuthenticationTokenPermissions) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } -// encodeFields implements json.Marshaler. -func (s AuthenticationTokenPermissions) encodeFields(e *jx.Encoder) { - for k, elem := range s { - e.FieldStart(k) - - if len(elem) != 0 { - e.Raw(elem) - } - } +// encodeFields encodes fields. +func (s *AuthenticationTokenPermissions) encodeFields(e *jx.Encoder) { } +var jsonFieldsNameOfAuthenticationTokenPermissions = [0]string{} + // Decode decodes AuthenticationTokenPermissions from json. func (s *AuthenticationTokenPermissions) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode AuthenticationTokenPermissions to nil") } - m := s.init() + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { - var elem jx.Raw - if err := func() error { - v, err := d.RawAppend(nil) - elem = jx.Raw(v) - if err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrapf(err, "decode field %q", k) + switch string(k) { + default: + return d.Skip() } - m[string(k)] = elem - return nil }); err != nil { return errors.Wrap(err, "decode AuthenticationTokenPermissions") } @@ -13826,7 +13800,7 @@ func (s *AuthenticationTokenPermissions) Decode(d *jx.Decoder) error { } // MarshalJSON implements stdjson.Marshaler. -func (s AuthenticationTokenPermissions) MarshalJSON() ([]byte, error) { +func (s *AuthenticationTokenPermissions) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil @@ -36757,43 +36731,29 @@ func (s *EnterpriseAdminUpdateAttributeForEnterpriseGroupReqOperationsItemValue) } // Encode implements json.Marshaler. -func (s EnterpriseAdminUpdateAttributeForEnterpriseGroupReqOperationsItemValue1) Encode(e *jx.Encoder) { +func (s *EnterpriseAdminUpdateAttributeForEnterpriseGroupReqOperationsItemValue1) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } -// encodeFields implements json.Marshaler. -func (s EnterpriseAdminUpdateAttributeForEnterpriseGroupReqOperationsItemValue1) encodeFields(e *jx.Encoder) { - for k, elem := range s { - e.FieldStart(k) - - if len(elem) != 0 { - e.Raw(elem) - } - } +// encodeFields encodes fields. +func (s *EnterpriseAdminUpdateAttributeForEnterpriseGroupReqOperationsItemValue1) encodeFields(e *jx.Encoder) { } +var jsonFieldsNameOfEnterpriseAdminUpdateAttributeForEnterpriseGroupReqOperationsItemValue1 = [0]string{} + // Decode decodes EnterpriseAdminUpdateAttributeForEnterpriseGroupReqOperationsItemValue1 from json. func (s *EnterpriseAdminUpdateAttributeForEnterpriseGroupReqOperationsItemValue1) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode EnterpriseAdminUpdateAttributeForEnterpriseGroupReqOperationsItemValue1 to nil") } - m := s.init() + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { - var elem jx.Raw - if err := func() error { - v, err := d.RawAppend(nil) - elem = jx.Raw(v) - if err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrapf(err, "decode field %q", k) + switch string(k) { + default: + return d.Skip() } - m[string(k)] = elem - return nil }); err != nil { return errors.Wrap(err, "decode EnterpriseAdminUpdateAttributeForEnterpriseGroupReqOperationsItemValue1") } @@ -36802,7 +36762,7 @@ func (s *EnterpriseAdminUpdateAttributeForEnterpriseGroupReqOperationsItemValue1 } // MarshalJSON implements stdjson.Marshaler. -func (s EnterpriseAdminUpdateAttributeForEnterpriseGroupReqOperationsItemValue1) MarshalJSON() ([]byte, error) { +func (s *EnterpriseAdminUpdateAttributeForEnterpriseGroupReqOperationsItemValue1) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil @@ -36950,43 +36910,29 @@ func (s *EnterpriseAdminUpdateAttributeForEnterpriseUserReq) UnmarshalJSON(data } // Encode implements json.Marshaler. -func (s EnterpriseAdminUpdateAttributeForEnterpriseUserReqOperationsItem) Encode(e *jx.Encoder) { +func (s *EnterpriseAdminUpdateAttributeForEnterpriseUserReqOperationsItem) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } -// encodeFields implements json.Marshaler. -func (s EnterpriseAdminUpdateAttributeForEnterpriseUserReqOperationsItem) encodeFields(e *jx.Encoder) { - for k, elem := range s { - e.FieldStart(k) - - if len(elem) != 0 { - e.Raw(elem) - } - } +// encodeFields encodes fields. +func (s *EnterpriseAdminUpdateAttributeForEnterpriseUserReqOperationsItem) encodeFields(e *jx.Encoder) { } +var jsonFieldsNameOfEnterpriseAdminUpdateAttributeForEnterpriseUserReqOperationsItem = [0]string{} + // Decode decodes EnterpriseAdminUpdateAttributeForEnterpriseUserReqOperationsItem from json. func (s *EnterpriseAdminUpdateAttributeForEnterpriseUserReqOperationsItem) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode EnterpriseAdminUpdateAttributeForEnterpriseUserReqOperationsItem to nil") } - m := s.init() + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { - var elem jx.Raw - if err := func() error { - v, err := d.RawAppend(nil) - elem = jx.Raw(v) - if err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrapf(err, "decode field %q", k) + switch string(k) { + default: + return d.Skip() } - m[string(k)] = elem - return nil }); err != nil { return errors.Wrap(err, "decode EnterpriseAdminUpdateAttributeForEnterpriseUserReqOperationsItem") } @@ -36995,7 +36941,7 @@ func (s *EnterpriseAdminUpdateAttributeForEnterpriseUserReqOperationsItem) Decod } // MarshalJSON implements stdjson.Marshaler. -func (s EnterpriseAdminUpdateAttributeForEnterpriseUserReqOperationsItem) MarshalJSON() ([]byte, error) { +func (s *EnterpriseAdminUpdateAttributeForEnterpriseUserReqOperationsItem) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil @@ -83047,40 +82993,6 @@ func (s *OptAuditLogEventData) UnmarshalJSON(data []byte) error { return s.Decode(d) } -// Encode encodes AuthenticationTokenPermissions as json. -func (o OptAuthenticationTokenPermissions) Encode(e *jx.Encoder) { - if !o.Set { - return - } - o.Value.Encode(e) -} - -// Decode decodes AuthenticationTokenPermissions from json. -func (o *OptAuthenticationTokenPermissions) Decode(d *jx.Decoder) error { - if o == nil { - return errors.New("invalid: unable to decode OptAuthenticationTokenPermissions to nil") - } - o.Set = true - o.Value = make(AuthenticationTokenPermissions) - if err := o.Value.Decode(d); err != nil { - return err - } - return nil -} - -// MarshalJSON implements stdjson.Marshaler. -func (s OptAuthenticationTokenPermissions) MarshalJSON() ([]byte, error) { - e := jx.Encoder{} - s.Encode(&e) - return e.Bytes(), nil -} - -// UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptAuthenticationTokenPermissions) UnmarshalJSON(data []byte) error { - d := jx.DecodeBytes(data) - return s.Decode(d) -} - // Encode encodes AuthenticationTokenRepositorySelection as json. func (o OptAuthenticationTokenRepositorySelection) Encode(e *jx.Encoder) { if !o.Set { diff --git a/examples/ex_github/oas_schemas_gen.go b/examples/ex_github/oas_schemas_gen.go index 9566b40e0..811c6ce25 100644 --- a/examples/ex_github/oas_schemas_gen.go +++ b/examples/ex_github/oas_schemas_gen.go @@ -186,16 +186,7 @@ func (s *APIOverviewSSHKeyFingerprints) SetSHA256ED25519(val OptString) { s.SHA256ED25519 = val } -type Accepted map[string]jx.Raw - -func (s *Accepted) init() Accepted { - m := *s - if m == nil { - m = map[string]jx.Raw{} - *s = m - } - return m -} +type Accepted struct{} func (*Accepted) appsRedeliverWebhookDeliveryRes() {} func (*Accepted) orgsRedeliverWebhookDeliveryRes() {} @@ -6224,8 +6215,8 @@ type AuthenticationToken struct { // The token used for authentication. Token string `json:"token"` // The time this token expires. - ExpiresAt time.Time `json:"expires_at"` - Permissions OptAuthenticationTokenPermissions `json:"permissions"` + ExpiresAt time.Time `json:"expires_at"` + Permissions *AuthenticationTokenPermissions `json:"permissions"` // The repositories this token has access to. Repositories []Repository `json:"repositories"` SingleFile OptNilString `json:"single_file"` @@ -6244,7 +6235,7 @@ func (s *AuthenticationToken) GetExpiresAt() time.Time { } // GetPermissions returns the value of Permissions. -func (s *AuthenticationToken) GetPermissions() OptAuthenticationTokenPermissions { +func (s *AuthenticationToken) GetPermissions() *AuthenticationTokenPermissions { return s.Permissions } @@ -6274,7 +6265,7 @@ func (s *AuthenticationToken) SetExpiresAt(val time.Time) { } // SetPermissions sets the value of Permissions. -func (s *AuthenticationToken) SetPermissions(val OptAuthenticationTokenPermissions) { +func (s *AuthenticationToken) SetPermissions(val *AuthenticationTokenPermissions) { s.Permissions = val } @@ -6293,16 +6284,7 @@ func (s *AuthenticationToken) SetRepositorySelection(val OptAuthenticationTokenR s.RepositorySelection = val } -type AuthenticationTokenPermissions map[string]jx.Raw - -func (s *AuthenticationTokenPermissions) init() AuthenticationTokenPermissions { - m := *s - if m == nil { - m = map[string]jx.Raw{} - *s = m - } - return m -} +type AuthenticationTokenPermissions struct{} // Describe whether all repositories have been selected or there's a selection involved. type AuthenticationTokenRepositorySelection string @@ -16719,16 +16701,7 @@ func NewAnyArrayEnterpriseAdminUpdateAttributeForEnterpriseGroupReqOperationsIte return s } -type EnterpriseAdminUpdateAttributeForEnterpriseGroupReqOperationsItemValue1 map[string]jx.Raw - -func (s *EnterpriseAdminUpdateAttributeForEnterpriseGroupReqOperationsItemValue1) init() EnterpriseAdminUpdateAttributeForEnterpriseGroupReqOperationsItemValue1 { - m := *s - if m == nil { - m = map[string]jx.Raw{} - *s = m - } - return m -} +type EnterpriseAdminUpdateAttributeForEnterpriseGroupReqOperationsItemValue1 struct{} type EnterpriseAdminUpdateAttributeForEnterpriseUserReq struct { // The SCIM schema URIs. @@ -16757,16 +16730,7 @@ func (s *EnterpriseAdminUpdateAttributeForEnterpriseUserReq) SetOperations(val [ s.Operations = val } -type EnterpriseAdminUpdateAttributeForEnterpriseUserReqOperationsItem map[string]jx.Raw - -func (s *EnterpriseAdminUpdateAttributeForEnterpriseUserReqOperationsItem) init() EnterpriseAdminUpdateAttributeForEnterpriseUserReqOperationsItem { - m := *s - if m == nil { - m = map[string]jx.Raw{} - *s = m - } - return m -} +type EnterpriseAdminUpdateAttributeForEnterpriseUserReqOperationsItem struct{} type EnterpriseAdminUpdateSelfHostedRunnerGroupForEnterpriseReq struct { // Name of the runner group. @@ -43047,52 +43011,6 @@ func (o OptAuditLogOrder) Or(d AuditLogOrder) AuditLogOrder { return d } -// NewOptAuthenticationTokenPermissions returns new OptAuthenticationTokenPermissions with value set to v. -func NewOptAuthenticationTokenPermissions(v AuthenticationTokenPermissions) OptAuthenticationTokenPermissions { - return OptAuthenticationTokenPermissions{ - Value: v, - Set: true, - } -} - -// OptAuthenticationTokenPermissions is optional AuthenticationTokenPermissions. -type OptAuthenticationTokenPermissions struct { - Value AuthenticationTokenPermissions - Set bool -} - -// IsSet returns true if OptAuthenticationTokenPermissions was set. -func (o OptAuthenticationTokenPermissions) IsSet() bool { return o.Set } - -// Reset unsets value. -func (o *OptAuthenticationTokenPermissions) Reset() { - var v AuthenticationTokenPermissions - o.Value = v - o.Set = false -} - -// SetTo sets value to v. -func (o *OptAuthenticationTokenPermissions) SetTo(v AuthenticationTokenPermissions) { - o.Set = true - o.Value = v -} - -// Get returns value and boolean that denotes whether value was set. -func (o OptAuthenticationTokenPermissions) Get() (v AuthenticationTokenPermissions, ok bool) { - if !o.Set { - return v, false - } - return o.Value, true -} - -// Or returns value if set, or given parameter if does not. -func (o OptAuthenticationTokenPermissions) Or(d AuthenticationTokenPermissions) AuthenticationTokenPermissions { - if v, ok := o.Get(); ok { - return v - } - return d -} - // NewOptAuthenticationTokenRepositorySelection returns new OptAuthenticationTokenRepositorySelection with value set to v. func NewOptAuthenticationTokenRepositorySelection(v AuthenticationTokenRepositorySelection) OptAuthenticationTokenRepositorySelection { return OptAuthenticationTokenRepositorySelection{ diff --git a/examples/ex_github/oas_test_examples_gen_test.go b/examples/ex_github/oas_test_examples_gen_test.go index 60602add4..1979df4e6 100644 --- a/examples/ex_github/oas_test_examples_gen_test.go +++ b/examples/ex_github/oas_test_examples_gen_test.go @@ -71,7 +71,6 @@ func TestAPIOverviewSSHKeyFingerprints_EncodeDecode(t *testing.T) { } func TestAccepted_EncodeDecode(t *testing.T) { var typ Accepted - typ = make(Accepted) typ.SetFake() e := jx.Encoder{} @@ -80,7 +79,6 @@ func TestAccepted_EncodeDecode(t *testing.T) { require.True(t, std.Valid(data), "Encoded: %s", data) var typ2 Accepted - typ2 = make(Accepted) require.NoError(t, typ2.Decode(jx.DecodeBytes(data))) } func TestActionsApproveWorkflowRunForbidden_EncodeDecode(t *testing.T) { @@ -3379,7 +3377,6 @@ func TestAuthenticationToken_Examples(t *testing.T) { } func TestAuthenticationTokenPermissions_EncodeDecode(t *testing.T) { var typ AuthenticationTokenPermissions - typ = make(AuthenticationTokenPermissions) typ.SetFake() e := jx.Encoder{} @@ -3388,7 +3385,6 @@ func TestAuthenticationTokenPermissions_EncodeDecode(t *testing.T) { require.True(t, std.Valid(data), "Encoded: %s", data) var typ2 AuthenticationTokenPermissions - typ2 = make(AuthenticationTokenPermissions) require.NoError(t, typ2.Decode(jx.DecodeBytes(data))) } @@ -3402,7 +3398,6 @@ func TestAuthenticationTokenPermissions_Examples(t *testing.T) { tc := tc t.Run(fmt.Sprintf("Test%d", i+1), func(t *testing.T) { var typ AuthenticationTokenPermissions - typ = make(AuthenticationTokenPermissions) if err := typ.Decode(jx.DecodeStr(tc.Input)); err != nil { if validateErr, ok := errors.Into[*validate.Error](err); ok { @@ -3417,7 +3412,6 @@ func TestAuthenticationTokenPermissions_Examples(t *testing.T) { require.True(t, std.Valid(e.Bytes()), "Encoded: %s", e.Bytes()) var typ2 AuthenticationTokenPermissions - typ2 = make(AuthenticationTokenPermissions) require.NoError(t, typ2.Decode(jx.DecodeBytes(e.Bytes()))) }) } @@ -7273,7 +7267,6 @@ func TestEnterpriseAdminUpdateAttributeForEnterpriseGroupReqOperationsItemValue_ } func TestEnterpriseAdminUpdateAttributeForEnterpriseGroupReqOperationsItemValue1_EncodeDecode(t *testing.T) { var typ EnterpriseAdminUpdateAttributeForEnterpriseGroupReqOperationsItemValue1 - typ = make(EnterpriseAdminUpdateAttributeForEnterpriseGroupReqOperationsItemValue1) typ.SetFake() e := jx.Encoder{} @@ -7282,7 +7275,6 @@ func TestEnterpriseAdminUpdateAttributeForEnterpriseGroupReqOperationsItemValue1 require.True(t, std.Valid(data), "Encoded: %s", data) var typ2 EnterpriseAdminUpdateAttributeForEnterpriseGroupReqOperationsItemValue1 - typ2 = make(EnterpriseAdminUpdateAttributeForEnterpriseGroupReqOperationsItemValue1) require.NoError(t, typ2.Decode(jx.DecodeBytes(data))) } func TestEnterpriseAdminUpdateAttributeForEnterpriseUserReq_EncodeDecode(t *testing.T) { @@ -7328,7 +7320,6 @@ func TestEnterpriseAdminUpdateAttributeForEnterpriseUserReq_Examples(t *testing. } func TestEnterpriseAdminUpdateAttributeForEnterpriseUserReqOperationsItem_EncodeDecode(t *testing.T) { var typ EnterpriseAdminUpdateAttributeForEnterpriseUserReqOperationsItem - typ = make(EnterpriseAdminUpdateAttributeForEnterpriseUserReqOperationsItem) typ.SetFake() e := jx.Encoder{} @@ -7337,7 +7328,6 @@ func TestEnterpriseAdminUpdateAttributeForEnterpriseUserReqOperationsItem_Encode require.True(t, std.Valid(data), "Encoded: %s", data) var typ2 EnterpriseAdminUpdateAttributeForEnterpriseUserReqOperationsItem - typ2 = make(EnterpriseAdminUpdateAttributeForEnterpriseUserReqOperationsItem) require.NoError(t, typ2.Decode(jx.DecodeBytes(data))) } func TestEnterpriseAdminUpdateSelfHostedRunnerGroupForEnterpriseReq_EncodeDecode(t *testing.T) { diff --git a/examples/ex_gotd/oas_faker_gen.go b/examples/ex_gotd/oas_faker_gen.go index 0fe45265d..ab888a523 100644 --- a/examples/ex_gotd/oas_faker_gen.go +++ b/examples/ex_gotd/oas_faker_gen.go @@ -2,12 +2,6 @@ package api -import ( - "fmt" - - "github.com/go-faster/jx" -) - // SetFake set fake values. func (s *AddStickerToSet) SetFake() { { @@ -445,13 +439,6 @@ func (s *BotCommandScopeDefault) SetFake() { // SetFake set fake values. func (s *CallbackGame) SetFake() { - var ( - elem jx.Raw - m map[string]jx.Raw = s.init() - ) - for i := 0; i < 0; i++ { - m[fmt.Sprintf("fake%d", i)] = elem - } } // SetFake set fake values. @@ -2122,8 +2109,8 @@ func (s *InlineKeyboardButton) SetFake() { } } { - { - s.CallbackGame.SetFake() + { // Keep pointer nil to prevent infinite recursion. + s.CallbackGame = nil } } { @@ -4526,8 +4513,8 @@ func (s *Message) SetFake() { } } { - { - s.VideoChatStarted.SetFake() + { // Keep pointer nil to prevent infinite recursion. + s.VideoChatStarted = nil } } { @@ -4660,15 +4647,6 @@ func (s *OptBotCommandScope) SetFake() { s.SetTo(elem) } -// SetFake set fake values. -func (s *OptCallbackGame) SetFake() { - var elem CallbackGame - { - elem.SetFake() - } - s.SetTo(elem) -} - // SetFake set fake values. func (s *OptCallbackQuery) SetFake() { var elem CallbackQuery @@ -5254,15 +5232,6 @@ func (s *OptVideoChatScheduled) SetFake() { s.SetTo(elem) } -// SetFake set fake values. -func (s *OptVideoChatStarted) SetFake() { - var elem VideoChatStarted - { - elem.SetFake() - } - s.SetTo(elem) -} - // SetFake set fake values. func (s *OptVideoNote) SetFake() { var elem VideoNote @@ -8503,13 +8472,6 @@ func (s *VideoChatScheduled) SetFake() { // SetFake set fake values. func (s *VideoChatStarted) SetFake() { - var ( - elem jx.Raw - m map[string]jx.Raw = s.init() - ) - for i := 0; i < 0; i++ { - m[fmt.Sprintf("fake%d", i)] = elem - } } // SetFake set fake values. diff --git a/examples/ex_gotd/oas_json_gen.go b/examples/ex_gotd/oas_json_gen.go index 50ba03cf2..93ffeb5bf 100644 --- a/examples/ex_gotd/oas_json_gen.go +++ b/examples/ex_gotd/oas_json_gen.go @@ -2832,43 +2832,29 @@ func (s *BotCommandScopeDefault) UnmarshalJSON(data []byte) error { } // Encode implements json.Marshaler. -func (s CallbackGame) Encode(e *jx.Encoder) { +func (s *CallbackGame) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } -// encodeFields implements json.Marshaler. -func (s CallbackGame) encodeFields(e *jx.Encoder) { - for k, elem := range s { - e.FieldStart(k) - - if len(elem) != 0 { - e.Raw(elem) - } - } +// encodeFields encodes fields. +func (s *CallbackGame) encodeFields(e *jx.Encoder) { } +var jsonFieldsNameOfCallbackGame = [0]string{} + // Decode decodes CallbackGame from json. func (s *CallbackGame) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode CallbackGame to nil") } - m := s.init() + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { - var elem jx.Raw - if err := func() error { - v, err := d.RawAppend(nil) - elem = jx.Raw(v) - if err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrapf(err, "decode field %q", k) - } - m[string(k)] = elem - return nil + switch string(k) { + default: + return d.Skip() + } }); err != nil { return errors.Wrap(err, "decode CallbackGame") } @@ -2877,7 +2863,7 @@ func (s *CallbackGame) Decode(d *jx.Decoder) error { } // MarshalJSON implements stdjson.Marshaler. -func (s CallbackGame) MarshalJSON() ([]byte, error) { +func (s *CallbackGame) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil @@ -12028,7 +12014,7 @@ func (s *InlineKeyboardButton) encodeFields(e *jx.Encoder) { } } { - if s.CallbackGame.Set { + if s.CallbackGame != nil { e.FieldStart("callback_game") s.CallbackGame.Encode(e) } @@ -12136,10 +12122,12 @@ func (s *InlineKeyboardButton) Decode(d *jx.Decoder) error { } case "callback_game": if err := func() error { - s.CallbackGame.Reset() - if err := s.CallbackGame.Decode(d); err != nil { + s.CallbackGame = nil + var elem CallbackGame + if err := elem.Decode(d); err != nil { return err } + s.CallbackGame = &elem return nil }(); err != nil { return errors.Wrap(err, "decode field \"callback_game\"") @@ -23949,7 +23937,7 @@ func (s *Message) encodeFields(e *jx.Encoder) { } } { - if s.VideoChatStarted.Set { + if s.VideoChatStarted != nil { e.FieldStart("video_chat_started") s.VideoChatStarted.Encode(e) } @@ -24657,10 +24645,12 @@ func (s *Message) Decode(d *jx.Decoder) error { } case "video_chat_started": if err := func() error { - s.VideoChatStarted.Reset() - if err := s.VideoChatStarted.Decode(d); err != nil { + s.VideoChatStarted = nil + var elem VideoChatStarted + if err := elem.Decode(d); err != nil { return err } + s.VideoChatStarted = &elem return nil }(); err != nil { return errors.Wrap(err, "decode field \"video_chat_started\"") @@ -25372,40 +25362,6 @@ func (s *OptBotCommandScope) UnmarshalJSON(data []byte) error { return s.Decode(d) } -// Encode encodes CallbackGame as json. -func (o OptCallbackGame) Encode(e *jx.Encoder) { - if !o.Set { - return - } - o.Value.Encode(e) -} - -// Decode decodes CallbackGame from json. -func (o *OptCallbackGame) Decode(d *jx.Decoder) error { - if o == nil { - return errors.New("invalid: unable to decode OptCallbackGame to nil") - } - o.Set = true - o.Value = make(CallbackGame) - if err := o.Value.Decode(d); err != nil { - return err - } - return nil -} - -// MarshalJSON implements stdjson.Marshaler. -func (s OptCallbackGame) MarshalJSON() ([]byte, error) { - e := jx.Encoder{} - s.Encode(&e) - return e.Bytes(), nil -} - -// UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptCallbackGame) UnmarshalJSON(data []byte) error { - d := jx.DecodeBytes(data) - return s.Decode(d) -} - // Encode encodes CallbackQuery as json. func (o OptCallbackQuery) Encode(e *jx.Encoder) { if !o.Set { @@ -27559,40 +27515,6 @@ func (s *OptVideoChatScheduled) UnmarshalJSON(data []byte) error { return s.Decode(d) } -// Encode encodes VideoChatStarted as json. -func (o OptVideoChatStarted) Encode(e *jx.Encoder) { - if !o.Set { - return - } - o.Value.Encode(e) -} - -// Decode decodes VideoChatStarted from json. -func (o *OptVideoChatStarted) Decode(d *jx.Decoder) error { - if o == nil { - return errors.New("invalid: unable to decode OptVideoChatStarted to nil") - } - o.Set = true - o.Value = make(VideoChatStarted) - if err := o.Value.Decode(d); err != nil { - return err - } - return nil -} - -// MarshalJSON implements stdjson.Marshaler. -func (s OptVideoChatStarted) MarshalJSON() ([]byte, error) { - e := jx.Encoder{} - s.Encode(&e) - return e.Bytes(), nil -} - -// UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptVideoChatStarted) UnmarshalJSON(data []byte) error { - d := jx.DecodeBytes(data) - return s.Decode(d) -} - // Encode encodes VideoNote as json. func (o OptVideoNote) Encode(e *jx.Encoder) { if !o.Set { @@ -45289,43 +45211,29 @@ func (s *VideoChatScheduled) UnmarshalJSON(data []byte) error { } // Encode implements json.Marshaler. -func (s VideoChatStarted) Encode(e *jx.Encoder) { +func (s *VideoChatStarted) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } -// encodeFields implements json.Marshaler. -func (s VideoChatStarted) encodeFields(e *jx.Encoder) { - for k, elem := range s { - e.FieldStart(k) - - if len(elem) != 0 { - e.Raw(elem) - } - } +// encodeFields encodes fields. +func (s *VideoChatStarted) encodeFields(e *jx.Encoder) { } +var jsonFieldsNameOfVideoChatStarted = [0]string{} + // Decode decodes VideoChatStarted from json. func (s *VideoChatStarted) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode VideoChatStarted to nil") } - m := s.init() + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { - var elem jx.Raw - if err := func() error { - v, err := d.RawAppend(nil) - elem = jx.Raw(v) - if err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrapf(err, "decode field %q", k) - } - m[string(k)] = elem - return nil + switch string(k) { + default: + return d.Skip() + } }); err != nil { return errors.Wrap(err, "decode VideoChatStarted") } @@ -45334,7 +45242,7 @@ func (s *VideoChatStarted) Decode(d *jx.Decoder) error { } // MarshalJSON implements stdjson.Marshaler. -func (s VideoChatStarted) MarshalJSON() ([]byte, error) { +func (s *VideoChatStarted) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil diff --git a/examples/ex_gotd/oas_schemas_gen.go b/examples/ex_gotd/oas_schemas_gen.go index 7ac19668c..1822188f0 100644 --- a/examples/ex_gotd/oas_schemas_gen.go +++ b/examples/ex_gotd/oas_schemas_gen.go @@ -6,7 +6,6 @@ import ( "fmt" "github.com/go-faster/errors" - "github.com/go-faster/jx" ) func (s *ErrorStatusCode) Error() string { @@ -1152,16 +1151,7 @@ func (s *BotCommandScopeDefault) SetType(val string) { // A placeholder, currently holds no information. Use BotFather to set up your game. // Ref: #/components/schemas/CallbackGame -type CallbackGame map[string]jx.Raw - -func (s *CallbackGame) init() CallbackGame { - m := *s - if m == nil { - m = map[string]jx.Raw{} - *s = m - } - return m -} +type CallbackGame struct{} // This object represents an incoming callback query from a callback button in an inline keyboard. If // the button that originated the query was attached to a message sent by the bot, the field message @@ -5109,8 +5099,8 @@ type InlineKeyboardButton struct { // current chat's input field. Can be empty, in which case only the bot's username will be inserted. // This offers a quick way for the user to open your bot in inline mode in the same chat – good for // selecting something from multiple options. - SwitchInlineQueryCurrentChat OptString `json:"switch_inline_query_current_chat"` - CallbackGame OptCallbackGame `json:"callback_game"` + SwitchInlineQueryCurrentChat OptString `json:"switch_inline_query_current_chat"` + CallbackGame *CallbackGame `json:"callback_game"` // Specify True, to send a Pay button.NOTE: This type of button must always be the first button in // the first row and can only be used in invoice messages. Pay OptBool `json:"pay"` @@ -5152,7 +5142,7 @@ func (s *InlineKeyboardButton) GetSwitchInlineQueryCurrentChat() OptString { } // GetCallbackGame returns the value of CallbackGame. -func (s *InlineKeyboardButton) GetCallbackGame() OptCallbackGame { +func (s *InlineKeyboardButton) GetCallbackGame() *CallbackGame { return s.CallbackGame } @@ -5197,7 +5187,7 @@ func (s *InlineKeyboardButton) SetSwitchInlineQueryCurrentChat(val OptString) { } // SetCallbackGame sets the value of CallbackGame. -func (s *InlineKeyboardButton) SetCallbackGame(val OptCallbackGame) { +func (s *InlineKeyboardButton) SetCallbackGame(val *CallbackGame) { s.CallbackGame = val } @@ -10751,7 +10741,7 @@ type Message struct { PassportData OptPassportData `json:"passport_data"` ProximityAlertTriggered OptProximityAlertTriggered `json:"proximity_alert_triggered"` VideoChatScheduled OptVideoChatScheduled `json:"video_chat_scheduled"` - VideoChatStarted OptVideoChatStarted `json:"video_chat_started"` + VideoChatStarted *VideoChatStarted `json:"video_chat_started"` VideoChatEnded OptVideoChatEnded `json:"video_chat_ended"` VideoChatParticipantsInvited OptVideoChatParticipantsInvited `json:"video_chat_participants_invited"` WebAppData OptWebAppData `json:"web_app_data"` @@ -11032,7 +11022,7 @@ func (s *Message) GetVideoChatScheduled() OptVideoChatScheduled { } // GetVideoChatStarted returns the value of VideoChatStarted. -func (s *Message) GetVideoChatStarted() OptVideoChatStarted { +func (s *Message) GetVideoChatStarted() *VideoChatStarted { return s.VideoChatStarted } @@ -11342,7 +11332,7 @@ func (s *Message) SetVideoChatScheduled(val OptVideoChatScheduled) { } // SetVideoChatStarted sets the value of VideoChatStarted. -func (s *Message) SetVideoChatStarted(val OptVideoChatStarted) { +func (s *Message) SetVideoChatStarted(val *VideoChatStarted) { s.VideoChatStarted = val } @@ -11826,52 +11816,6 @@ func (o OptBotCommandScope) Or(d BotCommandScope) BotCommandScope { return d } -// NewOptCallbackGame returns new OptCallbackGame with value set to v. -func NewOptCallbackGame(v CallbackGame) OptCallbackGame { - return OptCallbackGame{ - Value: v, - Set: true, - } -} - -// OptCallbackGame is optional CallbackGame. -type OptCallbackGame struct { - Value CallbackGame - Set bool -} - -// IsSet returns true if OptCallbackGame was set. -func (o OptCallbackGame) IsSet() bool { return o.Set } - -// Reset unsets value. -func (o *OptCallbackGame) Reset() { - var v CallbackGame - o.Value = v - o.Set = false -} - -// SetTo sets value to v. -func (o *OptCallbackGame) SetTo(v CallbackGame) { - o.Set = true - o.Value = v -} - -// Get returns value and boolean that denotes whether value was set. -func (o OptCallbackGame) Get() (v CallbackGame, ok bool) { - if !o.Set { - return v, false - } - return o.Value, true -} - -// Or returns value if set, or given parameter if does not. -func (o OptCallbackGame) Or(d CallbackGame) CallbackGame { - if v, ok := o.Get(); ok { - return v - } - return d -} - // NewOptCallbackQuery returns new OptCallbackQuery with value set to v. func NewOptCallbackQuery(v CallbackQuery) OptCallbackQuery { return OptCallbackQuery{ @@ -14862,52 +14806,6 @@ func (o OptVideoChatScheduled) Or(d VideoChatScheduled) VideoChatScheduled { return d } -// NewOptVideoChatStarted returns new OptVideoChatStarted with value set to v. -func NewOptVideoChatStarted(v VideoChatStarted) OptVideoChatStarted { - return OptVideoChatStarted{ - Value: v, - Set: true, - } -} - -// OptVideoChatStarted is optional VideoChatStarted. -type OptVideoChatStarted struct { - Value VideoChatStarted - Set bool -} - -// IsSet returns true if OptVideoChatStarted was set. -func (o OptVideoChatStarted) IsSet() bool { return o.Set } - -// Reset unsets value. -func (o *OptVideoChatStarted) Reset() { - var v VideoChatStarted - o.Value = v - o.Set = false -} - -// SetTo sets value to v. -func (o *OptVideoChatStarted) SetTo(v VideoChatStarted) { - o.Set = true - o.Value = v -} - -// Get returns value and boolean that denotes whether value was set. -func (o OptVideoChatStarted) Get() (v VideoChatStarted, ok bool) { - if !o.Set { - return v, false - } - return o.Value, true -} - -// Or returns value if set, or given parameter if does not. -func (o OptVideoChatStarted) Or(d VideoChatStarted) VideoChatStarted { - if v, ok := o.Get(); ok { - return v - } - return d -} - // NewOptVideoNote returns new OptVideoNote with value set to v. func NewOptVideoNote(v VideoNote) OptVideoNote { return OptVideoNote{ @@ -22793,16 +22691,7 @@ func (s *VideoChatScheduled) SetStartDate(val int) { // This object represents a service message about a video chat started in the chat. Currently holds // no information. // Ref: #/components/schemas/VideoChatStarted -type VideoChatStarted map[string]jx.Raw - -func (s *VideoChatStarted) init() VideoChatStarted { - m := *s - if m == nil { - m = map[string]jx.Raw{} - *s = m - } - return m -} +type VideoChatStarted struct{} // This object represents a video message (available in Telegram apps as of v.4.0). // Ref: #/components/schemas/VideoNote diff --git a/examples/ex_gotd/oas_test_examples_gen_test.go b/examples/ex_gotd/oas_test_examples_gen_test.go index 12733518f..a23527f77 100644 --- a/examples/ex_gotd/oas_test_examples_gen_test.go +++ b/examples/ex_gotd/oas_test_examples_gen_test.go @@ -253,7 +253,6 @@ func TestBotCommandScopeDefault_EncodeDecode(t *testing.T) { } func TestCallbackGame_EncodeDecode(t *testing.T) { var typ CallbackGame - typ = make(CallbackGame) typ.SetFake() e := jx.Encoder{} @@ -262,7 +261,6 @@ func TestCallbackGame_EncodeDecode(t *testing.T) { require.True(t, std.Valid(data), "Encoded: %s", data) var typ2 CallbackGame - typ2 = make(CallbackGame) require.NoError(t, typ2.Decode(jx.DecodeBytes(data))) } func TestCallbackQuery_EncodeDecode(t *testing.T) { @@ -2979,7 +2977,6 @@ func TestVideoChatScheduled_EncodeDecode(t *testing.T) { } func TestVideoChatStarted_EncodeDecode(t *testing.T) { var typ VideoChatStarted - typ = make(VideoChatStarted) typ.SetFake() e := jx.Encoder{} @@ -2988,7 +2985,6 @@ func TestVideoChatStarted_EncodeDecode(t *testing.T) { require.True(t, std.Valid(data), "Encoded: %s", data) var typ2 VideoChatStarted - typ2 = make(VideoChatStarted) require.NoError(t, typ2.Decode(jx.DecodeBytes(data))) } func TestVideoNote_EncodeDecode(t *testing.T) { diff --git a/examples/ex_k8s/oas_faker_gen.go b/examples/ex_k8s/oas_faker_gen.go index d5037031e..93a591c40 100644 --- a/examples/ex_k8s/oas_faker_gen.go +++ b/examples/ex_k8s/oas_faker_gen.go @@ -5,8 +5,6 @@ package api import ( "fmt" "time" - - "github.com/go-faster/jx" ) // SetFake set fake values. @@ -505,13 +503,6 @@ func (s *IoK8sAPIApiserverinternalV1alpha1StorageVersionList) SetFake() { // SetFake set fake values. func (s *IoK8sAPIApiserverinternalV1alpha1StorageVersionSpec) SetFake() { - var ( - elem jx.Raw - m map[string]jx.Raw = s.init() - ) - for i := 0; i < 0; i++ { - m[fmt.Sprintf("fake%d", i)] = elem - } } // SetFake set fake values. @@ -555,8 +546,8 @@ func (s *IoK8sAPIAppsV1ControllerRevision) SetFake() { } } { - { - s.Data.SetFake() + { // Keep pointer nil to prevent infinite recursion. + s.Data = nil } } { @@ -14327,13 +14318,6 @@ func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresou // SetFake set fake values. func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus) SetFake() { - var ( - elem jx.Raw - m map[string]jx.Raw = s.init() - ) - for i := 0; i < 0; i++ { - m[fmt.Sprintf("fake%d", i)] = elem - } } // SetFake set fake values. @@ -14344,8 +14328,8 @@ func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresou } } { - { - s.Status.SetFake() + { // Keep pointer nil to prevent infinite recursion. + s.Status = nil } } } @@ -14375,13 +14359,6 @@ func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1ExternalDocumentation) // SetFake set fake values. func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON) SetFake() { - var ( - elem jx.Raw - m map[string]jx.Raw = s.init() - ) - for i := 0; i < 0; i++ { - m[fmt.Sprintf("fake%d", i)] = elem - } } // SetFake set fake values. @@ -14397,13 +14374,13 @@ func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps) SetFa } } { - { - s.AdditionalItems.SetFake() + { // Keep pointer nil to prevent infinite recursion. + s.AdditionalItems = nil } } { - { - s.AdditionalProperties.SetFake() + { // Keep pointer nil to prevent infinite recursion. + s.AdditionalProperties = nil } } { @@ -14431,8 +14408,8 @@ func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps) SetFa } } { - { - s.Default.SetFake() + { // Keep pointer nil to prevent infinite recursion. + s.Default = nil } } { @@ -14463,8 +14440,8 @@ func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps) SetFa } } { - { - s.Example.SetFake() + { // Keep pointer nil to prevent infinite recursion. + s.Example = nil } } { @@ -14493,8 +14470,8 @@ func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps) SetFa } } { - { - s.Items.SetFake() + { // Keep pointer nil to prevent infinite recursion. + s.Items = nil } } { @@ -14669,35 +14646,14 @@ func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsDepende // SetFake set fake values. func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray) SetFake() { - var ( - elem jx.Raw - m map[string]jx.Raw = s.init() - ) - for i := 0; i < 0; i++ { - m[fmt.Sprintf("fake%d", i)] = elem - } } // SetFake set fake values. func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool) SetFake() { - var ( - elem jx.Raw - m map[string]jx.Raw = s.init() - ) - for i := 0; i < 0; i++ { - m[fmt.Sprintf("fake%d", i)] = elem - } } // SetFake set fake values. func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrStringArray) SetFake() { - var ( - elem jx.Raw - m map[string]jx.Raw = s.init() - ) - for i := 0; i < 0; i++ { - m[fmt.Sprintf("fake%d", i)] = elem - } } // SetFake set fake values. @@ -15049,13 +15005,6 @@ func (s *IoK8sApimachineryPkgApisMetaV1Condition) SetFake() { // SetFake set fake values. func (s *IoK8sApimachineryPkgApisMetaV1FieldsV1) SetFake() { - var ( - elem jx.Raw - m map[string]jx.Raw = s.init() - ) - for i := 0; i < 0; i++ { - m[fmt.Sprintf("fake%d", i)] = elem - } } // SetFake set fake values. @@ -15167,8 +15116,8 @@ func (s *IoK8sApimachineryPkgApisMetaV1ManagedFieldsEntry) SetFake() { } } { - { - s.FieldsV1.SetFake() + { // Keep pointer nil to prevent infinite recursion. + s.FieldsV1 = nil } } { @@ -15402,13 +15351,6 @@ func (s *IoK8sApimachineryPkgApisMetaV1WatchEvent) SetFake() { // SetFake set fake values. func (s *IoK8sApimachineryPkgRuntimeRawExtension) SetFake() { - var ( - elem jx.Raw - m map[string]jx.Raw = s.init() - ) - for i := 0; i < 0; i++ { - m[fmt.Sprintf("fake%d", i)] = elem - } } // SetFake set fake values. @@ -18026,15 +17968,6 @@ func (s *OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubre s.SetTo(elem) } -// SetFake set fake values. -func (s *OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus) SetFake() { - var elem IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus - { - elem.SetFake() - } - s.SetTo(elem) -} - // SetFake set fake values. func (s *OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresources) SetFake() { var elem IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresources @@ -18062,15 +17995,6 @@ func (s *OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1ExternalDocumentati s.SetTo(elem) } -// SetFake set fake values. -func (s *OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON) SetFake() { - var elem IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON - { - elem.SetFake() - } - s.SetTo(elem) -} - // SetFake set fake values. func (s *OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps) SetFake() { var elem IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps @@ -18098,24 +18022,6 @@ func (s *OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsDepe s.SetTo(elem) } -// SetFake set fake values. -func (s *OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray) SetFake() { - var elem IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray - { - elem.SetFake() - } - s.SetTo(elem) -} - -// SetFake set fake values. -func (s *OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool) SetFake() { - var elem IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool - { - elem.SetFake() - } - s.SetTo(elem) -} - // SetFake set fake values. func (s *OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsPatternProperties) SetFake() { var elem IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsPatternProperties @@ -18170,15 +18076,6 @@ func (s *OptIoK8sApimachineryPkgAPIResourceQuantity) SetFake() { s.SetTo(elem) } -// SetFake set fake values. -func (s *OptIoK8sApimachineryPkgApisMetaV1FieldsV1) SetFake() { - var elem IoK8sApimachineryPkgApisMetaV1FieldsV1 - { - elem.SetFake() - } - s.SetTo(elem) -} - // SetFake set fake values. func (s *OptIoK8sApimachineryPkgApisMetaV1GroupVersionForDiscovery) SetFake() { var elem IoK8sApimachineryPkgApisMetaV1GroupVersionForDiscovery @@ -18260,15 +18157,6 @@ func (s *OptIoK8sApimachineryPkgApisMetaV1Time) SetFake() { s.SetTo(elem) } -// SetFake set fake values. -func (s *OptIoK8sApimachineryPkgRuntimeRawExtension) SetFake() { - var elem IoK8sApimachineryPkgRuntimeRawExtension - { - elem.SetFake() - } - s.SetTo(elem) -} - // SetFake set fake values. func (s *OptIoK8sApimachineryPkgUtilIntstrIntOrString) SetFake() { var elem IoK8sApimachineryPkgUtilIntstrIntOrString diff --git a/examples/ex_k8s/oas_json_gen.go b/examples/ex_k8s/oas_json_gen.go index 50b00eb29..b0a9084d1 100644 --- a/examples/ex_k8s/oas_json_gen.go +++ b/examples/ex_k8s/oas_json_gen.go @@ -2212,43 +2212,29 @@ func (s *IoK8sAPIApiserverinternalV1alpha1StorageVersionList) UnmarshalJSON(data } // Encode implements json.Marshaler. -func (s IoK8sAPIApiserverinternalV1alpha1StorageVersionSpec) Encode(e *jx.Encoder) { +func (s *IoK8sAPIApiserverinternalV1alpha1StorageVersionSpec) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } -// encodeFields implements json.Marshaler. -func (s IoK8sAPIApiserverinternalV1alpha1StorageVersionSpec) encodeFields(e *jx.Encoder) { - for k, elem := range s { - e.FieldStart(k) - - if len(elem) != 0 { - e.Raw(elem) - } - } +// encodeFields encodes fields. +func (s *IoK8sAPIApiserverinternalV1alpha1StorageVersionSpec) encodeFields(e *jx.Encoder) { } +var jsonFieldsNameOfIoK8sAPIApiserverinternalV1alpha1StorageVersionSpec = [0]string{} + // Decode decodes IoK8sAPIApiserverinternalV1alpha1StorageVersionSpec from json. func (s *IoK8sAPIApiserverinternalV1alpha1StorageVersionSpec) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode IoK8sAPIApiserverinternalV1alpha1StorageVersionSpec to nil") } - m := s.init() + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { - var elem jx.Raw - if err := func() error { - v, err := d.RawAppend(nil) - elem = jx.Raw(v) - if err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrapf(err, "decode field %q", k) + switch string(k) { + default: + return d.Skip() } - m[string(k)] = elem - return nil }); err != nil { return errors.Wrap(err, "decode IoK8sAPIApiserverinternalV1alpha1StorageVersionSpec") } @@ -2257,7 +2243,7 @@ func (s *IoK8sAPIApiserverinternalV1alpha1StorageVersionSpec) Decode(d *jx.Decod } // MarshalJSON implements stdjson.Marshaler. -func (s IoK8sAPIApiserverinternalV1alpha1StorageVersionSpec) MarshalJSON() ([]byte, error) { +func (s *IoK8sAPIApiserverinternalV1alpha1StorageVersionSpec) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil @@ -2404,7 +2390,7 @@ func (s *IoK8sAPIAppsV1ControllerRevision) encodeFields(e *jx.Encoder) { } } { - if s.Data.Set { + if s.Data != nil { e.FieldStart("data") s.Data.Encode(e) } @@ -2456,10 +2442,12 @@ func (s *IoK8sAPIAppsV1ControllerRevision) Decode(d *jx.Decoder) error { } case "data": if err := func() error { - s.Data.Reset() - if err := s.Data.Decode(d); err != nil { + s.Data = nil + var elem IoK8sApimachineryPkgRuntimeRawExtension + if err := elem.Decode(d); err != nil { return err } + s.Data = &elem return nil }(); err != nil { return errors.Wrap(err, "decode field \"data\"") @@ -70472,43 +70460,29 @@ func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresou } // Encode implements json.Marshaler. -func (s IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus) Encode(e *jx.Encoder) { +func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } -// encodeFields implements json.Marshaler. -func (s IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus) encodeFields(e *jx.Encoder) { - for k, elem := range s { - e.FieldStart(k) - - if len(elem) != 0 { - e.Raw(elem) - } - } +// encodeFields encodes fields. +func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus) encodeFields(e *jx.Encoder) { } +var jsonFieldsNameOfIoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus = [0]string{} + // Decode decodes IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus from json. func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus to nil") } - m := s.init() + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { - var elem jx.Raw - if err := func() error { - v, err := d.RawAppend(nil) - elem = jx.Raw(v) - if err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrapf(err, "decode field %q", k) + switch string(k) { + default: + return d.Skip() } - m[string(k)] = elem - return nil }); err != nil { return errors.Wrap(err, "decode IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus") } @@ -70517,7 +70491,7 @@ func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresou } // MarshalJSON implements stdjson.Marshaler. -func (s IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus) MarshalJSON() ([]byte, error) { +func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil @@ -70545,7 +70519,7 @@ func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresou } } { - if s.Status.Set { + if s.Status != nil { e.FieldStart("status") s.Status.Encode(e) } @@ -70577,10 +70551,12 @@ func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresou } case "status": if err := func() error { - s.Status.Reset() - if err := s.Status.Decode(d); err != nil { + s.Status = nil + var elem IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus + if err := elem.Decode(d); err != nil { return err } + s.Status = &elem return nil }(); err != nil { return errors.Wrap(err, "decode field \"status\"") @@ -70753,43 +70729,29 @@ func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1ExternalDocumentation) } // Encode implements json.Marshaler. -func (s IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON) Encode(e *jx.Encoder) { +func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } -// encodeFields implements json.Marshaler. -func (s IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON) encodeFields(e *jx.Encoder) { - for k, elem := range s { - e.FieldStart(k) - - if len(elem) != 0 { - e.Raw(elem) - } - } +// encodeFields encodes fields. +func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON) encodeFields(e *jx.Encoder) { } +var jsonFieldsNameOfIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON = [0]string{} + // Decode decodes IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON from json. func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON to nil") } - m := s.init() + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { - var elem jx.Raw - if err := func() error { - v, err := d.RawAppend(nil) - elem = jx.Raw(v) - if err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrapf(err, "decode field %q", k) + switch string(k) { + default: + return d.Skip() } - m[string(k)] = elem - return nil }); err != nil { return errors.Wrap(err, "decode IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON") } @@ -70798,7 +70760,7 @@ func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON) Decode(d *jx.Dec } // MarshalJSON implements stdjson.Marshaler. -func (s IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON) MarshalJSON() ([]byte, error) { +func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil @@ -70832,13 +70794,13 @@ func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps) encod } } { - if s.AdditionalItems.Set { + if s.AdditionalItems != nil { e.FieldStart("additionalItems") s.AdditionalItems.Encode(e) } } { - if s.AdditionalProperties.Set { + if s.AdditionalProperties != nil { e.FieldStart("additionalProperties") s.AdditionalProperties.Encode(e) } @@ -70864,7 +70826,7 @@ func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps) encod } } { - if s.Default.Set { + if s.Default != nil { e.FieldStart("default") s.Default.Encode(e) } @@ -70898,7 +70860,7 @@ func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps) encod } } { - if s.Example.Set { + if s.Example != nil { e.FieldStart("example") s.Example.Encode(e) } @@ -70934,7 +70896,7 @@ func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps) encod } } { - if s.Items.Set { + if s.Items != nil { e.FieldStart("items") s.Items.Encode(e) } @@ -71179,20 +71141,24 @@ func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps) Decod } case "additionalItems": if err := func() error { - s.AdditionalItems.Reset() - if err := s.AdditionalItems.Decode(d); err != nil { + s.AdditionalItems = nil + var elem IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool + if err := elem.Decode(d); err != nil { return err } + s.AdditionalItems = &elem return nil }(); err != nil { return errors.Wrap(err, "decode field \"additionalItems\"") } case "additionalProperties": if err := func() error { - s.AdditionalProperties.Reset() - if err := s.AdditionalProperties.Decode(d); err != nil { + s.AdditionalProperties = nil + var elem IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool + if err := elem.Decode(d); err != nil { return err } + s.AdditionalProperties = &elem return nil }(); err != nil { return errors.Wrap(err, "decode field \"additionalProperties\"") @@ -71233,10 +71199,12 @@ func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps) Decod } case "default": if err := func() error { - s.Default.Reset() - if err := s.Default.Decode(d); err != nil { + s.Default = nil + var elem IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON + if err := elem.Decode(d); err != nil { return err } + s.Default = &elem return nil }(); err != nil { return errors.Wrap(err, "decode field \"default\"") @@ -71290,10 +71258,12 @@ func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps) Decod } case "example": if err := func() error { - s.Example.Reset() - if err := s.Example.Decode(d); err != nil { + s.Example = nil + var elem IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON + if err := elem.Decode(d); err != nil { return err } + s.Example = &elem return nil }(); err != nil { return errors.Wrap(err, "decode field \"example\"") @@ -71350,10 +71320,12 @@ func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps) Decod } case "items": if err := func() error { - s.Items.Reset() - if err := s.Items.Decode(d); err != nil { + s.Items = nil + var elem IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray + if err := elem.Decode(d); err != nil { return err } + s.Items = &elem return nil }(); err != nil { return errors.Wrap(err, "decode field \"items\"") @@ -71768,43 +71740,29 @@ func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsDepende } // Encode implements json.Marshaler. -func (s IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray) Encode(e *jx.Encoder) { +func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } -// encodeFields implements json.Marshaler. -func (s IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray) encodeFields(e *jx.Encoder) { - for k, elem := range s { - e.FieldStart(k) - - if len(elem) != 0 { - e.Raw(elem) - } - } +// encodeFields encodes fields. +func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray) encodeFields(e *jx.Encoder) { } +var jsonFieldsNameOfIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray = [0]string{} + // Decode decodes IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray from json. func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray to nil") } - m := s.init() + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { - var elem jx.Raw - if err := func() error { - v, err := d.RawAppend(nil) - elem = jx.Raw(v) - if err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrapf(err, "decode field %q", k) + switch string(k) { + default: + return d.Skip() } - m[string(k)] = elem - return nil }); err != nil { return errors.Wrap(err, "decode IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray") } @@ -71813,7 +71771,7 @@ func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray } // MarshalJSON implements stdjson.Marshaler. -func (s IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray) MarshalJSON() ([]byte, error) { +func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil @@ -71826,43 +71784,29 @@ func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray } // Encode implements json.Marshaler. -func (s IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool) Encode(e *jx.Encoder) { +func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } -// encodeFields implements json.Marshaler. -func (s IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool) encodeFields(e *jx.Encoder) { - for k, elem := range s { - e.FieldStart(k) - - if len(elem) != 0 { - e.Raw(elem) - } - } +// encodeFields encodes fields. +func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool) encodeFields(e *jx.Encoder) { } +var jsonFieldsNameOfIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool = [0]string{} + // Decode decodes IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool from json. func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool to nil") } - m := s.init() + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { - var elem jx.Raw - if err := func() error { - v, err := d.RawAppend(nil) - elem = jx.Raw(v) - if err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrapf(err, "decode field %q", k) + switch string(k) { + default: + return d.Skip() } - m[string(k)] = elem - return nil }); err != nil { return errors.Wrap(err, "decode IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool") } @@ -71871,7 +71815,7 @@ func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool) } // MarshalJSON implements stdjson.Marshaler. -func (s IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool) MarshalJSON() ([]byte, error) { +func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil @@ -71884,43 +71828,29 @@ func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool) } // Encode implements json.Marshaler. -func (s IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrStringArray) Encode(e *jx.Encoder) { +func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrStringArray) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } -// encodeFields implements json.Marshaler. -func (s IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrStringArray) encodeFields(e *jx.Encoder) { - for k, elem := range s { - e.FieldStart(k) - - if len(elem) != 0 { - e.Raw(elem) - } - } +// encodeFields encodes fields. +func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrStringArray) encodeFields(e *jx.Encoder) { } +var jsonFieldsNameOfIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrStringArray = [0]string{} + // Decode decodes IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrStringArray from json. func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrStringArray) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrStringArray to nil") } - m := s.init() + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { - var elem jx.Raw - if err := func() error { - v, err := d.RawAppend(nil) - elem = jx.Raw(v) - if err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrapf(err, "decode field %q", k) + switch string(k) { + default: + return d.Skip() } - m[string(k)] = elem - return nil }); err != nil { return errors.Wrap(err, "decode IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrStringArray") } @@ -71929,7 +71859,7 @@ func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrStrin } // MarshalJSON implements stdjson.Marshaler. -func (s IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrStringArray) MarshalJSON() ([]byte, error) { +func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrStringArray) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil @@ -73593,43 +73523,29 @@ func (s *IoK8sApimachineryPkgApisMetaV1Condition) UnmarshalJSON(data []byte) err } // Encode implements json.Marshaler. -func (s IoK8sApimachineryPkgApisMetaV1FieldsV1) Encode(e *jx.Encoder) { +func (s *IoK8sApimachineryPkgApisMetaV1FieldsV1) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } -// encodeFields implements json.Marshaler. -func (s IoK8sApimachineryPkgApisMetaV1FieldsV1) encodeFields(e *jx.Encoder) { - for k, elem := range s { - e.FieldStart(k) - - if len(elem) != 0 { - e.Raw(elem) - } - } +// encodeFields encodes fields. +func (s *IoK8sApimachineryPkgApisMetaV1FieldsV1) encodeFields(e *jx.Encoder) { } +var jsonFieldsNameOfIoK8sApimachineryPkgApisMetaV1FieldsV1 = [0]string{} + // Decode decodes IoK8sApimachineryPkgApisMetaV1FieldsV1 from json. func (s *IoK8sApimachineryPkgApisMetaV1FieldsV1) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode IoK8sApimachineryPkgApisMetaV1FieldsV1 to nil") } - m := s.init() + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { - var elem jx.Raw - if err := func() error { - v, err := d.RawAppend(nil) - elem = jx.Raw(v) - if err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrapf(err, "decode field %q", k) + switch string(k) { + default: + return d.Skip() } - m[string(k)] = elem - return nil }); err != nil { return errors.Wrap(err, "decode IoK8sApimachineryPkgApisMetaV1FieldsV1") } @@ -73638,7 +73554,7 @@ func (s *IoK8sApimachineryPkgApisMetaV1FieldsV1) Decode(d *jx.Decoder) error { } // MarshalJSON implements stdjson.Marshaler. -func (s IoK8sApimachineryPkgApisMetaV1FieldsV1) MarshalJSON() ([]byte, error) { +func (s *IoK8sApimachineryPkgApisMetaV1FieldsV1) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil @@ -74189,7 +74105,7 @@ func (s *IoK8sApimachineryPkgApisMetaV1ManagedFieldsEntry) encodeFields(e *jx.En } } { - if s.FieldsV1.Set { + if s.FieldsV1 != nil { e.FieldStart("fieldsV1") s.FieldsV1.Encode(e) } @@ -74260,10 +74176,12 @@ func (s *IoK8sApimachineryPkgApisMetaV1ManagedFieldsEntry) Decode(d *jx.Decoder) } case "fieldsV1": if err := func() error { - s.FieldsV1.Reset() - if err := s.FieldsV1.Decode(d); err != nil { + s.FieldsV1 = nil + var elem IoK8sApimachineryPkgApisMetaV1FieldsV1 + if err := elem.Decode(d); err != nil { return err } + s.FieldsV1 = &elem return nil }(); err != nil { return errors.Wrap(err, "decode field \"fieldsV1\"") @@ -75283,43 +75201,29 @@ func (s *IoK8sApimachineryPkgApisMetaV1WatchEvent) UnmarshalJSON(data []byte) er } // Encode implements json.Marshaler. -func (s IoK8sApimachineryPkgRuntimeRawExtension) Encode(e *jx.Encoder) { +func (s *IoK8sApimachineryPkgRuntimeRawExtension) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } -// encodeFields implements json.Marshaler. -func (s IoK8sApimachineryPkgRuntimeRawExtension) encodeFields(e *jx.Encoder) { - for k, elem := range s { - e.FieldStart(k) - - if len(elem) != 0 { - e.Raw(elem) - } - } +// encodeFields encodes fields. +func (s *IoK8sApimachineryPkgRuntimeRawExtension) encodeFields(e *jx.Encoder) { } +var jsonFieldsNameOfIoK8sApimachineryPkgRuntimeRawExtension = [0]string{} + // Decode decodes IoK8sApimachineryPkgRuntimeRawExtension from json. func (s *IoK8sApimachineryPkgRuntimeRawExtension) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode IoK8sApimachineryPkgRuntimeRawExtension to nil") } - m := s.init() + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { - var elem jx.Raw - if err := func() error { - v, err := d.RawAppend(nil) - elem = jx.Raw(v) - if err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrapf(err, "decode field %q", k) + switch string(k) { + default: + return d.Skip() } - m[string(k)] = elem - return nil }); err != nil { return errors.Wrap(err, "decode IoK8sApimachineryPkgRuntimeRawExtension") } @@ -75328,7 +75232,7 @@ func (s *IoK8sApimachineryPkgRuntimeRawExtension) Decode(d *jx.Decoder) error { } // MarshalJSON implements stdjson.Marshaler. -func (s IoK8sApimachineryPkgRuntimeRawExtension) MarshalJSON() ([]byte, error) { +func (s *IoK8sApimachineryPkgRuntimeRawExtension) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil @@ -85258,40 +85162,6 @@ func (s *OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubre return s.Decode(d) } -// Encode encodes IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus as json. -func (o OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus) Encode(e *jx.Encoder) { - if !o.Set { - return - } - o.Value.Encode(e) -} - -// Decode decodes IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus from json. -func (o *OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus) Decode(d *jx.Decoder) error { - if o == nil { - return errors.New("invalid: unable to decode OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus to nil") - } - o.Set = true - o.Value = make(IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus) - if err := o.Value.Decode(d); err != nil { - return err - } - return nil -} - -// MarshalJSON implements stdjson.Marshaler. -func (s OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus) MarshalJSON() ([]byte, error) { - e := jx.Encoder{} - s.Encode(&e) - return e.Bytes(), nil -} - -// UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus) UnmarshalJSON(data []byte) error { - d := jx.DecodeBytes(data) - return s.Decode(d) -} - // Encode encodes IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresources as json. func (o OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresources) Encode(e *jx.Encoder) { if !o.Set { @@ -85391,40 +85261,6 @@ func (s *OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1ExternalDocumentati return s.Decode(d) } -// Encode encodes IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON as json. -func (o OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON) Encode(e *jx.Encoder) { - if !o.Set { - return - } - o.Value.Encode(e) -} - -// Decode decodes IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON from json. -func (o *OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON) Decode(d *jx.Decoder) error { - if o == nil { - return errors.New("invalid: unable to decode OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON to nil") - } - o.Set = true - o.Value = make(IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON) - if err := o.Value.Decode(d); err != nil { - return err - } - return nil -} - -// MarshalJSON implements stdjson.Marshaler. -func (s OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON) MarshalJSON() ([]byte, error) { - e := jx.Encoder{} - s.Encode(&e) - return e.Bytes(), nil -} - -// UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON) UnmarshalJSON(data []byte) error { - d := jx.DecodeBytes(data) - return s.Decode(d) -} - // Encode encodes IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps as json. func (o OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps) Encode(e *jx.Encoder) { if !o.Set { @@ -85526,74 +85362,6 @@ func (s *OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsDepe return s.Decode(d) } -// Encode encodes IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray as json. -func (o OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray) Encode(e *jx.Encoder) { - if !o.Set { - return - } - o.Value.Encode(e) -} - -// Decode decodes IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray from json. -func (o *OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray) Decode(d *jx.Decoder) error { - if o == nil { - return errors.New("invalid: unable to decode OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray to nil") - } - o.Set = true - o.Value = make(IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray) - if err := o.Value.Decode(d); err != nil { - return err - } - return nil -} - -// MarshalJSON implements stdjson.Marshaler. -func (s OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray) MarshalJSON() ([]byte, error) { - e := jx.Encoder{} - s.Encode(&e) - return e.Bytes(), nil -} - -// UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray) UnmarshalJSON(data []byte) error { - d := jx.DecodeBytes(data) - return s.Decode(d) -} - -// Encode encodes IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool as json. -func (o OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool) Encode(e *jx.Encoder) { - if !o.Set { - return - } - o.Value.Encode(e) -} - -// Decode decodes IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool from json. -func (o *OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool) Decode(d *jx.Decoder) error { - if o == nil { - return errors.New("invalid: unable to decode OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool to nil") - } - o.Set = true - o.Value = make(IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool) - if err := o.Value.Decode(d); err != nil { - return err - } - return nil -} - -// MarshalJSON implements stdjson.Marshaler. -func (s OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool) MarshalJSON() ([]byte, error) { - e := jx.Encoder{} - s.Encode(&e) - return e.Bytes(), nil -} - -// UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool) UnmarshalJSON(data []byte) error { - d := jx.DecodeBytes(data) - return s.Decode(d) -} - // Encode encodes IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsPatternProperties as json. func (o OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsPatternProperties) Encode(e *jx.Encoder) { if !o.Set { @@ -85794,40 +85562,6 @@ func (s *OptIoK8sApimachineryPkgAPIResourceQuantity) UnmarshalJSON(data []byte) return s.Decode(d) } -// Encode encodes IoK8sApimachineryPkgApisMetaV1FieldsV1 as json. -func (o OptIoK8sApimachineryPkgApisMetaV1FieldsV1) Encode(e *jx.Encoder) { - if !o.Set { - return - } - o.Value.Encode(e) -} - -// Decode decodes IoK8sApimachineryPkgApisMetaV1FieldsV1 from json. -func (o *OptIoK8sApimachineryPkgApisMetaV1FieldsV1) Decode(d *jx.Decoder) error { - if o == nil { - return errors.New("invalid: unable to decode OptIoK8sApimachineryPkgApisMetaV1FieldsV1 to nil") - } - o.Set = true - o.Value = make(IoK8sApimachineryPkgApisMetaV1FieldsV1) - if err := o.Value.Decode(d); err != nil { - return err - } - return nil -} - -// MarshalJSON implements stdjson.Marshaler. -func (s OptIoK8sApimachineryPkgApisMetaV1FieldsV1) MarshalJSON() ([]byte, error) { - e := jx.Encoder{} - s.Encode(&e) - return e.Bytes(), nil -} - -// UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptIoK8sApimachineryPkgApisMetaV1FieldsV1) UnmarshalJSON(data []byte) error { - d := jx.DecodeBytes(data) - return s.Decode(d) -} - // Encode encodes IoK8sApimachineryPkgApisMetaV1GroupVersionForDiscovery as json. func (o OptIoK8sApimachineryPkgApisMetaV1GroupVersionForDiscovery) Encode(e *jx.Encoder) { if !o.Set { @@ -86128,40 +85862,6 @@ func (s *OptIoK8sApimachineryPkgApisMetaV1Time) UnmarshalJSON(data []byte) error return s.Decode(d) } -// Encode encodes IoK8sApimachineryPkgRuntimeRawExtension as json. -func (o OptIoK8sApimachineryPkgRuntimeRawExtension) Encode(e *jx.Encoder) { - if !o.Set { - return - } - o.Value.Encode(e) -} - -// Decode decodes IoK8sApimachineryPkgRuntimeRawExtension from json. -func (o *OptIoK8sApimachineryPkgRuntimeRawExtension) Decode(d *jx.Decoder) error { - if o == nil { - return errors.New("invalid: unable to decode OptIoK8sApimachineryPkgRuntimeRawExtension to nil") - } - o.Set = true - o.Value = make(IoK8sApimachineryPkgRuntimeRawExtension) - if err := o.Value.Decode(d); err != nil { - return err - } - return nil -} - -// MarshalJSON implements stdjson.Marshaler. -func (s OptIoK8sApimachineryPkgRuntimeRawExtension) MarshalJSON() ([]byte, error) { - e := jx.Encoder{} - s.Encode(&e) - return e.Bytes(), nil -} - -// UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptIoK8sApimachineryPkgRuntimeRawExtension) UnmarshalJSON(data []byte) error { - d := jx.DecodeBytes(data) - return s.Decode(d) -} - // Encode encodes IoK8sApimachineryPkgUtilIntstrIntOrString as json. func (o OptIoK8sApimachineryPkgUtilIntstrIntOrString) Encode(e *jx.Encoder) { if !o.Set { diff --git a/examples/ex_k8s/oas_schemas_gen.go b/examples/ex_k8s/oas_schemas_gen.go index 2f3b3e8ed..4e01b8ec8 100644 --- a/examples/ex_k8s/oas_schemas_gen.go +++ b/examples/ex_k8s/oas_schemas_gen.go @@ -5,8 +5,6 @@ package api import ( "io" "time" - - "github.com/go-faster/jx" ) type BearerToken struct { @@ -3637,16 +3635,7 @@ func (*IoK8sAPIApiserverinternalV1alpha1StorageVersionList) listInternalApiserve // StorageVersionSpec is an empty spec. // Ref: #/components/schemas/io.k8s.api.apiserverinternal.v1alpha1.StorageVersionSpec -type IoK8sAPIApiserverinternalV1alpha1StorageVersionSpec map[string]jx.Raw - -func (s *IoK8sAPIApiserverinternalV1alpha1StorageVersionSpec) init() IoK8sAPIApiserverinternalV1alpha1StorageVersionSpec { - m := *s - if m == nil { - m = map[string]jx.Raw{} - *s = m - } - return m -} +type IoK8sAPIApiserverinternalV1alpha1StorageVersionSpec struct{} // API server instances report the versions they can decode and the version they encode objects to // when persisting objects in the backend. @@ -3708,8 +3697,8 @@ type IoK8sAPIAppsV1ControllerRevision struct { // APIVersion defines the versioned schema of this representation of an object. Servers should // convert recognized schemas to the latest internal value, and may reject unrecognized values. More // info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources. - ApiVersion OptString `json:"apiVersion"` - Data OptIoK8sApimachineryPkgRuntimeRawExtension `json:"data"` + ApiVersion OptString `json:"apiVersion"` + Data *IoK8sApimachineryPkgRuntimeRawExtension `json:"data"` // Kind is a string value representing the REST resource this object represents. Servers may infer // this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: // https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds. @@ -3725,7 +3714,7 @@ func (s *IoK8sAPIAppsV1ControllerRevision) GetApiVersion() OptString { } // GetData returns the value of Data. -func (s *IoK8sAPIAppsV1ControllerRevision) GetData() OptIoK8sApimachineryPkgRuntimeRawExtension { +func (s *IoK8sAPIAppsV1ControllerRevision) GetData() *IoK8sApimachineryPkgRuntimeRawExtension { return s.Data } @@ -3750,7 +3739,7 @@ func (s *IoK8sAPIAppsV1ControllerRevision) SetApiVersion(val OptString) { } // SetData sets the value of Data. -func (s *IoK8sAPIAppsV1ControllerRevision) SetData(val OptIoK8sApimachineryPkgRuntimeRawExtension) { +func (s *IoK8sAPIAppsV1ControllerRevision) SetData(val *IoK8sApimachineryPkgRuntimeRawExtension) { s.Data = val } @@ -31937,22 +31926,13 @@ func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresou // custom resource object, and ignore changes to anything except the status stanza * PUT/POST/PATCH // requests to the custom resource ignore changes to the status stanza. // Ref: #/components/schemas/io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.CustomResourceSubresourceStatus -type IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus map[string]jx.Raw - -func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus) init() IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus { - m := *s - if m == nil { - m = map[string]jx.Raw{} - *s = m - } - return m -} +type IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus struct{} // CustomResourceSubresources defines the status and scale subresources for CustomResources. // Ref: #/components/schemas/io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.CustomResourceSubresources type IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresources struct { - Scale OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceScale `json:"scale"` - Status OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus `json:"status"` + Scale OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceScale `json:"scale"` + Status *IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus `json:"status"` } // GetScale returns the value of Scale. @@ -31961,7 +31941,7 @@ func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresou } // GetStatus returns the value of Status. -func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresources) GetStatus() OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus { +func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresources) GetStatus() *IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus { return s.Status } @@ -31971,7 +31951,7 @@ func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresou } // SetStatus sets the value of Status. -func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresources) SetStatus(val OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus) { +func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresources) SetStatus(val *IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus) { s.Status = val } @@ -32021,32 +32001,23 @@ func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1ExternalDocumentation) // JSON represents any valid JSON value. These types are supported: bool, int64, float64, string, // []interface{}, map[string]interface{} and nil. // Ref: #/components/schemas/io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.JSON -type IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON map[string]jx.Raw - -func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON) init() IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON { - m := *s - if m == nil { - m = map[string]jx.Raw{} - *s = m - } - return m -} +type IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON struct{} // JSONSchemaProps is a JSON-Schema following Specification Draft 4 (http://json-schema.org/). // Ref: #/components/schemas/io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.JSONSchemaProps type IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps struct { Ref OptString `json:"$ref"` Schema OptString `json:"$schema"` - AdditionalItems OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool `json:"additionalItems"` - AdditionalProperties OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool `json:"additionalProperties"` + AdditionalItems *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool `json:"additionalItems"` + AdditionalProperties *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool `json:"additionalProperties"` AllOf []IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps `json:"allOf"` AnyOf []IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps `json:"anyOf"` - Default OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON `json:"default"` + Default *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON `json:"default"` Definitions OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsDefinitions `json:"definitions"` Dependencies OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsDependencies `json:"dependencies"` Description OptString `json:"description"` Enum []IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON `json:"enum"` - Example OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON `json:"example"` + Example *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON `json:"example"` ExclusiveMaximum OptBool `json:"exclusiveMaximum"` ExclusiveMinimum OptBool `json:"exclusiveMinimum"` ExternalDocs OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1ExternalDocumentation `json:"externalDocs"` @@ -32071,7 +32042,7 @@ type IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps struct { // ^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$ with any non digit characters mixed in - ssn: a U.S. social security number following the regex ^\d{3}[- ]?\d{2}[- ]?\d{4}$ - hexcolor: an hexadecimal color code like "#FFFFFF: following the regex ^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$ - rgbcolor: an RGB color code like rgb like "rgb(255,255,2559" - byte: base64 encoded binary data - password: any kind of string - date: a date string like "2006-01-02" as defined by full-date in RFC3339 - duration: a duration string like "22 ns" as parsed by Golang time.ParseDuration or compatible with Scala duration format - datetime: a date time string like "2014-12-15T19:30:20.000Z" as defined by date-time in RFC3339. Format OptString `json:"format"` ID OptString `json:"id"` - Items OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray `json:"items"` + Items *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray `json:"items"` MaxItems OptInt64 `json:"maxItems"` MaxLength OptInt64 `json:"maxLength"` MaxProperties OptInt64 `json:"maxProperties"` @@ -32159,12 +32130,12 @@ func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps) GetSc } // GetAdditionalItems returns the value of AdditionalItems. -func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps) GetAdditionalItems() OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool { +func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps) GetAdditionalItems() *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool { return s.AdditionalItems } // GetAdditionalProperties returns the value of AdditionalProperties. -func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps) GetAdditionalProperties() OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool { +func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps) GetAdditionalProperties() *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool { return s.AdditionalProperties } @@ -32179,7 +32150,7 @@ func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps) GetAn } // GetDefault returns the value of Default. -func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps) GetDefault() OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON { +func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps) GetDefault() *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON { return s.Default } @@ -32204,7 +32175,7 @@ func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps) GetEn } // GetExample returns the value of Example. -func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps) GetExample() OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON { +func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps) GetExample() *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON { return s.Example } @@ -32234,7 +32205,7 @@ func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps) GetID } // GetItems returns the value of Items. -func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps) GetItems() OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray { +func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps) GetItems() *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray { return s.Items } @@ -32374,12 +32345,12 @@ func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps) SetSc } // SetAdditionalItems sets the value of AdditionalItems. -func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps) SetAdditionalItems(val OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool) { +func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps) SetAdditionalItems(val *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool) { s.AdditionalItems = val } // SetAdditionalProperties sets the value of AdditionalProperties. -func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps) SetAdditionalProperties(val OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool) { +func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps) SetAdditionalProperties(val *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool) { s.AdditionalProperties = val } @@ -32394,7 +32365,7 @@ func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps) SetAn } // SetDefault sets the value of Default. -func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps) SetDefault(val OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON) { +func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps) SetDefault(val *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON) { s.Default = val } @@ -32419,7 +32390,7 @@ func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps) SetEn } // SetExample sets the value of Example. -func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps) SetExample(val OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON) { +func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps) SetExample(val *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON) { s.Example = val } @@ -32449,7 +32420,7 @@ func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps) SetID } // SetItems sets the value of Items. -func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps) SetItems(val OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray) { +func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps) SetItems(val *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray) { s.Items = val } @@ -32603,43 +32574,16 @@ func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsDepende // JSONSchemaPropsOrArray represents a value that can either be a JSONSchemaProps or an array of // JSONSchemaProps. Mainly here for serialization purposes. // Ref: #/components/schemas/io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.JSONSchemaPropsOrArray -type IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray map[string]jx.Raw - -func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray) init() IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray { - m := *s - if m == nil { - m = map[string]jx.Raw{} - *s = m - } - return m -} +type IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray struct{} // JSONSchemaPropsOrBool represents JSONSchemaProps or a boolean value. Defaults to true for the // boolean property. // Ref: #/components/schemas/io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.JSONSchemaPropsOrBool -type IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool map[string]jx.Raw - -func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool) init() IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool { - m := *s - if m == nil { - m = map[string]jx.Raw{} - *s = m - } - return m -} +type IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool struct{} // JSONSchemaPropsOrStringArray represents a JSONSchemaProps or a string array. // Ref: #/components/schemas/io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.JSONSchemaPropsOrStringArray -type IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrStringArray map[string]jx.Raw - -func (s *IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrStringArray) init() IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrStringArray { - m := *s - if m == nil { - m = map[string]jx.Raw{} - *s = m - } - return m -} +type IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrStringArray struct{} type IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsPatternProperties map[string]IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps @@ -33344,16 +33288,7 @@ func (s *IoK8sApimachineryPkgApisMetaV1Condition) SetType(val string) { // values If a key maps to an empty Fields value, the field that key represents is part of the set. // The exact format is defined in sigs.k8s.io/structured-merge-diff. // Ref: #/components/schemas/io.k8s.apimachinery.pkg.apis.meta.v1.FieldsV1 -type IoK8sApimachineryPkgApisMetaV1FieldsV1 map[string]jx.Raw - -func (s *IoK8sApimachineryPkgApisMetaV1FieldsV1) init() IoK8sApimachineryPkgApisMetaV1FieldsV1 { - m := *s - if m == nil { - m = map[string]jx.Raw{} - *s = m - } - return m -} +type IoK8sApimachineryPkgApisMetaV1FieldsV1 struct{} // GroupVersion contains the "group/version" and "version" string of a version. It is made a struct // to keep extensibility. @@ -33561,8 +33496,8 @@ type IoK8sApimachineryPkgApisMetaV1ManagedFieldsEntry struct { ApiVersion OptString `json:"apiVersion"` // FieldsType is the discriminator for the different fields format and version. There is currently // only one possible value: "FieldsV1". - FieldsType OptString `json:"fieldsType"` - FieldsV1 OptIoK8sApimachineryPkgApisMetaV1FieldsV1 `json:"fieldsV1"` + FieldsType OptString `json:"fieldsType"` + FieldsV1 *IoK8sApimachineryPkgApisMetaV1FieldsV1 `json:"fieldsV1"` // Manager is an identifier of the workflow managing these fields. Manager OptString `json:"manager"` // Operation is the type of operation which lead to this ManagedFieldsEntry being created. The only @@ -33588,7 +33523,7 @@ func (s *IoK8sApimachineryPkgApisMetaV1ManagedFieldsEntry) GetFieldsType() OptSt } // GetFieldsV1 returns the value of FieldsV1. -func (s *IoK8sApimachineryPkgApisMetaV1ManagedFieldsEntry) GetFieldsV1() OptIoK8sApimachineryPkgApisMetaV1FieldsV1 { +func (s *IoK8sApimachineryPkgApisMetaV1ManagedFieldsEntry) GetFieldsV1() *IoK8sApimachineryPkgApisMetaV1FieldsV1 { return s.FieldsV1 } @@ -33623,7 +33558,7 @@ func (s *IoK8sApimachineryPkgApisMetaV1ManagedFieldsEntry) SetFieldsType(val Opt } // SetFieldsV1 sets the value of FieldsV1. -func (s *IoK8sApimachineryPkgApisMetaV1ManagedFieldsEntry) SetFieldsV1(val OptIoK8sApimachineryPkgApisMetaV1FieldsV1) { +func (s *IoK8sApimachineryPkgApisMetaV1ManagedFieldsEntry) SetFieldsV1(val *IoK8sApimachineryPkgApisMetaV1FieldsV1) { s.FieldsV1 = val } @@ -34304,16 +34239,7 @@ func (*IoK8sApimachineryPkgApisMetaV1WatchEvent) watchStorageV1beta1NamespacedCS // the correct object type, and storing it in the Object. (TODO: In the case where the object is of // an unknown type, a runtime.Unknown object will be created and stored.). // Ref: #/components/schemas/io.k8s.apimachinery.pkg.runtime.RawExtension -type IoK8sApimachineryPkgRuntimeRawExtension map[string]jx.Raw - -func (s *IoK8sApimachineryPkgRuntimeRawExtension) init() IoK8sApimachineryPkgRuntimeRawExtension { - m := *s - if m == nil { - m = map[string]jx.Raw{} - *s = m - } - return m -} +type IoK8sApimachineryPkgRuntimeRawExtension struct{} type IoK8sApimachineryPkgUtilIntstrIntOrString string @@ -47615,54 +47541,6 @@ func (o OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubres return d } -// NewOptIoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus returns new OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus with value set to v. -func NewOptIoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus(v IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus) OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus { - return OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus{ - Value: v, - Set: true, - } -} - -// OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus is optional IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus. -type OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus struct { - Value IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus - Set bool -} - -// IsSet returns true if OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus was set. -func (o OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus) IsSet() bool { - return o.Set -} - -// Reset unsets value. -func (o *OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus) Reset() { - var v IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus - o.Value = v - o.Set = false -} - -// SetTo sets value to v. -func (o *OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus) SetTo(v IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus) { - o.Set = true - o.Value = v -} - -// Get returns value and boolean that denotes whether value was set. -func (o OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus) Get() (v IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus, ok bool) { - if !o.Set { - return v, false - } - return o.Value, true -} - -// Or returns value if set, or given parameter if does not. -func (o OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus) Or(d IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus) IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus { - if v, ok := o.Get(); ok { - return v - } - return d -} - // NewOptIoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresources returns new OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresources with value set to v. func NewOptIoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresources(v IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresources) OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresources { return OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresources{ @@ -47807,52 +47685,6 @@ func (o OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1ExternalDocumentatio return d } -// NewOptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON returns new OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON with value set to v. -func NewOptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON(v IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON) OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON { - return OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON{ - Value: v, - Set: true, - } -} - -// OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON is optional IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON. -type OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON struct { - Value IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON - Set bool -} - -// IsSet returns true if OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON was set. -func (o OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON) IsSet() bool { return o.Set } - -// Reset unsets value. -func (o *OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON) Reset() { - var v IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON - o.Value = v - o.Set = false -} - -// SetTo sets value to v. -func (o *OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON) SetTo(v IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON) { - o.Set = true - o.Value = v -} - -// Get returns value and boolean that denotes whether value was set. -func (o OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON) Get() (v IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON, ok bool) { - if !o.Set { - return v, false - } - return o.Value, true -} - -// Or returns value if set, or given parameter if does not. -func (o OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON) Or(d IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON) IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON { - if v, ok := o.Get(); ok { - return v - } - return d -} - // NewOptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps returns new OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps with value set to v. func NewOptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps(v IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps) OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps { return OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps{ @@ -47997,102 +47829,6 @@ func (o OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsDepen return d } -// NewOptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray returns new OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray with value set to v. -func NewOptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray(v IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray) OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray { - return OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray{ - Value: v, - Set: true, - } -} - -// OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray is optional IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray. -type OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray struct { - Value IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray - Set bool -} - -// IsSet returns true if OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray was set. -func (o OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray) IsSet() bool { - return o.Set -} - -// Reset unsets value. -func (o *OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray) Reset() { - var v IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray - o.Value = v - o.Set = false -} - -// SetTo sets value to v. -func (o *OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray) SetTo(v IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray) { - o.Set = true - o.Value = v -} - -// Get returns value and boolean that denotes whether value was set. -func (o OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray) Get() (v IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray, ok bool) { - if !o.Set { - return v, false - } - return o.Value, true -} - -// Or returns value if set, or given parameter if does not. -func (o OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray) Or(d IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray) IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray { - if v, ok := o.Get(); ok { - return v - } - return d -} - -// NewOptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool returns new OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool with value set to v. -func NewOptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool(v IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool) OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool { - return OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool{ - Value: v, - Set: true, - } -} - -// OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool is optional IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool. -type OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool struct { - Value IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool - Set bool -} - -// IsSet returns true if OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool was set. -func (o OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool) IsSet() bool { - return o.Set -} - -// Reset unsets value. -func (o *OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool) Reset() { - var v IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool - o.Value = v - o.Set = false -} - -// SetTo sets value to v. -func (o *OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool) SetTo(v IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool) { - o.Set = true - o.Value = v -} - -// Get returns value and boolean that denotes whether value was set. -func (o OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool) Get() (v IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool, ok bool) { - if !o.Set { - return v, false - } - return o.Value, true -} - -// Or returns value if set, or given parameter if does not. -func (o OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool) Or(d IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool) IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool { - if v, ok := o.Get(); ok { - return v - } - return d -} - // NewOptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsPatternProperties returns new OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsPatternProperties with value set to v. func NewOptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsPatternProperties(v IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsPatternProperties) OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsPatternProperties { return OptIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsPatternProperties{ @@ -48379,52 +48115,6 @@ func (o OptIoK8sApimachineryPkgAPIResourceQuantity) Or(d IoK8sApimachineryPkgAPI return d } -// NewOptIoK8sApimachineryPkgApisMetaV1FieldsV1 returns new OptIoK8sApimachineryPkgApisMetaV1FieldsV1 with value set to v. -func NewOptIoK8sApimachineryPkgApisMetaV1FieldsV1(v IoK8sApimachineryPkgApisMetaV1FieldsV1) OptIoK8sApimachineryPkgApisMetaV1FieldsV1 { - return OptIoK8sApimachineryPkgApisMetaV1FieldsV1{ - Value: v, - Set: true, - } -} - -// OptIoK8sApimachineryPkgApisMetaV1FieldsV1 is optional IoK8sApimachineryPkgApisMetaV1FieldsV1. -type OptIoK8sApimachineryPkgApisMetaV1FieldsV1 struct { - Value IoK8sApimachineryPkgApisMetaV1FieldsV1 - Set bool -} - -// IsSet returns true if OptIoK8sApimachineryPkgApisMetaV1FieldsV1 was set. -func (o OptIoK8sApimachineryPkgApisMetaV1FieldsV1) IsSet() bool { return o.Set } - -// Reset unsets value. -func (o *OptIoK8sApimachineryPkgApisMetaV1FieldsV1) Reset() { - var v IoK8sApimachineryPkgApisMetaV1FieldsV1 - o.Value = v - o.Set = false -} - -// SetTo sets value to v. -func (o *OptIoK8sApimachineryPkgApisMetaV1FieldsV1) SetTo(v IoK8sApimachineryPkgApisMetaV1FieldsV1) { - o.Set = true - o.Value = v -} - -// Get returns value and boolean that denotes whether value was set. -func (o OptIoK8sApimachineryPkgApisMetaV1FieldsV1) Get() (v IoK8sApimachineryPkgApisMetaV1FieldsV1, ok bool) { - if !o.Set { - return v, false - } - return o.Value, true -} - -// Or returns value if set, or given parameter if does not. -func (o OptIoK8sApimachineryPkgApisMetaV1FieldsV1) Or(d IoK8sApimachineryPkgApisMetaV1FieldsV1) IoK8sApimachineryPkgApisMetaV1FieldsV1 { - if v, ok := o.Get(); ok { - return v - } - return d -} - // NewOptIoK8sApimachineryPkgApisMetaV1GroupVersionForDiscovery returns new OptIoK8sApimachineryPkgApisMetaV1GroupVersionForDiscovery with value set to v. func NewOptIoK8sApimachineryPkgApisMetaV1GroupVersionForDiscovery(v IoK8sApimachineryPkgApisMetaV1GroupVersionForDiscovery) OptIoK8sApimachineryPkgApisMetaV1GroupVersionForDiscovery { return OptIoK8sApimachineryPkgApisMetaV1GroupVersionForDiscovery{ @@ -48839,52 +48529,6 @@ func (o OptIoK8sApimachineryPkgApisMetaV1Time) Or(d IoK8sApimachineryPkgApisMeta return d } -// NewOptIoK8sApimachineryPkgRuntimeRawExtension returns new OptIoK8sApimachineryPkgRuntimeRawExtension with value set to v. -func NewOptIoK8sApimachineryPkgRuntimeRawExtension(v IoK8sApimachineryPkgRuntimeRawExtension) OptIoK8sApimachineryPkgRuntimeRawExtension { - return OptIoK8sApimachineryPkgRuntimeRawExtension{ - Value: v, - Set: true, - } -} - -// OptIoK8sApimachineryPkgRuntimeRawExtension is optional IoK8sApimachineryPkgRuntimeRawExtension. -type OptIoK8sApimachineryPkgRuntimeRawExtension struct { - Value IoK8sApimachineryPkgRuntimeRawExtension - Set bool -} - -// IsSet returns true if OptIoK8sApimachineryPkgRuntimeRawExtension was set. -func (o OptIoK8sApimachineryPkgRuntimeRawExtension) IsSet() bool { return o.Set } - -// Reset unsets value. -func (o *OptIoK8sApimachineryPkgRuntimeRawExtension) Reset() { - var v IoK8sApimachineryPkgRuntimeRawExtension - o.Value = v - o.Set = false -} - -// SetTo sets value to v. -func (o *OptIoK8sApimachineryPkgRuntimeRawExtension) SetTo(v IoK8sApimachineryPkgRuntimeRawExtension) { - o.Set = true - o.Value = v -} - -// Get returns value and boolean that denotes whether value was set. -func (o OptIoK8sApimachineryPkgRuntimeRawExtension) Get() (v IoK8sApimachineryPkgRuntimeRawExtension, ok bool) { - if !o.Set { - return v, false - } - return o.Value, true -} - -// Or returns value if set, or given parameter if does not. -func (o OptIoK8sApimachineryPkgRuntimeRawExtension) Or(d IoK8sApimachineryPkgRuntimeRawExtension) IoK8sApimachineryPkgRuntimeRawExtension { - if v, ok := o.Get(); ok { - return v - } - return d -} - // NewOptIoK8sApimachineryPkgUtilIntstrIntOrString returns new OptIoK8sApimachineryPkgUtilIntstrIntOrString with value set to v. func NewOptIoK8sApimachineryPkgUtilIntstrIntOrString(v IoK8sApimachineryPkgUtilIntstrIntOrString) OptIoK8sApimachineryPkgUtilIntstrIntOrString { return OptIoK8sApimachineryPkgUtilIntstrIntOrString{ diff --git a/examples/ex_k8s/oas_test_examples_gen_test.go b/examples/ex_k8s/oas_test_examples_gen_test.go index 0797a1cca..64fa413b8 100644 --- a/examples/ex_k8s/oas_test_examples_gen_test.go +++ b/examples/ex_k8s/oas_test_examples_gen_test.go @@ -181,7 +181,6 @@ func TestIoK8sAPIApiserverinternalV1alpha1StorageVersionList_EncodeDecode(t *tes } func TestIoK8sAPIApiserverinternalV1alpha1StorageVersionSpec_EncodeDecode(t *testing.T) { var typ IoK8sAPIApiserverinternalV1alpha1StorageVersionSpec - typ = make(IoK8sAPIApiserverinternalV1alpha1StorageVersionSpec) typ.SetFake() e := jx.Encoder{} @@ -190,7 +189,6 @@ func TestIoK8sAPIApiserverinternalV1alpha1StorageVersionSpec_EncodeDecode(t *tes require.True(t, std.Valid(data), "Encoded: %s", data) var typ2 IoK8sAPIApiserverinternalV1alpha1StorageVersionSpec - typ2 = make(IoK8sAPIApiserverinternalV1alpha1StorageVersionSpec) require.NoError(t, typ2.Decode(jx.DecodeBytes(data))) } func TestIoK8sAPIApiserverinternalV1alpha1StorageVersionStatus_EncodeDecode(t *testing.T) { @@ -6225,7 +6223,6 @@ func TestIoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresou } func TestIoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus_EncodeDecode(t *testing.T) { var typ IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus - typ = make(IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus) typ.SetFake() e := jx.Encoder{} @@ -6234,7 +6231,6 @@ func TestIoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresou require.True(t, std.Valid(data), "Encoded: %s", data) var typ2 IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus - typ2 = make(IoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresourceStatus) require.NoError(t, typ2.Decode(jx.DecodeBytes(data))) } func TestIoK8sApiextensionsApiserverPkgApisApiextensionsV1CustomResourceSubresources_EncodeDecode(t *testing.T) { @@ -6275,7 +6271,6 @@ func TestIoK8sApiextensionsApiserverPkgApisApiextensionsV1ExternalDocumentation_ } func TestIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON_EncodeDecode(t *testing.T) { var typ IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON - typ = make(IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON) typ.SetFake() e := jx.Encoder{} @@ -6284,7 +6279,6 @@ func TestIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON_EncodeDecode(t *t require.True(t, std.Valid(data), "Encoded: %s", data) var typ2 IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON - typ2 = make(IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSON) require.NoError(t, typ2.Decode(jx.DecodeBytes(data))) } func TestIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaProps_EncodeDecode(t *testing.T) { @@ -6329,7 +6323,6 @@ func TestIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsDepende } func TestIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray_EncodeDecode(t *testing.T) { var typ IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray - typ = make(IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray) typ.SetFake() e := jx.Encoder{} @@ -6338,12 +6331,10 @@ func TestIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray require.True(t, std.Valid(data), "Encoded: %s", data) var typ2 IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray - typ2 = make(IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrArray) require.NoError(t, typ2.Decode(jx.DecodeBytes(data))) } func TestIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool_EncodeDecode(t *testing.T) { var typ IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool - typ = make(IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool) typ.SetFake() e := jx.Encoder{} @@ -6352,12 +6343,10 @@ func TestIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool_ require.True(t, std.Valid(data), "Encoded: %s", data) var typ2 IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool - typ2 = make(IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrBool) require.NoError(t, typ2.Decode(jx.DecodeBytes(data))) } func TestIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrStringArray_EncodeDecode(t *testing.T) { var typ IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrStringArray - typ = make(IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrStringArray) typ.SetFake() e := jx.Encoder{} @@ -6366,7 +6355,6 @@ func TestIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrStrin require.True(t, std.Valid(data), "Encoded: %s", data) var typ2 IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrStringArray - typ2 = make(IoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsOrStringArray) require.NoError(t, typ2.Decode(jx.DecodeBytes(data))) } func TestIoK8sApiextensionsApiserverPkgApisApiextensionsV1JSONSchemaPropsPatternProperties_EncodeDecode(t *testing.T) { @@ -6519,7 +6507,6 @@ func TestIoK8sApimachineryPkgApisMetaV1Condition_EncodeDecode(t *testing.T) { } func TestIoK8sApimachineryPkgApisMetaV1FieldsV1_EncodeDecode(t *testing.T) { var typ IoK8sApimachineryPkgApisMetaV1FieldsV1 - typ = make(IoK8sApimachineryPkgApisMetaV1FieldsV1) typ.SetFake() e := jx.Encoder{} @@ -6528,7 +6515,6 @@ func TestIoK8sApimachineryPkgApisMetaV1FieldsV1_EncodeDecode(t *testing.T) { require.True(t, std.Valid(data), "Encoded: %s", data) var typ2 IoK8sApimachineryPkgApisMetaV1FieldsV1 - typ2 = make(IoK8sApimachineryPkgApisMetaV1FieldsV1) require.NoError(t, typ2.Decode(jx.DecodeBytes(data))) } func TestIoK8sApimachineryPkgApisMetaV1GroupVersionForDiscovery_EncodeDecode(t *testing.T) { @@ -6707,7 +6693,6 @@ func TestIoK8sApimachineryPkgApisMetaV1WatchEvent_EncodeDecode(t *testing.T) { } func TestIoK8sApimachineryPkgRuntimeRawExtension_EncodeDecode(t *testing.T) { var typ IoK8sApimachineryPkgRuntimeRawExtension - typ = make(IoK8sApimachineryPkgRuntimeRawExtension) typ.SetFake() e := jx.Encoder{} @@ -6716,7 +6701,6 @@ func TestIoK8sApimachineryPkgRuntimeRawExtension_EncodeDecode(t *testing.T) { require.True(t, std.Valid(data), "Encoded: %s", data) var typ2 IoK8sApimachineryPkgRuntimeRawExtension - typ2 = make(IoK8sApimachineryPkgRuntimeRawExtension) require.NoError(t, typ2.Decode(jx.DecodeBytes(data))) } func TestIoK8sApimachineryPkgUtilIntstrIntOrString_EncodeDecode(t *testing.T) { diff --git a/examples/ex_openai/oas_json_gen.go b/examples/ex_openai/oas_json_gen.go index 68239367f..86457d2a2 100644 --- a/examples/ex_openai/oas_json_gen.go +++ b/examples/ex_openai/oas_json_gen.go @@ -748,43 +748,29 @@ func (s *CreateAnswerRequest) UnmarshalJSON(data []byte) error { } // Encode implements json.Marshaler. -func (s CreateAnswerRequestLogitBias) Encode(e *jx.Encoder) { +func (s *CreateAnswerRequestLogitBias) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } -// encodeFields implements json.Marshaler. -func (s CreateAnswerRequestLogitBias) encodeFields(e *jx.Encoder) { - for k, elem := range s { - e.FieldStart(k) - - if len(elem) != 0 { - e.Raw(elem) - } - } +// encodeFields encodes fields. +func (s *CreateAnswerRequestLogitBias) encodeFields(e *jx.Encoder) { } +var jsonFieldsNameOfCreateAnswerRequestLogitBias = [0]string{} + // Decode decodes CreateAnswerRequestLogitBias from json. func (s *CreateAnswerRequestLogitBias) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode CreateAnswerRequestLogitBias to nil") } - m := s.init() + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { - var elem jx.Raw - if err := func() error { - v, err := d.RawAppend(nil) - elem = jx.Raw(v) - if err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrapf(err, "decode field %q", k) + switch string(k) { + default: + return d.Skip() } - m[string(k)] = elem - return nil }); err != nil { return errors.Wrap(err, "decode CreateAnswerRequestLogitBias") } @@ -793,7 +779,7 @@ func (s *CreateAnswerRequestLogitBias) Decode(d *jx.Decoder) error { } // MarshalJSON implements stdjson.Marshaler. -func (s CreateAnswerRequestLogitBias) MarshalJSON() ([]byte, error) { +func (s *CreateAnswerRequestLogitBias) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil @@ -1415,43 +1401,29 @@ func (s *CreateChatCompletionRequest) UnmarshalJSON(data []byte) error { } // Encode implements json.Marshaler. -func (s CreateChatCompletionRequestLogitBias) Encode(e *jx.Encoder) { +func (s *CreateChatCompletionRequestLogitBias) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } -// encodeFields implements json.Marshaler. -func (s CreateChatCompletionRequestLogitBias) encodeFields(e *jx.Encoder) { - for k, elem := range s { - e.FieldStart(k) - - if len(elem) != 0 { - e.Raw(elem) - } - } +// encodeFields encodes fields. +func (s *CreateChatCompletionRequestLogitBias) encodeFields(e *jx.Encoder) { } +var jsonFieldsNameOfCreateChatCompletionRequestLogitBias = [0]string{} + // Decode decodes CreateChatCompletionRequestLogitBias from json. func (s *CreateChatCompletionRequestLogitBias) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode CreateChatCompletionRequestLogitBias to nil") } - m := s.init() + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { - var elem jx.Raw - if err := func() error { - v, err := d.RawAppend(nil) - elem = jx.Raw(v) - if err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrapf(err, "decode field %q", k) + switch string(k) { + default: + return d.Skip() } - m[string(k)] = elem - return nil }); err != nil { return errors.Wrap(err, "decode CreateChatCompletionRequestLogitBias") } @@ -1460,7 +1432,7 @@ func (s *CreateChatCompletionRequestLogitBias) Decode(d *jx.Decoder) error { } // MarshalJSON implements stdjson.Marshaler. -func (s CreateChatCompletionRequestLogitBias) MarshalJSON() ([]byte, error) { +func (s *CreateChatCompletionRequestLogitBias) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil @@ -2272,43 +2244,29 @@ func (s *CreateClassificationRequest) UnmarshalJSON(data []byte) error { } // Encode implements json.Marshaler. -func (s CreateClassificationRequestLogitBias) Encode(e *jx.Encoder) { +func (s *CreateClassificationRequestLogitBias) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } -// encodeFields implements json.Marshaler. -func (s CreateClassificationRequestLogitBias) encodeFields(e *jx.Encoder) { - for k, elem := range s { - e.FieldStart(k) - - if len(elem) != 0 { - e.Raw(elem) - } - } +// encodeFields encodes fields. +func (s *CreateClassificationRequestLogitBias) encodeFields(e *jx.Encoder) { } +var jsonFieldsNameOfCreateClassificationRequestLogitBias = [0]string{} + // Decode decodes CreateClassificationRequestLogitBias from json. func (s *CreateClassificationRequestLogitBias) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode CreateClassificationRequestLogitBias to nil") } - m := s.init() + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { - var elem jx.Raw - if err := func() error { - v, err := d.RawAppend(nil) - elem = jx.Raw(v) - if err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrapf(err, "decode field %q", k) + switch string(k) { + default: + return d.Skip() } - m[string(k)] = elem - return nil }); err != nil { return errors.Wrap(err, "decode CreateClassificationRequestLogitBias") } @@ -2317,7 +2275,7 @@ func (s *CreateClassificationRequestLogitBias) Decode(d *jx.Decoder) error { } // MarshalJSON implements stdjson.Marshaler. -func (s CreateClassificationRequestLogitBias) MarshalJSON() ([]byte, error) { +func (s *CreateClassificationRequestLogitBias) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil @@ -2939,43 +2897,29 @@ func (s *CreateCompletionRequest) UnmarshalJSON(data []byte) error { } // Encode implements json.Marshaler. -func (s CreateCompletionRequestLogitBias) Encode(e *jx.Encoder) { +func (s *CreateCompletionRequestLogitBias) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } -// encodeFields implements json.Marshaler. -func (s CreateCompletionRequestLogitBias) encodeFields(e *jx.Encoder) { - for k, elem := range s { - e.FieldStart(k) - - if len(elem) != 0 { - e.Raw(elem) - } - } +// encodeFields encodes fields. +func (s *CreateCompletionRequestLogitBias) encodeFields(e *jx.Encoder) { } +var jsonFieldsNameOfCreateCompletionRequestLogitBias = [0]string{} + // Decode decodes CreateCompletionRequestLogitBias from json. func (s *CreateCompletionRequestLogitBias) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode CreateCompletionRequestLogitBias to nil") } - m := s.init() + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { - var elem jx.Raw - if err := func() error { - v, err := d.RawAppend(nil) - elem = jx.Raw(v) - if err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrapf(err, "decode field %q", k) + switch string(k) { + default: + return d.Skip() } - m[string(k)] = elem - return nil }); err != nil { return errors.Wrap(err, "decode CreateCompletionRequestLogitBias") } @@ -2984,7 +2928,7 @@ func (s *CreateCompletionRequestLogitBias) Decode(d *jx.Decoder) error { } // MarshalJSON implements stdjson.Marshaler. -func (s CreateCompletionRequestLogitBias) MarshalJSON() ([]byte, error) { +func (s *CreateCompletionRequestLogitBias) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil @@ -3598,43 +3542,29 @@ func (s *CreateCompletionResponseChoicesItemLogprobs) UnmarshalJSON(data []byte) } // Encode implements json.Marshaler. -func (s CreateCompletionResponseChoicesItemLogprobsTopLogprobsItem) Encode(e *jx.Encoder) { +func (s *CreateCompletionResponseChoicesItemLogprobsTopLogprobsItem) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } -// encodeFields implements json.Marshaler. -func (s CreateCompletionResponseChoicesItemLogprobsTopLogprobsItem) encodeFields(e *jx.Encoder) { - for k, elem := range s { - e.FieldStart(k) - - if len(elem) != 0 { - e.Raw(elem) - } - } +// encodeFields encodes fields. +func (s *CreateCompletionResponseChoicesItemLogprobsTopLogprobsItem) encodeFields(e *jx.Encoder) { } +var jsonFieldsNameOfCreateCompletionResponseChoicesItemLogprobsTopLogprobsItem = [0]string{} + // Decode decodes CreateCompletionResponseChoicesItemLogprobsTopLogprobsItem from json. func (s *CreateCompletionResponseChoicesItemLogprobsTopLogprobsItem) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode CreateCompletionResponseChoicesItemLogprobsTopLogprobsItem to nil") } - m := s.init() + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { - var elem jx.Raw - if err := func() error { - v, err := d.RawAppend(nil) - elem = jx.Raw(v) - if err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrapf(err, "decode field %q", k) + switch string(k) { + default: + return d.Skip() } - m[string(k)] = elem - return nil }); err != nil { return errors.Wrap(err, "decode CreateCompletionResponseChoicesItemLogprobsTopLogprobsItem") } @@ -3643,7 +3573,7 @@ func (s *CreateCompletionResponseChoicesItemLogprobsTopLogprobsItem) Decode(d *j } // MarshalJSON implements stdjson.Marshaler. -func (s CreateCompletionResponseChoicesItemLogprobsTopLogprobsItem) MarshalJSON() ([]byte, error) { +func (s *CreateCompletionResponseChoicesItemLogprobsTopLogprobsItem) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil @@ -4401,43 +4331,29 @@ func (s *CreateEditResponseChoicesItemLogprobs) UnmarshalJSON(data []byte) error } // Encode implements json.Marshaler. -func (s CreateEditResponseChoicesItemLogprobsTopLogprobsItem) Encode(e *jx.Encoder) { +func (s *CreateEditResponseChoicesItemLogprobsTopLogprobsItem) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } -// encodeFields implements json.Marshaler. -func (s CreateEditResponseChoicesItemLogprobsTopLogprobsItem) encodeFields(e *jx.Encoder) { - for k, elem := range s { - e.FieldStart(k) - - if len(elem) != 0 { - e.Raw(elem) - } - } +// encodeFields encodes fields. +func (s *CreateEditResponseChoicesItemLogprobsTopLogprobsItem) encodeFields(e *jx.Encoder) { } +var jsonFieldsNameOfCreateEditResponseChoicesItemLogprobsTopLogprobsItem = [0]string{} + // Decode decodes CreateEditResponseChoicesItemLogprobsTopLogprobsItem from json. func (s *CreateEditResponseChoicesItemLogprobsTopLogprobsItem) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode CreateEditResponseChoicesItemLogprobsTopLogprobsItem to nil") } - m := s.init() + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { - var elem jx.Raw - if err := func() error { - v, err := d.RawAppend(nil) - elem = jx.Raw(v) - if err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrapf(err, "decode field %q", k) + switch string(k) { + default: + return d.Skip() } - m[string(k)] = elem - return nil }); err != nil { return errors.Wrap(err, "decode CreateEditResponseChoicesItemLogprobsTopLogprobsItem") } @@ -4446,7 +4362,7 @@ func (s *CreateEditResponseChoicesItemLogprobsTopLogprobsItem) Decode(d *jx.Deco } // MarshalJSON implements stdjson.Marshaler. -func (s CreateEditResponseChoicesItemLogprobsTopLogprobsItem) MarshalJSON() ([]byte, error) { +func (s *CreateEditResponseChoicesItemLogprobsTopLogprobsItem) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil @@ -8295,18 +8211,18 @@ func (s *OptChatCompletionResponseMessage) UnmarshalJSON(data []byte) error { return s.Decode(d) } -// Encode encodes CreateChatCompletionResponseUsage as json. -func (o OptCreateChatCompletionResponseUsage) Encode(e *jx.Encoder) { +// Encode encodes *CreateAnswerRequestLogitBias as json. +func (o OptCreateAnswerRequestLogitBias) Encode(e *jx.Encoder) { if !o.Set { return } o.Value.Encode(e) } -// Decode decodes CreateChatCompletionResponseUsage from json. -func (o *OptCreateChatCompletionResponseUsage) Decode(d *jx.Decoder) error { +// Decode decodes *CreateAnswerRequestLogitBias from json. +func (o *OptCreateAnswerRequestLogitBias) Decode(d *jx.Decoder) error { if o == nil { - return errors.New("invalid: unable to decode OptCreateChatCompletionResponseUsage to nil") + return errors.New("invalid: unable to decode OptCreateAnswerRequestLogitBias to nil") } o.Set = true if err := o.Value.Decode(d); err != nil { @@ -8316,30 +8232,30 @@ func (o *OptCreateChatCompletionResponseUsage) Decode(d *jx.Decoder) error { } // MarshalJSON implements stdjson.Marshaler. -func (s OptCreateChatCompletionResponseUsage) MarshalJSON() ([]byte, error) { +func (s OptCreateAnswerRequestLogitBias) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptCreateChatCompletionResponseUsage) UnmarshalJSON(data []byte) error { +func (s *OptCreateAnswerRequestLogitBias) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } -// Encode encodes CreateCompletionResponseUsage as json. -func (o OptCreateCompletionResponseUsage) Encode(e *jx.Encoder) { +// Encode encodes *CreateChatCompletionRequestLogitBias as json. +func (o OptCreateChatCompletionRequestLogitBias) Encode(e *jx.Encoder) { if !o.Set { return } o.Value.Encode(e) } -// Decode decodes CreateCompletionResponseUsage from json. -func (o *OptCreateCompletionResponseUsage) Decode(d *jx.Decoder) error { +// Decode decodes *CreateChatCompletionRequestLogitBias from json. +func (o *OptCreateChatCompletionRequestLogitBias) Decode(d *jx.Decoder) error { if o == nil { - return errors.New("invalid: unable to decode OptCreateCompletionResponseUsage to nil") + return errors.New("invalid: unable to decode OptCreateChatCompletionRequestLogitBias to nil") } o.Set = true if err := o.Value.Decode(d); err != nil { @@ -8349,305 +8265,222 @@ func (o *OptCreateCompletionResponseUsage) Decode(d *jx.Decoder) error { } // MarshalJSON implements stdjson.Marshaler. -func (s OptCreateCompletionResponseUsage) MarshalJSON() ([]byte, error) { +func (s OptCreateChatCompletionRequestLogitBias) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptCreateCompletionResponseUsage) UnmarshalJSON(data []byte) error { +func (s *OptCreateChatCompletionRequestLogitBias) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } -// Encode encodes float64 as json. -func (o OptFloat64) Encode(e *jx.Encoder) { +// Encode encodes CreateChatCompletionResponseUsage as json. +func (o OptCreateChatCompletionResponseUsage) Encode(e *jx.Encoder) { if !o.Set { return } - e.Float64(float64(o.Value)) + o.Value.Encode(e) } -// Decode decodes float64 from json. -func (o *OptFloat64) Decode(d *jx.Decoder) error { +// Decode decodes CreateChatCompletionResponseUsage from json. +func (o *OptCreateChatCompletionResponseUsage) Decode(d *jx.Decoder) error { if o == nil { - return errors.New("invalid: unable to decode OptFloat64 to nil") + return errors.New("invalid: unable to decode OptCreateChatCompletionResponseUsage to nil") } o.Set = true - v, err := d.Float64() - if err != nil { + if err := o.Value.Decode(d); err != nil { return err } - o.Value = float64(v) return nil } // MarshalJSON implements stdjson.Marshaler. -func (s OptFloat64) MarshalJSON() ([]byte, error) { +func (s OptCreateChatCompletionResponseUsage) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptFloat64) UnmarshalJSON(data []byte) error { +func (s *OptCreateChatCompletionResponseUsage) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } -// Encode encodes int as json. -func (o OptInt) Encode(e *jx.Encoder) { +// Encode encodes *CreateClassificationRequestLogitBias as json. +func (o OptCreateClassificationRequestLogitBias) Encode(e *jx.Encoder) { if !o.Set { return } - e.Int(int(o.Value)) + o.Value.Encode(e) } -// Decode decodes int from json. -func (o *OptInt) Decode(d *jx.Decoder) error { +// Decode decodes *CreateClassificationRequestLogitBias from json. +func (o *OptCreateClassificationRequestLogitBias) Decode(d *jx.Decoder) error { if o == nil { - return errors.New("invalid: unable to decode OptInt to nil") + return errors.New("invalid: unable to decode OptCreateClassificationRequestLogitBias to nil") } o.Set = true - v, err := d.Int() - if err != nil { + if err := o.Value.Decode(d); err != nil { return err } - o.Value = int(v) return nil } // MarshalJSON implements stdjson.Marshaler. -func (s OptInt) MarshalJSON() ([]byte, error) { +func (s OptCreateClassificationRequestLogitBias) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptInt) UnmarshalJSON(data []byte) error { +func (s *OptCreateClassificationRequestLogitBias) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } -// Encode encodes []jx.Raw as json. -func (o OptNilAnyArray) Encode(e *jx.Encoder) { +// Encode encodes *CreateCompletionRequestLogitBias as json. +func (o OptCreateCompletionRequestLogitBias) Encode(e *jx.Encoder) { if !o.Set { return } - if o.Null { - e.Null() - return - } - e.ArrStart() - for _, elem := range o.Value { - if len(elem) != 0 { - e.Raw(elem) - } - } - e.ArrEnd() + o.Value.Encode(e) } -// Decode decodes []jx.Raw from json. -func (o *OptNilAnyArray) Decode(d *jx.Decoder) error { +// Decode decodes *CreateCompletionRequestLogitBias from json. +func (o *OptCreateCompletionRequestLogitBias) Decode(d *jx.Decoder) error { if o == nil { - return errors.New("invalid: unable to decode OptNilAnyArray to nil") - } - if d.Next() == jx.Null { - if err := d.Null(); err != nil { - return err - } - - var v []jx.Raw - o.Value = v - o.Set = true - o.Null = true - return nil + return errors.New("invalid: unable to decode OptCreateCompletionRequestLogitBias to nil") } o.Set = true - o.Null = false - o.Value = make([]jx.Raw, 0) - if err := d.Arr(func(d *jx.Decoder) error { - var elem jx.Raw - v, err := d.RawAppend(nil) - elem = jx.Raw(v) - if err != nil { - return err - } - o.Value = append(o.Value, elem) - return nil - }); err != nil { + if err := o.Value.Decode(d); err != nil { return err } return nil } // MarshalJSON implements stdjson.Marshaler. -func (s OptNilAnyArray) MarshalJSON() ([]byte, error) { +func (s OptCreateCompletionRequestLogitBias) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptNilAnyArray) UnmarshalJSON(data []byte) error { +func (s *OptCreateCompletionRequestLogitBias) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } -// Encode encodes bool as json. -func (o OptNilBool) Encode(e *jx.Encoder) { +// Encode encodes CreateCompletionResponseUsage as json. +func (o OptCreateCompletionResponseUsage) Encode(e *jx.Encoder) { if !o.Set { return } - if o.Null { - e.Null() - return - } - e.Bool(bool(o.Value)) + o.Value.Encode(e) } -// Decode decodes bool from json. -func (o *OptNilBool) Decode(d *jx.Decoder) error { +// Decode decodes CreateCompletionResponseUsage from json. +func (o *OptCreateCompletionResponseUsage) Decode(d *jx.Decoder) error { if o == nil { - return errors.New("invalid: unable to decode OptNilBool to nil") - } - if d.Next() == jx.Null { - if err := d.Null(); err != nil { - return err - } - - var v bool - o.Value = v - o.Set = true - o.Null = true - return nil + return errors.New("invalid: unable to decode OptCreateCompletionResponseUsage to nil") } o.Set = true - o.Null = false - v, err := d.Bool() - if err != nil { + if err := o.Value.Decode(d); err != nil { return err } - o.Value = bool(v) return nil } // MarshalJSON implements stdjson.Marshaler. -func (s OptNilBool) MarshalJSON() ([]byte, error) { +func (s OptCreateCompletionResponseUsage) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptNilBool) UnmarshalJSON(data []byte) error { +func (s *OptCreateCompletionResponseUsage) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } -// Encode encodes CreateAnswerRequestLogitBias as json. -func (o OptNilCreateAnswerRequestLogitBias) Encode(e *jx.Encoder) { +// Encode encodes float64 as json. +func (o OptFloat64) Encode(e *jx.Encoder) { if !o.Set { return } - if o.Null { - e.Null() - return - } - o.Value.Encode(e) + e.Float64(float64(o.Value)) } -// Decode decodes CreateAnswerRequestLogitBias from json. -func (o *OptNilCreateAnswerRequestLogitBias) Decode(d *jx.Decoder) error { +// Decode decodes float64 from json. +func (o *OptFloat64) Decode(d *jx.Decoder) error { if o == nil { - return errors.New("invalid: unable to decode OptNilCreateAnswerRequestLogitBias to nil") - } - if d.Next() == jx.Null { - if err := d.Null(); err != nil { - return err - } - - var v CreateAnswerRequestLogitBias - o.Value = v - o.Set = true - o.Null = true - return nil + return errors.New("invalid: unable to decode OptFloat64 to nil") } o.Set = true - o.Null = false - o.Value = make(CreateAnswerRequestLogitBias) - if err := o.Value.Decode(d); err != nil { + v, err := d.Float64() + if err != nil { return err } + o.Value = float64(v) return nil } // MarshalJSON implements stdjson.Marshaler. -func (s OptNilCreateAnswerRequestLogitBias) MarshalJSON() ([]byte, error) { +func (s OptFloat64) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptNilCreateAnswerRequestLogitBias) UnmarshalJSON(data []byte) error { +func (s *OptFloat64) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } -// Encode encodes CreateAnswerRequestStop as json. -func (o OptNilCreateAnswerRequestStop) Encode(e *jx.Encoder) { +// Encode encodes int as json. +func (o OptInt) Encode(e *jx.Encoder) { if !o.Set { return } - if o.Null { - e.Null() - return - } - o.Value.Encode(e) + e.Int(int(o.Value)) } -// Decode decodes CreateAnswerRequestStop from json. -func (o *OptNilCreateAnswerRequestStop) Decode(d *jx.Decoder) error { +// Decode decodes int from json. +func (o *OptInt) Decode(d *jx.Decoder) error { if o == nil { - return errors.New("invalid: unable to decode OptNilCreateAnswerRequestStop to nil") - } - if d.Next() == jx.Null { - if err := d.Null(); err != nil { - return err - } - - var v CreateAnswerRequestStop - o.Value = v - o.Set = true - o.Null = true - return nil + return errors.New("invalid: unable to decode OptInt to nil") } o.Set = true - o.Null = false - if err := o.Value.Decode(d); err != nil { + v, err := d.Int() + if err != nil { return err } + o.Value = int(v) return nil } // MarshalJSON implements stdjson.Marshaler. -func (s OptNilCreateAnswerRequestStop) MarshalJSON() ([]byte, error) { +func (s OptInt) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptNilCreateAnswerRequestStop) UnmarshalJSON(data []byte) error { +func (s *OptInt) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } -// Encode encodes CreateChatCompletionRequestLogitBias as json. -func (o OptNilCreateChatCompletionRequestLogitBias) Encode(e *jx.Encoder) { +// Encode encodes []jx.Raw as json. +func (o OptNilAnyArray) Encode(e *jx.Encoder) { if !o.Set { return } @@ -8655,20 +8488,26 @@ func (o OptNilCreateChatCompletionRequestLogitBias) Encode(e *jx.Encoder) { e.Null() return } - o.Value.Encode(e) + e.ArrStart() + for _, elem := range o.Value { + if len(elem) != 0 { + e.Raw(elem) + } + } + e.ArrEnd() } -// Decode decodes CreateChatCompletionRequestLogitBias from json. -func (o *OptNilCreateChatCompletionRequestLogitBias) Decode(d *jx.Decoder) error { +// Decode decodes []jx.Raw from json. +func (o *OptNilAnyArray) Decode(d *jx.Decoder) error { if o == nil { - return errors.New("invalid: unable to decode OptNilCreateChatCompletionRequestLogitBias to nil") + return errors.New("invalid: unable to decode OptNilAnyArray to nil") } if d.Next() == jx.Null { if err := d.Null(); err != nil { return err } - var v CreateChatCompletionRequestLogitBias + var v []jx.Raw o.Value = v o.Set = true o.Null = true @@ -8676,28 +8515,37 @@ func (o *OptNilCreateChatCompletionRequestLogitBias) Decode(d *jx.Decoder) error } o.Set = true o.Null = false - o.Value = make(CreateChatCompletionRequestLogitBias) - if err := o.Value.Decode(d); err != nil { + o.Value = make([]jx.Raw, 0) + if err := d.Arr(func(d *jx.Decoder) error { + var elem jx.Raw + v, err := d.RawAppend(nil) + elem = jx.Raw(v) + if err != nil { + return err + } + o.Value = append(o.Value, elem) + return nil + }); err != nil { return err } return nil } // MarshalJSON implements stdjson.Marshaler. -func (s OptNilCreateChatCompletionRequestLogitBias) MarshalJSON() ([]byte, error) { +func (s OptNilAnyArray) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptNilCreateChatCompletionRequestLogitBias) UnmarshalJSON(data []byte) error { +func (s *OptNilAnyArray) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } -// Encode encodes CreateChatCompletionRequestStop as json. -func (o OptNilCreateChatCompletionRequestStop) Encode(e *jx.Encoder) { +// Encode encodes bool as json. +func (o OptNilBool) Encode(e *jx.Encoder) { if !o.Set { return } @@ -8705,20 +8553,20 @@ func (o OptNilCreateChatCompletionRequestStop) Encode(e *jx.Encoder) { e.Null() return } - o.Value.Encode(e) + e.Bool(bool(o.Value)) } -// Decode decodes CreateChatCompletionRequestStop from json. -func (o *OptNilCreateChatCompletionRequestStop) Decode(d *jx.Decoder) error { +// Decode decodes bool from json. +func (o *OptNilBool) Decode(d *jx.Decoder) error { if o == nil { - return errors.New("invalid: unable to decode OptNilCreateChatCompletionRequestStop to nil") + return errors.New("invalid: unable to decode OptNilBool to nil") } if d.Next() == jx.Null { if err := d.Null(); err != nil { return err } - var v CreateChatCompletionRequestStop + var v bool o.Value = v o.Set = true o.Null = true @@ -8726,27 +8574,29 @@ func (o *OptNilCreateChatCompletionRequestStop) Decode(d *jx.Decoder) error { } o.Set = true o.Null = false - if err := o.Value.Decode(d); err != nil { + v, err := d.Bool() + if err != nil { return err } + o.Value = bool(v) return nil } // MarshalJSON implements stdjson.Marshaler. -func (s OptNilCreateChatCompletionRequestStop) MarshalJSON() ([]byte, error) { +func (s OptNilBool) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptNilCreateChatCompletionRequestStop) UnmarshalJSON(data []byte) error { +func (s *OptNilBool) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } -// Encode encodes CreateClassificationRequestLogitBias as json. -func (o OptNilCreateClassificationRequestLogitBias) Encode(e *jx.Encoder) { +// Encode encodes CreateAnswerRequestStop as json. +func (o OptNilCreateAnswerRequestStop) Encode(e *jx.Encoder) { if !o.Set { return } @@ -8757,17 +8607,17 @@ func (o OptNilCreateClassificationRequestLogitBias) Encode(e *jx.Encoder) { o.Value.Encode(e) } -// Decode decodes CreateClassificationRequestLogitBias from json. -func (o *OptNilCreateClassificationRequestLogitBias) Decode(d *jx.Decoder) error { +// Decode decodes CreateAnswerRequestStop from json. +func (o *OptNilCreateAnswerRequestStop) Decode(d *jx.Decoder) error { if o == nil { - return errors.New("invalid: unable to decode OptNilCreateClassificationRequestLogitBias to nil") + return errors.New("invalid: unable to decode OptNilCreateAnswerRequestStop to nil") } if d.Next() == jx.Null { if err := d.Null(); err != nil { return err } - var v CreateClassificationRequestLogitBias + var v CreateAnswerRequestStop o.Value = v o.Set = true o.Null = true @@ -8775,7 +8625,6 @@ func (o *OptNilCreateClassificationRequestLogitBias) Decode(d *jx.Decoder) error } o.Set = true o.Null = false - o.Value = make(CreateClassificationRequestLogitBias) if err := o.Value.Decode(d); err != nil { return err } @@ -8783,20 +8632,20 @@ func (o *OptNilCreateClassificationRequestLogitBias) Decode(d *jx.Decoder) error } // MarshalJSON implements stdjson.Marshaler. -func (s OptNilCreateClassificationRequestLogitBias) MarshalJSON() ([]byte, error) { +func (s OptNilCreateAnswerRequestStop) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptNilCreateClassificationRequestLogitBias) UnmarshalJSON(data []byte) error { +func (s *OptNilCreateAnswerRequestStop) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } -// Encode encodes CreateCompletionRequestLogitBias as json. -func (o OptNilCreateCompletionRequestLogitBias) Encode(e *jx.Encoder) { +// Encode encodes CreateChatCompletionRequestStop as json. +func (o OptNilCreateChatCompletionRequestStop) Encode(e *jx.Encoder) { if !o.Set { return } @@ -8807,17 +8656,17 @@ func (o OptNilCreateCompletionRequestLogitBias) Encode(e *jx.Encoder) { o.Value.Encode(e) } -// Decode decodes CreateCompletionRequestLogitBias from json. -func (o *OptNilCreateCompletionRequestLogitBias) Decode(d *jx.Decoder) error { +// Decode decodes CreateChatCompletionRequestStop from json. +func (o *OptNilCreateChatCompletionRequestStop) Decode(d *jx.Decoder) error { if o == nil { - return errors.New("invalid: unable to decode OptNilCreateCompletionRequestLogitBias to nil") + return errors.New("invalid: unable to decode OptNilCreateChatCompletionRequestStop to nil") } if d.Next() == jx.Null { if err := d.Null(); err != nil { return err } - var v CreateCompletionRequestLogitBias + var v CreateChatCompletionRequestStop o.Value = v o.Set = true o.Null = true @@ -8825,7 +8674,6 @@ func (o *OptNilCreateCompletionRequestLogitBias) Decode(d *jx.Decoder) error { } o.Set = true o.Null = false - o.Value = make(CreateCompletionRequestLogitBias) if err := o.Value.Decode(d); err != nil { return err } @@ -8833,14 +8681,14 @@ func (o *OptNilCreateCompletionRequestLogitBias) Decode(d *jx.Decoder) error { } // MarshalJSON implements stdjson.Marshaler. -func (s OptNilCreateCompletionRequestLogitBias) MarshalJSON() ([]byte, error) { +func (s OptNilCreateChatCompletionRequestStop) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil } // UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptNilCreateCompletionRequestLogitBias) UnmarshalJSON(data []byte) error { +func (s *OptNilCreateChatCompletionRequestStop) UnmarshalJSON(data []byte) error { d := jx.DecodeBytes(data) return s.Decode(d) } diff --git a/examples/ex_openai/oas_schemas_gen.go b/examples/ex_openai/oas_schemas_gen.go index 660df8c7c..bab05afc6 100644 --- a/examples/ex_openai/oas_schemas_gen.go +++ b/examples/ex_openai/oas_schemas_gen.go @@ -230,7 +230,7 @@ type CreateAnswerRequest struct { // or 100 should result in a ban or exclusive selection of the relevant token. // As an example, you can pass `{"50256": -100}` to prevent the <|endoftext|> token from being // generated. - LogitBias OptNilCreateAnswerRequestLogitBias `json:"logit_bias"` + LogitBias OptCreateAnswerRequestLogitBias `json:"logit_bias"` // A special boolean flag for showing metadata. If set to `true`, each document entry in the returned // JSON will contain a "metadata" field. // This flag only takes effect when `file` is set. @@ -312,7 +312,7 @@ func (s *CreateAnswerRequest) GetN() OptNilInt { } // GetLogitBias returns the value of LogitBias. -func (s *CreateAnswerRequest) GetLogitBias() OptNilCreateAnswerRequestLogitBias { +func (s *CreateAnswerRequest) GetLogitBias() OptCreateAnswerRequestLogitBias { return s.LogitBias } @@ -402,7 +402,7 @@ func (s *CreateAnswerRequest) SetN(val OptNilInt) { } // SetLogitBias sets the value of LogitBias. -func (s *CreateAnswerRequest) SetLogitBias(val OptNilCreateAnswerRequestLogitBias) { +func (s *CreateAnswerRequest) SetLogitBias(val OptCreateAnswerRequestLogitBias) { s.LogitBias = val } @@ -437,16 +437,7 @@ func (s *CreateAnswerRequest) SetUser(val OptString) { // or 100 should result in a ban or exclusive selection of the relevant token. // As an example, you can pass `{"50256": -100}` to prevent the <|endoftext|> token from being // generated. -type CreateAnswerRequestLogitBias map[string]jx.Raw - -func (s *CreateAnswerRequestLogitBias) init() CreateAnswerRequestLogitBias { - m := *s - if m == nil { - m = map[string]jx.Raw{} - *s = m - } - return m -} +type CreateAnswerRequestLogitBias struct{} // Up to 4 sequences where the API will stop generating further tokens. The returned text will not // contain the stop sequence. @@ -655,7 +646,7 @@ type CreateChatCompletionRequest struct { // by the model prior to sampling. The exact effect will vary per model, but values between -1 and 1 // should decrease or increase likelihood of selection; values like -100 or 100 should result in a // ban or exclusive selection of the relevant token. - LogitBias OptNilCreateChatCompletionRequestLogitBias `json:"logit_bias"` + LogitBias OptCreateChatCompletionRequestLogitBias `json:"logit_bias"` // A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. // [Learn more](/docs/guides/safety-best-practices/end-user-ids). User OptString `json:"user"` @@ -712,7 +703,7 @@ func (s *CreateChatCompletionRequest) GetFrequencyPenalty() OptNilFloat64 { } // GetLogitBias returns the value of LogitBias. -func (s *CreateChatCompletionRequest) GetLogitBias() OptNilCreateChatCompletionRequestLogitBias { +func (s *CreateChatCompletionRequest) GetLogitBias() OptCreateChatCompletionRequestLogitBias { return s.LogitBias } @@ -772,7 +763,7 @@ func (s *CreateChatCompletionRequest) SetFrequencyPenalty(val OptNilFloat64) { } // SetLogitBias sets the value of LogitBias. -func (s *CreateChatCompletionRequest) SetLogitBias(val OptNilCreateChatCompletionRequestLogitBias) { +func (s *CreateChatCompletionRequest) SetLogitBias(val OptCreateChatCompletionRequestLogitBias) { s.LogitBias = val } @@ -787,16 +778,7 @@ func (s *CreateChatCompletionRequest) SetUser(val OptString) { // by the model prior to sampling. The exact effect will vary per model, but values between -1 and 1 // should decrease or increase likelihood of selection; values like -100 or 100 should result in a // ban or exclusive selection of the relevant token. -type CreateChatCompletionRequestLogitBias map[string]jx.Raw - -func (s *CreateChatCompletionRequestLogitBias) init() CreateChatCompletionRequestLogitBias { - m := *s - if m == nil { - m = map[string]jx.Raw{} - *s = m - } - return m -} +type CreateChatCompletionRequestLogitBias struct{} // Up to 4 sequences where the API will stop generating further tokens. // CreateChatCompletionRequestStop represents sum type. @@ -1057,7 +1039,7 @@ type CreateClassificationRequest struct { // or 100 should result in a ban or exclusive selection of the relevant token. // As an example, you can pass `{"50256": -100}` to prevent the <|endoftext|> token from being // generated. - LogitBias OptNilCreateClassificationRequestLogitBias `json:"logit_bias"` + LogitBias OptCreateClassificationRequestLogitBias `json:"logit_bias"` // If set to `true`, the returned JSON will include a "prompt" field containing the final prompt that // was used to request a completion. This is mainly useful for debugging purposes. ReturnPrompt OptNilBool `json:"return_prompt"` @@ -1119,7 +1101,7 @@ func (s *CreateClassificationRequest) GetMaxExamples() OptNilInt { } // GetLogitBias returns the value of LogitBias. -func (s *CreateClassificationRequest) GetLogitBias() OptNilCreateClassificationRequestLogitBias { +func (s *CreateClassificationRequest) GetLogitBias() OptCreateClassificationRequestLogitBias { return s.LogitBias } @@ -1189,7 +1171,7 @@ func (s *CreateClassificationRequest) SetMaxExamples(val OptNilInt) { } // SetLogitBias sets the value of LogitBias. -func (s *CreateClassificationRequest) SetLogitBias(val OptNilCreateClassificationRequestLogitBias) { +func (s *CreateClassificationRequest) SetLogitBias(val OptCreateClassificationRequestLogitBias) { s.LogitBias = val } @@ -1224,16 +1206,7 @@ func (s *CreateClassificationRequest) SetUser(val OptString) { // or 100 should result in a ban or exclusive selection of the relevant token. // As an example, you can pass `{"50256": -100}` to prevent the <|endoftext|> token from being // generated. -type CreateClassificationRequestLogitBias map[string]jx.Raw - -func (s *CreateClassificationRequestLogitBias) init() CreateClassificationRequestLogitBias { - m := *s - if m == nil { - m = map[string]jx.Raw{} - *s = m - } - return m -} +type CreateClassificationRequestLogitBias struct{} // Ref: #/components/schemas/CreateClassificationResponse type CreateClassificationResponse struct { @@ -1414,7 +1387,7 @@ type CreateCompletionRequest struct { // or 100 should result in a ban or exclusive selection of the relevant token. // As an example, you can pass `{"50256": -100}` to prevent the <|endoftext|> token from being // generated. - LogitBias OptNilCreateCompletionRequestLogitBias `json:"logit_bias"` + LogitBias OptCreateCompletionRequestLogitBias `json:"logit_bias"` // A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. // [Learn more](/docs/guides/safety-best-practices/end-user-ids). User OptString `json:"user"` @@ -1491,7 +1464,7 @@ func (s *CreateCompletionRequest) GetBestOf() OptNilInt { } // GetLogitBias returns the value of LogitBias. -func (s *CreateCompletionRequest) GetLogitBias() OptNilCreateCompletionRequestLogitBias { +func (s *CreateCompletionRequest) GetLogitBias() OptCreateCompletionRequestLogitBias { return s.LogitBias } @@ -1571,7 +1544,7 @@ func (s *CreateCompletionRequest) SetBestOf(val OptNilInt) { } // SetLogitBias sets the value of LogitBias. -func (s *CreateCompletionRequest) SetLogitBias(val OptNilCreateCompletionRequestLogitBias) { +func (s *CreateCompletionRequest) SetLogitBias(val OptCreateCompletionRequestLogitBias) { s.LogitBias = val } @@ -1591,16 +1564,7 @@ func (s *CreateCompletionRequest) SetUser(val OptString) { // or 100 should result in a ban or exclusive selection of the relevant token. // As an example, you can pass `{"50256": -100}` to prevent the <|endoftext|> token from being // generated. -type CreateCompletionRequestLogitBias map[string]jx.Raw - -func (s *CreateCompletionRequestLogitBias) init() CreateCompletionRequestLogitBias { - m := *s - if m == nil { - m = map[string]jx.Raw{} - *s = m - } - return m -} +type CreateCompletionRequestLogitBias struct{} // The prompt(s) to generate completions for, encoded as a string, array of strings, array of tokens, // or array of token arrays. @@ -1934,16 +1898,7 @@ func (s *CreateCompletionResponseChoicesItemLogprobs) SetTextOffset(val []int) { s.TextOffset = val } -type CreateCompletionResponseChoicesItemLogprobsTopLogprobsItem map[string]jx.Raw - -func (s *CreateCompletionResponseChoicesItemLogprobsTopLogprobsItem) init() CreateCompletionResponseChoicesItemLogprobsTopLogprobsItem { - m := *s - if m == nil { - m = map[string]jx.Raw{} - *s = m - } - return m -} +type CreateCompletionResponseChoicesItemLogprobsTopLogprobsItem struct{} type CreateCompletionResponseUsage struct { PromptTokens int `json:"prompt_tokens"` @@ -2205,16 +2160,7 @@ func (s *CreateEditResponseChoicesItemLogprobs) SetTextOffset(val []int) { s.TextOffset = val } -type CreateEditResponseChoicesItemLogprobsTopLogprobsItem map[string]jx.Raw - -func (s *CreateEditResponseChoicesItemLogprobsTopLogprobsItem) init() CreateEditResponseChoicesItemLogprobsTopLogprobsItem { - m := *s - if m == nil { - m = map[string]jx.Raw{} - *s = m - } - return m -} +type CreateEditResponseChoicesItemLogprobsTopLogprobsItem struct{} type CreateEditResponseUsage struct { PromptTokens int `json:"prompt_tokens"` @@ -4186,38 +4132,38 @@ func (o OptChatCompletionResponseMessage) Or(d ChatCompletionResponseMessage) Ch return d } -// NewOptCreateChatCompletionResponseUsage returns new OptCreateChatCompletionResponseUsage with value set to v. -func NewOptCreateChatCompletionResponseUsage(v CreateChatCompletionResponseUsage) OptCreateChatCompletionResponseUsage { - return OptCreateChatCompletionResponseUsage{ +// NewOptCreateAnswerRequestLogitBias returns new OptCreateAnswerRequestLogitBias with value set to v. +func NewOptCreateAnswerRequestLogitBias(v *CreateAnswerRequestLogitBias) OptCreateAnswerRequestLogitBias { + return OptCreateAnswerRequestLogitBias{ Value: v, Set: true, } } -// OptCreateChatCompletionResponseUsage is optional CreateChatCompletionResponseUsage. -type OptCreateChatCompletionResponseUsage struct { - Value CreateChatCompletionResponseUsage +// OptCreateAnswerRequestLogitBias is optional *CreateAnswerRequestLogitBias. +type OptCreateAnswerRequestLogitBias struct { + Value *CreateAnswerRequestLogitBias Set bool } -// IsSet returns true if OptCreateChatCompletionResponseUsage was set. -func (o OptCreateChatCompletionResponseUsage) IsSet() bool { return o.Set } +// IsSet returns true if OptCreateAnswerRequestLogitBias was set. +func (o OptCreateAnswerRequestLogitBias) IsSet() bool { return o.Set } // Reset unsets value. -func (o *OptCreateChatCompletionResponseUsage) Reset() { - var v CreateChatCompletionResponseUsage +func (o *OptCreateAnswerRequestLogitBias) Reset() { + var v *CreateAnswerRequestLogitBias o.Value = v o.Set = false } // SetTo sets value to v. -func (o *OptCreateChatCompletionResponseUsage) SetTo(v CreateChatCompletionResponseUsage) { +func (o *OptCreateAnswerRequestLogitBias) SetTo(v *CreateAnswerRequestLogitBias) { o.Set = true o.Value = v } // Get returns value and boolean that denotes whether value was set. -func (o OptCreateChatCompletionResponseUsage) Get() (v CreateChatCompletionResponseUsage, ok bool) { +func (o OptCreateAnswerRequestLogitBias) Get() (v *CreateAnswerRequestLogitBias, ok bool) { if !o.Set { return v, false } @@ -4225,45 +4171,45 @@ func (o OptCreateChatCompletionResponseUsage) Get() (v CreateChatCompletionRespo } // Or returns value if set, or given parameter if does not. -func (o OptCreateChatCompletionResponseUsage) Or(d CreateChatCompletionResponseUsage) CreateChatCompletionResponseUsage { +func (o OptCreateAnswerRequestLogitBias) Or(d *CreateAnswerRequestLogitBias) *CreateAnswerRequestLogitBias { if v, ok := o.Get(); ok { return v } return d } -// NewOptCreateCompletionResponseUsage returns new OptCreateCompletionResponseUsage with value set to v. -func NewOptCreateCompletionResponseUsage(v CreateCompletionResponseUsage) OptCreateCompletionResponseUsage { - return OptCreateCompletionResponseUsage{ +// NewOptCreateChatCompletionRequestLogitBias returns new OptCreateChatCompletionRequestLogitBias with value set to v. +func NewOptCreateChatCompletionRequestLogitBias(v *CreateChatCompletionRequestLogitBias) OptCreateChatCompletionRequestLogitBias { + return OptCreateChatCompletionRequestLogitBias{ Value: v, Set: true, } } -// OptCreateCompletionResponseUsage is optional CreateCompletionResponseUsage. -type OptCreateCompletionResponseUsage struct { - Value CreateCompletionResponseUsage +// OptCreateChatCompletionRequestLogitBias is optional *CreateChatCompletionRequestLogitBias. +type OptCreateChatCompletionRequestLogitBias struct { + Value *CreateChatCompletionRequestLogitBias Set bool } -// IsSet returns true if OptCreateCompletionResponseUsage was set. -func (o OptCreateCompletionResponseUsage) IsSet() bool { return o.Set } +// IsSet returns true if OptCreateChatCompletionRequestLogitBias was set. +func (o OptCreateChatCompletionRequestLogitBias) IsSet() bool { return o.Set } // Reset unsets value. -func (o *OptCreateCompletionResponseUsage) Reset() { - var v CreateCompletionResponseUsage +func (o *OptCreateChatCompletionRequestLogitBias) Reset() { + var v *CreateChatCompletionRequestLogitBias o.Value = v o.Set = false } // SetTo sets value to v. -func (o *OptCreateCompletionResponseUsage) SetTo(v CreateCompletionResponseUsage) { +func (o *OptCreateChatCompletionRequestLogitBias) SetTo(v *CreateChatCompletionRequestLogitBias) { o.Set = true o.Value = v } // Get returns value and boolean that denotes whether value was set. -func (o OptCreateCompletionResponseUsage) Get() (v CreateCompletionResponseUsage, ok bool) { +func (o OptCreateChatCompletionRequestLogitBias) Get() (v *CreateChatCompletionRequestLogitBias, ok bool) { if !o.Set { return v, false } @@ -4271,45 +4217,45 @@ func (o OptCreateCompletionResponseUsage) Get() (v CreateCompletionResponseUsage } // Or returns value if set, or given parameter if does not. -func (o OptCreateCompletionResponseUsage) Or(d CreateCompletionResponseUsage) CreateCompletionResponseUsage { +func (o OptCreateChatCompletionRequestLogitBias) Or(d *CreateChatCompletionRequestLogitBias) *CreateChatCompletionRequestLogitBias { if v, ok := o.Get(); ok { return v } return d } -// NewOptFloat64 returns new OptFloat64 with value set to v. -func NewOptFloat64(v float64) OptFloat64 { - return OptFloat64{ +// NewOptCreateChatCompletionResponseUsage returns new OptCreateChatCompletionResponseUsage with value set to v. +func NewOptCreateChatCompletionResponseUsage(v CreateChatCompletionResponseUsage) OptCreateChatCompletionResponseUsage { + return OptCreateChatCompletionResponseUsage{ Value: v, Set: true, } } -// OptFloat64 is optional float64. -type OptFloat64 struct { - Value float64 +// OptCreateChatCompletionResponseUsage is optional CreateChatCompletionResponseUsage. +type OptCreateChatCompletionResponseUsage struct { + Value CreateChatCompletionResponseUsage Set bool } -// IsSet returns true if OptFloat64 was set. -func (o OptFloat64) IsSet() bool { return o.Set } +// IsSet returns true if OptCreateChatCompletionResponseUsage was set. +func (o OptCreateChatCompletionResponseUsage) IsSet() bool { return o.Set } // Reset unsets value. -func (o *OptFloat64) Reset() { - var v float64 +func (o *OptCreateChatCompletionResponseUsage) Reset() { + var v CreateChatCompletionResponseUsage o.Value = v o.Set = false } // SetTo sets value to v. -func (o *OptFloat64) SetTo(v float64) { +func (o *OptCreateChatCompletionResponseUsage) SetTo(v CreateChatCompletionResponseUsage) { o.Set = true o.Value = v } // Get returns value and boolean that denotes whether value was set. -func (o OptFloat64) Get() (v float64, ok bool) { +func (o OptCreateChatCompletionResponseUsage) Get() (v CreateChatCompletionResponseUsage, ok bool) { if !o.Set { return v, false } @@ -4317,45 +4263,45 @@ func (o OptFloat64) Get() (v float64, ok bool) { } // Or returns value if set, or given parameter if does not. -func (o OptFloat64) Or(d float64) float64 { +func (o OptCreateChatCompletionResponseUsage) Or(d CreateChatCompletionResponseUsage) CreateChatCompletionResponseUsage { if v, ok := o.Get(); ok { return v } return d } -// NewOptInt returns new OptInt with value set to v. -func NewOptInt(v int) OptInt { - return OptInt{ +// NewOptCreateClassificationRequestLogitBias returns new OptCreateClassificationRequestLogitBias with value set to v. +func NewOptCreateClassificationRequestLogitBias(v *CreateClassificationRequestLogitBias) OptCreateClassificationRequestLogitBias { + return OptCreateClassificationRequestLogitBias{ Value: v, Set: true, } } -// OptInt is optional int. -type OptInt struct { - Value int +// OptCreateClassificationRequestLogitBias is optional *CreateClassificationRequestLogitBias. +type OptCreateClassificationRequestLogitBias struct { + Value *CreateClassificationRequestLogitBias Set bool } -// IsSet returns true if OptInt was set. -func (o OptInt) IsSet() bool { return o.Set } +// IsSet returns true if OptCreateClassificationRequestLogitBias was set. +func (o OptCreateClassificationRequestLogitBias) IsSet() bool { return o.Set } // Reset unsets value. -func (o *OptInt) Reset() { - var v int +func (o *OptCreateClassificationRequestLogitBias) Reset() { + var v *CreateClassificationRequestLogitBias o.Value = v o.Set = false } // SetTo sets value to v. -func (o *OptInt) SetTo(v int) { +func (o *OptCreateClassificationRequestLogitBias) SetTo(v *CreateClassificationRequestLogitBias) { o.Set = true o.Value = v } // Get returns value and boolean that denotes whether value was set. -func (o OptInt) Get() (v int, ok bool) { +func (o OptCreateClassificationRequestLogitBias) Get() (v *CreateClassificationRequestLogitBias, ok bool) { if !o.Set { return v, false } @@ -4363,45 +4309,45 @@ func (o OptInt) Get() (v int, ok bool) { } // Or returns value if set, or given parameter if does not. -func (o OptInt) Or(d int) int { +func (o OptCreateClassificationRequestLogitBias) Or(d *CreateClassificationRequestLogitBias) *CreateClassificationRequestLogitBias { if v, ok := o.Get(); ok { return v } return d } -// NewOptMultipartFile returns new OptMultipartFile with value set to v. -func NewOptMultipartFile(v ht.MultipartFile) OptMultipartFile { - return OptMultipartFile{ +// NewOptCreateCompletionRequestLogitBias returns new OptCreateCompletionRequestLogitBias with value set to v. +func NewOptCreateCompletionRequestLogitBias(v *CreateCompletionRequestLogitBias) OptCreateCompletionRequestLogitBias { + return OptCreateCompletionRequestLogitBias{ Value: v, Set: true, } } -// OptMultipartFile is optional ht.MultipartFile. -type OptMultipartFile struct { - Value ht.MultipartFile +// OptCreateCompletionRequestLogitBias is optional *CreateCompletionRequestLogitBias. +type OptCreateCompletionRequestLogitBias struct { + Value *CreateCompletionRequestLogitBias Set bool } -// IsSet returns true if OptMultipartFile was set. -func (o OptMultipartFile) IsSet() bool { return o.Set } +// IsSet returns true if OptCreateCompletionRequestLogitBias was set. +func (o OptCreateCompletionRequestLogitBias) IsSet() bool { return o.Set } // Reset unsets value. -func (o *OptMultipartFile) Reset() { - var v ht.MultipartFile +func (o *OptCreateCompletionRequestLogitBias) Reset() { + var v *CreateCompletionRequestLogitBias o.Value = v o.Set = false } // SetTo sets value to v. -func (o *OptMultipartFile) SetTo(v ht.MultipartFile) { +func (o *OptCreateCompletionRequestLogitBias) SetTo(v *CreateCompletionRequestLogitBias) { o.Set = true o.Value = v } // Get returns value and boolean that denotes whether value was set. -func (o OptMultipartFile) Get() (v ht.MultipartFile, ok bool) { +func (o OptCreateCompletionRequestLogitBias) Get() (v *CreateCompletionRequestLogitBias, ok bool) { if !o.Set { return v, false } @@ -4409,62 +4355,45 @@ func (o OptMultipartFile) Get() (v ht.MultipartFile, ok bool) { } // Or returns value if set, or given parameter if does not. -func (o OptMultipartFile) Or(d ht.MultipartFile) ht.MultipartFile { +func (o OptCreateCompletionRequestLogitBias) Or(d *CreateCompletionRequestLogitBias) *CreateCompletionRequestLogitBias { if v, ok := o.Get(); ok { return v } return d } -// NewOptNilAnyArray returns new OptNilAnyArray with value set to v. -func NewOptNilAnyArray(v []jx.Raw) OptNilAnyArray { - return OptNilAnyArray{ +// NewOptCreateCompletionResponseUsage returns new OptCreateCompletionResponseUsage with value set to v. +func NewOptCreateCompletionResponseUsage(v CreateCompletionResponseUsage) OptCreateCompletionResponseUsage { + return OptCreateCompletionResponseUsage{ Value: v, Set: true, } } -// OptNilAnyArray is optional nullable []jx.Raw. -type OptNilAnyArray struct { - Value []jx.Raw +// OptCreateCompletionResponseUsage is optional CreateCompletionResponseUsage. +type OptCreateCompletionResponseUsage struct { + Value CreateCompletionResponseUsage Set bool - Null bool } -// IsSet returns true if OptNilAnyArray was set. -func (o OptNilAnyArray) IsSet() bool { return o.Set } +// IsSet returns true if OptCreateCompletionResponseUsage was set. +func (o OptCreateCompletionResponseUsage) IsSet() bool { return o.Set } // Reset unsets value. -func (o *OptNilAnyArray) Reset() { - var v []jx.Raw +func (o *OptCreateCompletionResponseUsage) Reset() { + var v CreateCompletionResponseUsage o.Value = v o.Set = false - o.Null = false } // SetTo sets value to v. -func (o *OptNilAnyArray) SetTo(v []jx.Raw) { - o.Set = true - o.Null = false - o.Value = v -} - -// IsSet returns true if value is Null. -func (o OptNilAnyArray) IsNull() bool { return o.Null } - -// SetNull sets value to null. -func (o *OptNilAnyArray) SetToNull() { +func (o *OptCreateCompletionResponseUsage) SetTo(v CreateCompletionResponseUsage) { o.Set = true - o.Null = true - var v []jx.Raw o.Value = v } // Get returns value and boolean that denotes whether value was set. -func (o OptNilAnyArray) Get() (v []jx.Raw, ok bool) { - if o.Null { - return v, false - } +func (o OptCreateCompletionResponseUsage) Get() (v CreateCompletionResponseUsage, ok bool) { if !o.Set { return v, false } @@ -4472,62 +4401,45 @@ func (o OptNilAnyArray) Get() (v []jx.Raw, ok bool) { } // Or returns value if set, or given parameter if does not. -func (o OptNilAnyArray) Or(d []jx.Raw) []jx.Raw { +func (o OptCreateCompletionResponseUsage) Or(d CreateCompletionResponseUsage) CreateCompletionResponseUsage { if v, ok := o.Get(); ok { return v } return d } -// NewOptNilBool returns new OptNilBool with value set to v. -func NewOptNilBool(v bool) OptNilBool { - return OptNilBool{ +// NewOptFloat64 returns new OptFloat64 with value set to v. +func NewOptFloat64(v float64) OptFloat64 { + return OptFloat64{ Value: v, Set: true, } } -// OptNilBool is optional nullable bool. -type OptNilBool struct { - Value bool +// OptFloat64 is optional float64. +type OptFloat64 struct { + Value float64 Set bool - Null bool } -// IsSet returns true if OptNilBool was set. -func (o OptNilBool) IsSet() bool { return o.Set } +// IsSet returns true if OptFloat64 was set. +func (o OptFloat64) IsSet() bool { return o.Set } // Reset unsets value. -func (o *OptNilBool) Reset() { - var v bool +func (o *OptFloat64) Reset() { + var v float64 o.Value = v o.Set = false - o.Null = false } // SetTo sets value to v. -func (o *OptNilBool) SetTo(v bool) { - o.Set = true - o.Null = false - o.Value = v -} - -// IsSet returns true if value is Null. -func (o OptNilBool) IsNull() bool { return o.Null } - -// SetNull sets value to null. -func (o *OptNilBool) SetToNull() { +func (o *OptFloat64) SetTo(v float64) { o.Set = true - o.Null = true - var v bool o.Value = v } // Get returns value and boolean that denotes whether value was set. -func (o OptNilBool) Get() (v bool, ok bool) { - if o.Null { - return v, false - } +func (o OptFloat64) Get() (v float64, ok bool) { if !o.Set { return v, false } @@ -4535,62 +4447,45 @@ func (o OptNilBool) Get() (v bool, ok bool) { } // Or returns value if set, or given parameter if does not. -func (o OptNilBool) Or(d bool) bool { +func (o OptFloat64) Or(d float64) float64 { if v, ok := o.Get(); ok { return v } return d } -// NewOptNilCreateAnswerRequestLogitBias returns new OptNilCreateAnswerRequestLogitBias with value set to v. -func NewOptNilCreateAnswerRequestLogitBias(v CreateAnswerRequestLogitBias) OptNilCreateAnswerRequestLogitBias { - return OptNilCreateAnswerRequestLogitBias{ +// NewOptInt returns new OptInt with value set to v. +func NewOptInt(v int) OptInt { + return OptInt{ Value: v, Set: true, } } -// OptNilCreateAnswerRequestLogitBias is optional nullable CreateAnswerRequestLogitBias. -type OptNilCreateAnswerRequestLogitBias struct { - Value CreateAnswerRequestLogitBias +// OptInt is optional int. +type OptInt struct { + Value int Set bool - Null bool } -// IsSet returns true if OptNilCreateAnswerRequestLogitBias was set. -func (o OptNilCreateAnswerRequestLogitBias) IsSet() bool { return o.Set } +// IsSet returns true if OptInt was set. +func (o OptInt) IsSet() bool { return o.Set } // Reset unsets value. -func (o *OptNilCreateAnswerRequestLogitBias) Reset() { - var v CreateAnswerRequestLogitBias +func (o *OptInt) Reset() { + var v int o.Value = v o.Set = false - o.Null = false } // SetTo sets value to v. -func (o *OptNilCreateAnswerRequestLogitBias) SetTo(v CreateAnswerRequestLogitBias) { - o.Set = true - o.Null = false - o.Value = v -} - -// IsSet returns true if value is Null. -func (o OptNilCreateAnswerRequestLogitBias) IsNull() bool { return o.Null } - -// SetNull sets value to null. -func (o *OptNilCreateAnswerRequestLogitBias) SetToNull() { +func (o *OptInt) SetTo(v int) { o.Set = true - o.Null = true - var v CreateAnswerRequestLogitBias o.Value = v } // Get returns value and boolean that denotes whether value was set. -func (o OptNilCreateAnswerRequestLogitBias) Get() (v CreateAnswerRequestLogitBias, ok bool) { - if o.Null { - return v, false - } +func (o OptInt) Get() (v int, ok bool) { if !o.Set { return v, false } @@ -4598,62 +4493,45 @@ func (o OptNilCreateAnswerRequestLogitBias) Get() (v CreateAnswerRequestLogitBia } // Or returns value if set, or given parameter if does not. -func (o OptNilCreateAnswerRequestLogitBias) Or(d CreateAnswerRequestLogitBias) CreateAnswerRequestLogitBias { +func (o OptInt) Or(d int) int { if v, ok := o.Get(); ok { return v } return d } -// NewOptNilCreateAnswerRequestStop returns new OptNilCreateAnswerRequestStop with value set to v. -func NewOptNilCreateAnswerRequestStop(v CreateAnswerRequestStop) OptNilCreateAnswerRequestStop { - return OptNilCreateAnswerRequestStop{ +// NewOptMultipartFile returns new OptMultipartFile with value set to v. +func NewOptMultipartFile(v ht.MultipartFile) OptMultipartFile { + return OptMultipartFile{ Value: v, Set: true, } } -// OptNilCreateAnswerRequestStop is optional nullable CreateAnswerRequestStop. -type OptNilCreateAnswerRequestStop struct { - Value CreateAnswerRequestStop +// OptMultipartFile is optional ht.MultipartFile. +type OptMultipartFile struct { + Value ht.MultipartFile Set bool - Null bool } -// IsSet returns true if OptNilCreateAnswerRequestStop was set. -func (o OptNilCreateAnswerRequestStop) IsSet() bool { return o.Set } +// IsSet returns true if OptMultipartFile was set. +func (o OptMultipartFile) IsSet() bool { return o.Set } // Reset unsets value. -func (o *OptNilCreateAnswerRequestStop) Reset() { - var v CreateAnswerRequestStop +func (o *OptMultipartFile) Reset() { + var v ht.MultipartFile o.Value = v o.Set = false - o.Null = false } // SetTo sets value to v. -func (o *OptNilCreateAnswerRequestStop) SetTo(v CreateAnswerRequestStop) { - o.Set = true - o.Null = false - o.Value = v -} - -// IsSet returns true if value is Null. -func (o OptNilCreateAnswerRequestStop) IsNull() bool { return o.Null } - -// SetNull sets value to null. -func (o *OptNilCreateAnswerRequestStop) SetToNull() { +func (o *OptMultipartFile) SetTo(v ht.MultipartFile) { o.Set = true - o.Null = true - var v CreateAnswerRequestStop o.Value = v } // Get returns value and boolean that denotes whether value was set. -func (o OptNilCreateAnswerRequestStop) Get() (v CreateAnswerRequestStop, ok bool) { - if o.Null { - return v, false - } +func (o OptMultipartFile) Get() (v ht.MultipartFile, ok bool) { if !o.Set { return v, false } @@ -4661,59 +4539,59 @@ func (o OptNilCreateAnswerRequestStop) Get() (v CreateAnswerRequestStop, ok bool } // Or returns value if set, or given parameter if does not. -func (o OptNilCreateAnswerRequestStop) Or(d CreateAnswerRequestStop) CreateAnswerRequestStop { +func (o OptMultipartFile) Or(d ht.MultipartFile) ht.MultipartFile { if v, ok := o.Get(); ok { return v } return d } -// NewOptNilCreateChatCompletionRequestLogitBias returns new OptNilCreateChatCompletionRequestLogitBias with value set to v. -func NewOptNilCreateChatCompletionRequestLogitBias(v CreateChatCompletionRequestLogitBias) OptNilCreateChatCompletionRequestLogitBias { - return OptNilCreateChatCompletionRequestLogitBias{ +// NewOptNilAnyArray returns new OptNilAnyArray with value set to v. +func NewOptNilAnyArray(v []jx.Raw) OptNilAnyArray { + return OptNilAnyArray{ Value: v, Set: true, } } -// OptNilCreateChatCompletionRequestLogitBias is optional nullable CreateChatCompletionRequestLogitBias. -type OptNilCreateChatCompletionRequestLogitBias struct { - Value CreateChatCompletionRequestLogitBias +// OptNilAnyArray is optional nullable []jx.Raw. +type OptNilAnyArray struct { + Value []jx.Raw Set bool Null bool } -// IsSet returns true if OptNilCreateChatCompletionRequestLogitBias was set. -func (o OptNilCreateChatCompletionRequestLogitBias) IsSet() bool { return o.Set } +// IsSet returns true if OptNilAnyArray was set. +func (o OptNilAnyArray) IsSet() bool { return o.Set } // Reset unsets value. -func (o *OptNilCreateChatCompletionRequestLogitBias) Reset() { - var v CreateChatCompletionRequestLogitBias +func (o *OptNilAnyArray) Reset() { + var v []jx.Raw o.Value = v o.Set = false o.Null = false } // SetTo sets value to v. -func (o *OptNilCreateChatCompletionRequestLogitBias) SetTo(v CreateChatCompletionRequestLogitBias) { +func (o *OptNilAnyArray) SetTo(v []jx.Raw) { o.Set = true o.Null = false o.Value = v } // IsSet returns true if value is Null. -func (o OptNilCreateChatCompletionRequestLogitBias) IsNull() bool { return o.Null } +func (o OptNilAnyArray) IsNull() bool { return o.Null } // SetNull sets value to null. -func (o *OptNilCreateChatCompletionRequestLogitBias) SetToNull() { +func (o *OptNilAnyArray) SetToNull() { o.Set = true o.Null = true - var v CreateChatCompletionRequestLogitBias + var v []jx.Raw o.Value = v } // Get returns value and boolean that denotes whether value was set. -func (o OptNilCreateChatCompletionRequestLogitBias) Get() (v CreateChatCompletionRequestLogitBias, ok bool) { +func (o OptNilAnyArray) Get() (v []jx.Raw, ok bool) { if o.Null { return v, false } @@ -4724,59 +4602,59 @@ func (o OptNilCreateChatCompletionRequestLogitBias) Get() (v CreateChatCompletio } // Or returns value if set, or given parameter if does not. -func (o OptNilCreateChatCompletionRequestLogitBias) Or(d CreateChatCompletionRequestLogitBias) CreateChatCompletionRequestLogitBias { +func (o OptNilAnyArray) Or(d []jx.Raw) []jx.Raw { if v, ok := o.Get(); ok { return v } return d } -// NewOptNilCreateChatCompletionRequestStop returns new OptNilCreateChatCompletionRequestStop with value set to v. -func NewOptNilCreateChatCompletionRequestStop(v CreateChatCompletionRequestStop) OptNilCreateChatCompletionRequestStop { - return OptNilCreateChatCompletionRequestStop{ +// NewOptNilBool returns new OptNilBool with value set to v. +func NewOptNilBool(v bool) OptNilBool { + return OptNilBool{ Value: v, Set: true, } } -// OptNilCreateChatCompletionRequestStop is optional nullable CreateChatCompletionRequestStop. -type OptNilCreateChatCompletionRequestStop struct { - Value CreateChatCompletionRequestStop +// OptNilBool is optional nullable bool. +type OptNilBool struct { + Value bool Set bool Null bool } -// IsSet returns true if OptNilCreateChatCompletionRequestStop was set. -func (o OptNilCreateChatCompletionRequestStop) IsSet() bool { return o.Set } +// IsSet returns true if OptNilBool was set. +func (o OptNilBool) IsSet() bool { return o.Set } // Reset unsets value. -func (o *OptNilCreateChatCompletionRequestStop) Reset() { - var v CreateChatCompletionRequestStop +func (o *OptNilBool) Reset() { + var v bool o.Value = v o.Set = false o.Null = false } // SetTo sets value to v. -func (o *OptNilCreateChatCompletionRequestStop) SetTo(v CreateChatCompletionRequestStop) { +func (o *OptNilBool) SetTo(v bool) { o.Set = true o.Null = false o.Value = v } // IsSet returns true if value is Null. -func (o OptNilCreateChatCompletionRequestStop) IsNull() bool { return o.Null } +func (o OptNilBool) IsNull() bool { return o.Null } // SetNull sets value to null. -func (o *OptNilCreateChatCompletionRequestStop) SetToNull() { +func (o *OptNilBool) SetToNull() { o.Set = true o.Null = true - var v CreateChatCompletionRequestStop + var v bool o.Value = v } // Get returns value and boolean that denotes whether value was set. -func (o OptNilCreateChatCompletionRequestStop) Get() (v CreateChatCompletionRequestStop, ok bool) { +func (o OptNilBool) Get() (v bool, ok bool) { if o.Null { return v, false } @@ -4787,59 +4665,59 @@ func (o OptNilCreateChatCompletionRequestStop) Get() (v CreateChatCompletionRequ } // Or returns value if set, or given parameter if does not. -func (o OptNilCreateChatCompletionRequestStop) Or(d CreateChatCompletionRequestStop) CreateChatCompletionRequestStop { +func (o OptNilBool) Or(d bool) bool { if v, ok := o.Get(); ok { return v } return d } -// NewOptNilCreateClassificationRequestLogitBias returns new OptNilCreateClassificationRequestLogitBias with value set to v. -func NewOptNilCreateClassificationRequestLogitBias(v CreateClassificationRequestLogitBias) OptNilCreateClassificationRequestLogitBias { - return OptNilCreateClassificationRequestLogitBias{ +// NewOptNilCreateAnswerRequestStop returns new OptNilCreateAnswerRequestStop with value set to v. +func NewOptNilCreateAnswerRequestStop(v CreateAnswerRequestStop) OptNilCreateAnswerRequestStop { + return OptNilCreateAnswerRequestStop{ Value: v, Set: true, } } -// OptNilCreateClassificationRequestLogitBias is optional nullable CreateClassificationRequestLogitBias. -type OptNilCreateClassificationRequestLogitBias struct { - Value CreateClassificationRequestLogitBias +// OptNilCreateAnswerRequestStop is optional nullable CreateAnswerRequestStop. +type OptNilCreateAnswerRequestStop struct { + Value CreateAnswerRequestStop Set bool Null bool } -// IsSet returns true if OptNilCreateClassificationRequestLogitBias was set. -func (o OptNilCreateClassificationRequestLogitBias) IsSet() bool { return o.Set } +// IsSet returns true if OptNilCreateAnswerRequestStop was set. +func (o OptNilCreateAnswerRequestStop) IsSet() bool { return o.Set } // Reset unsets value. -func (o *OptNilCreateClassificationRequestLogitBias) Reset() { - var v CreateClassificationRequestLogitBias +func (o *OptNilCreateAnswerRequestStop) Reset() { + var v CreateAnswerRequestStop o.Value = v o.Set = false o.Null = false } // SetTo sets value to v. -func (o *OptNilCreateClassificationRequestLogitBias) SetTo(v CreateClassificationRequestLogitBias) { +func (o *OptNilCreateAnswerRequestStop) SetTo(v CreateAnswerRequestStop) { o.Set = true o.Null = false o.Value = v } // IsSet returns true if value is Null. -func (o OptNilCreateClassificationRequestLogitBias) IsNull() bool { return o.Null } +func (o OptNilCreateAnswerRequestStop) IsNull() bool { return o.Null } // SetNull sets value to null. -func (o *OptNilCreateClassificationRequestLogitBias) SetToNull() { +func (o *OptNilCreateAnswerRequestStop) SetToNull() { o.Set = true o.Null = true - var v CreateClassificationRequestLogitBias + var v CreateAnswerRequestStop o.Value = v } // Get returns value and boolean that denotes whether value was set. -func (o OptNilCreateClassificationRequestLogitBias) Get() (v CreateClassificationRequestLogitBias, ok bool) { +func (o OptNilCreateAnswerRequestStop) Get() (v CreateAnswerRequestStop, ok bool) { if o.Null { return v, false } @@ -4850,59 +4728,59 @@ func (o OptNilCreateClassificationRequestLogitBias) Get() (v CreateClassificatio } // Or returns value if set, or given parameter if does not. -func (o OptNilCreateClassificationRequestLogitBias) Or(d CreateClassificationRequestLogitBias) CreateClassificationRequestLogitBias { +func (o OptNilCreateAnswerRequestStop) Or(d CreateAnswerRequestStop) CreateAnswerRequestStop { if v, ok := o.Get(); ok { return v } return d } -// NewOptNilCreateCompletionRequestLogitBias returns new OptNilCreateCompletionRequestLogitBias with value set to v. -func NewOptNilCreateCompletionRequestLogitBias(v CreateCompletionRequestLogitBias) OptNilCreateCompletionRequestLogitBias { - return OptNilCreateCompletionRequestLogitBias{ +// NewOptNilCreateChatCompletionRequestStop returns new OptNilCreateChatCompletionRequestStop with value set to v. +func NewOptNilCreateChatCompletionRequestStop(v CreateChatCompletionRequestStop) OptNilCreateChatCompletionRequestStop { + return OptNilCreateChatCompletionRequestStop{ Value: v, Set: true, } } -// OptNilCreateCompletionRequestLogitBias is optional nullable CreateCompletionRequestLogitBias. -type OptNilCreateCompletionRequestLogitBias struct { - Value CreateCompletionRequestLogitBias +// OptNilCreateChatCompletionRequestStop is optional nullable CreateChatCompletionRequestStop. +type OptNilCreateChatCompletionRequestStop struct { + Value CreateChatCompletionRequestStop Set bool Null bool } -// IsSet returns true if OptNilCreateCompletionRequestLogitBias was set. -func (o OptNilCreateCompletionRequestLogitBias) IsSet() bool { return o.Set } +// IsSet returns true if OptNilCreateChatCompletionRequestStop was set. +func (o OptNilCreateChatCompletionRequestStop) IsSet() bool { return o.Set } // Reset unsets value. -func (o *OptNilCreateCompletionRequestLogitBias) Reset() { - var v CreateCompletionRequestLogitBias +func (o *OptNilCreateChatCompletionRequestStop) Reset() { + var v CreateChatCompletionRequestStop o.Value = v o.Set = false o.Null = false } // SetTo sets value to v. -func (o *OptNilCreateCompletionRequestLogitBias) SetTo(v CreateCompletionRequestLogitBias) { +func (o *OptNilCreateChatCompletionRequestStop) SetTo(v CreateChatCompletionRequestStop) { o.Set = true o.Null = false o.Value = v } // IsSet returns true if value is Null. -func (o OptNilCreateCompletionRequestLogitBias) IsNull() bool { return o.Null } +func (o OptNilCreateChatCompletionRequestStop) IsNull() bool { return o.Null } // SetNull sets value to null. -func (o *OptNilCreateCompletionRequestLogitBias) SetToNull() { +func (o *OptNilCreateChatCompletionRequestStop) SetToNull() { o.Set = true o.Null = true - var v CreateCompletionRequestLogitBias + var v CreateChatCompletionRequestStop o.Value = v } // Get returns value and boolean that denotes whether value was set. -func (o OptNilCreateCompletionRequestLogitBias) Get() (v CreateCompletionRequestLogitBias, ok bool) { +func (o OptNilCreateChatCompletionRequestStop) Get() (v CreateChatCompletionRequestStop, ok bool) { if o.Null { return v, false } @@ -4913,7 +4791,7 @@ func (o OptNilCreateCompletionRequestLogitBias) Get() (v CreateCompletionRequest } // Or returns value if set, or given parameter if does not. -func (o OptNilCreateCompletionRequestLogitBias) Or(d CreateCompletionRequestLogitBias) CreateCompletionRequestLogitBias { +func (o OptNilCreateChatCompletionRequestStop) Or(d CreateChatCompletionRequestStop) CreateChatCompletionRequestStop { if v, ok := o.Get(); ok { return v } diff --git a/examples/ex_telegram/oas_faker_gen.go b/examples/ex_telegram/oas_faker_gen.go index f43fb63ea..64c6196d7 100644 --- a/examples/ex_telegram/oas_faker_gen.go +++ b/examples/ex_telegram/oas_faker_gen.go @@ -3,10 +3,7 @@ package api import ( - "fmt" "net/url" - - "github.com/go-faster/jx" ) // SetFake set fake values. @@ -427,13 +424,6 @@ func (s *BotCommandScopeDefault) SetFake() { // SetFake set fake values. func (s *CallbackGame) SetFake() { - var ( - elem jx.Raw - m map[string]jx.Raw = s.init() - ) - for i := 0; i < 0; i++ { - m[fmt.Sprintf("fake%d", i)] = elem - } } // SetFake set fake values. @@ -2012,8 +2002,8 @@ func (s *InlineKeyboardButton) SetFake() { } } { - { - s.CallbackGame.SetFake() + { // Keep pointer nil to prevent infinite recursion. + s.CallbackGame = nil } } { @@ -4364,8 +4354,8 @@ func (s *Message) SetFake() { } } { - { - s.VoiceChatStarted.SetFake() + { // Keep pointer nil to prevent infinite recursion. + s.VoiceChatStarted = nil } } { @@ -4478,15 +4468,6 @@ func (s *OptBotCommandScope) SetFake() { s.SetTo(elem) } -// SetFake set fake values. -func (s *OptCallbackGame) SetFake() { - var elem CallbackGame - { - elem.SetFake() - } - s.SetTo(elem) -} - // SetFake set fake values. func (s *OptCallbackQuery) SetFake() { var elem CallbackQuery @@ -5153,15 +5134,6 @@ func (s *OptVoiceChatScheduled) SetFake() { s.SetTo(elem) } -// SetFake set fake values. -func (s *OptVoiceChatStarted) SetFake() { - var elem VoiceChatStarted - { - elem.SetFake() - } - s.SetTo(elem) -} - // SetFake set fake values. func (s *OptWebhookInfo) SetFake() { var elem WebhookInfo @@ -8357,13 +8329,6 @@ func (s *VoiceChatScheduled) SetFake() { // SetFake set fake values. func (s *VoiceChatStarted) SetFake() { - var ( - elem jx.Raw - m map[string]jx.Raw = s.init() - ) - for i := 0; i < 0; i++ { - m[fmt.Sprintf("fake%d", i)] = elem - } } // SetFake set fake values. diff --git a/examples/ex_telegram/oas_json_gen.go b/examples/ex_telegram/oas_json_gen.go index 5938a4c0d..6515cd7f2 100644 --- a/examples/ex_telegram/oas_json_gen.go +++ b/examples/ex_telegram/oas_json_gen.go @@ -2705,43 +2705,29 @@ func (s *BotCommandScopeDefault) UnmarshalJSON(data []byte) error { } // Encode implements json.Marshaler. -func (s CallbackGame) Encode(e *jx.Encoder) { +func (s *CallbackGame) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } -// encodeFields implements json.Marshaler. -func (s CallbackGame) encodeFields(e *jx.Encoder) { - for k, elem := range s { - e.FieldStart(k) - - if len(elem) != 0 { - e.Raw(elem) - } - } +// encodeFields encodes fields. +func (s *CallbackGame) encodeFields(e *jx.Encoder) { } +var jsonFieldsNameOfCallbackGame = [0]string{} + // Decode decodes CallbackGame from json. func (s *CallbackGame) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode CallbackGame to nil") } - m := s.init() + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { - var elem jx.Raw - if err := func() error { - v, err := d.RawAppend(nil) - elem = jx.Raw(v) - if err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrapf(err, "decode field %q", k) - } - m[string(k)] = elem - return nil + switch string(k) { + default: + return d.Skip() + } }); err != nil { return errors.Wrap(err, "decode CallbackGame") } @@ -2750,7 +2736,7 @@ func (s *CallbackGame) Decode(d *jx.Decoder) error { } // MarshalJSON implements stdjson.Marshaler. -func (s CallbackGame) MarshalJSON() ([]byte, error) { +func (s *CallbackGame) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil @@ -11567,7 +11553,7 @@ func (s *InlineKeyboardButton) encodeFields(e *jx.Encoder) { } } { - if s.CallbackGame.Set { + if s.CallbackGame != nil { e.FieldStart("callback_game") s.CallbackGame.Encode(e) } @@ -11664,10 +11650,12 @@ func (s *InlineKeyboardButton) Decode(d *jx.Decoder) error { } case "callback_game": if err := func() error { - s.CallbackGame.Reset() - if err := s.CallbackGame.Decode(d); err != nil { + s.CallbackGame = nil + var elem CallbackGame + if err := elem.Decode(d); err != nil { return err } + s.CallbackGame = &elem return nil }(); err != nil { return errors.Wrap(err, "decode field \"callback_game\"") @@ -23027,7 +23015,7 @@ func (s *Message) encodeFields(e *jx.Encoder) { } } { - if s.VoiceChatStarted.Set { + if s.VoiceChatStarted != nil { e.FieldStart("voice_chat_started") s.VoiceChatStarted.Encode(e) } @@ -23707,10 +23695,12 @@ func (s *Message) Decode(d *jx.Decoder) error { } case "voice_chat_started": if err := func() error { - s.VoiceChatStarted.Reset() - if err := s.VoiceChatStarted.Decode(d); err != nil { + s.VoiceChatStarted = nil + var elem VoiceChatStarted + if err := elem.Decode(d); err != nil { return err } + s.VoiceChatStarted = &elem return nil }(); err != nil { return errors.Wrap(err, "decode field \"voice_chat_started\"") @@ -24380,40 +24370,6 @@ func (s *OptBotCommandScope) UnmarshalJSON(data []byte) error { return s.Decode(d) } -// Encode encodes CallbackGame as json. -func (o OptCallbackGame) Encode(e *jx.Encoder) { - if !o.Set { - return - } - o.Value.Encode(e) -} - -// Decode decodes CallbackGame from json. -func (o *OptCallbackGame) Decode(d *jx.Decoder) error { - if o == nil { - return errors.New("invalid: unable to decode OptCallbackGame to nil") - } - o.Set = true - o.Value = make(CallbackGame) - if err := o.Value.Decode(d); err != nil { - return err - } - return nil -} - -// MarshalJSON implements stdjson.Marshaler. -func (s OptCallbackGame) MarshalJSON() ([]byte, error) { - e := jx.Encoder{} - s.Encode(&e) - return e.Bytes(), nil -} - -// UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptCallbackGame) UnmarshalJSON(data []byte) error { - d := jx.DecodeBytes(data) - return s.Decode(d) -} - // Encode encodes CallbackQuery as json. func (o OptCallbackQuery) Encode(e *jx.Encoder) { if !o.Set { @@ -26866,40 +26822,6 @@ func (s *OptVoiceChatScheduled) UnmarshalJSON(data []byte) error { return s.Decode(d) } -// Encode encodes VoiceChatStarted as json. -func (o OptVoiceChatStarted) Encode(e *jx.Encoder) { - if !o.Set { - return - } - o.Value.Encode(e) -} - -// Decode decodes VoiceChatStarted from json. -func (o *OptVoiceChatStarted) Decode(d *jx.Decoder) error { - if o == nil { - return errors.New("invalid: unable to decode OptVoiceChatStarted to nil") - } - o.Set = true - o.Value = make(VoiceChatStarted) - if err := o.Value.Decode(d); err != nil { - return err - } - return nil -} - -// MarshalJSON implements stdjson.Marshaler. -func (s OptVoiceChatStarted) MarshalJSON() ([]byte, error) { - e := jx.Encoder{} - s.Encode(&e) - return e.Bytes(), nil -} - -// UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptVoiceChatStarted) UnmarshalJSON(data []byte) error { - d := jx.DecodeBytes(data) - return s.Decode(d) -} - // Encode encodes WebhookInfo as json. func (o OptWebhookInfo) Encode(e *jx.Encoder) { if !o.Set { @@ -45570,43 +45492,29 @@ func (s *VoiceChatScheduled) UnmarshalJSON(data []byte) error { } // Encode implements json.Marshaler. -func (s VoiceChatStarted) Encode(e *jx.Encoder) { +func (s *VoiceChatStarted) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } -// encodeFields implements json.Marshaler. -func (s VoiceChatStarted) encodeFields(e *jx.Encoder) { - for k, elem := range s { - e.FieldStart(k) - - if len(elem) != 0 { - e.Raw(elem) - } - } +// encodeFields encodes fields. +func (s *VoiceChatStarted) encodeFields(e *jx.Encoder) { } +var jsonFieldsNameOfVoiceChatStarted = [0]string{} + // Decode decodes VoiceChatStarted from json. func (s *VoiceChatStarted) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode VoiceChatStarted to nil") } - m := s.init() + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { - var elem jx.Raw - if err := func() error { - v, err := d.RawAppend(nil) - elem = jx.Raw(v) - if err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrapf(err, "decode field %q", k) - } - m[string(k)] = elem - return nil + switch string(k) { + default: + return d.Skip() + } }); err != nil { return errors.Wrap(err, "decode VoiceChatStarted") } @@ -45615,7 +45523,7 @@ func (s *VoiceChatStarted) Decode(d *jx.Decoder) error { } // MarshalJSON implements stdjson.Marshaler. -func (s VoiceChatStarted) MarshalJSON() ([]byte, error) { +func (s *VoiceChatStarted) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil diff --git a/examples/ex_telegram/oas_schemas_gen.go b/examples/ex_telegram/oas_schemas_gen.go index dfc55fc00..32f2c62a3 100644 --- a/examples/ex_telegram/oas_schemas_gen.go +++ b/examples/ex_telegram/oas_schemas_gen.go @@ -7,7 +7,6 @@ import ( "net/url" "github.com/go-faster/errors" - "github.com/go-faster/jx" ) func (s *ErrorStatusCode) Error() string { @@ -1112,16 +1111,7 @@ func (s *BotCommandScopeDefault) SetType(val string) { // A placeholder, currently holds no information. Use BotFather to set up your game. // Ref: #/components/schemas/CallbackGame -type CallbackGame map[string]jx.Raw - -func (s *CallbackGame) init() CallbackGame { - m := *s - if m == nil { - m = map[string]jx.Raw{} - *s = m - } - return m -} +type CallbackGame struct{} // This object represents an incoming callback query from a callback button in an inline keyboard. If // the button that originated the query was attached to a message sent by the bot, the field message @@ -4976,8 +4966,8 @@ type InlineKeyboardButton struct { // current chat's input field. Can be empty, in which case only the bot's username will be inserted. // This offers a quick way for the user to open your bot in inline mode in the same chat – good for // selecting something from multiple options. - SwitchInlineQueryCurrentChat OptString `json:"switch_inline_query_current_chat"` - CallbackGame OptCallbackGame `json:"callback_game"` + SwitchInlineQueryCurrentChat OptString `json:"switch_inline_query_current_chat"` + CallbackGame *CallbackGame `json:"callback_game"` // Specify True, to send a Pay button.NOTE: This type of button must always be the first button in // the first row and can only be used in invoice messages. Pay OptBool `json:"pay"` @@ -5014,7 +5004,7 @@ func (s *InlineKeyboardButton) GetSwitchInlineQueryCurrentChat() OptString { } // GetCallbackGame returns the value of CallbackGame. -func (s *InlineKeyboardButton) GetCallbackGame() OptCallbackGame { +func (s *InlineKeyboardButton) GetCallbackGame() *CallbackGame { return s.CallbackGame } @@ -5054,7 +5044,7 @@ func (s *InlineKeyboardButton) SetSwitchInlineQueryCurrentChat(val OptString) { } // SetCallbackGame sets the value of CallbackGame. -func (s *InlineKeyboardButton) SetCallbackGame(val OptCallbackGame) { +func (s *InlineKeyboardButton) SetCallbackGame(val *CallbackGame) { s.CallbackGame = val } @@ -10430,7 +10420,7 @@ type Message struct { PassportData OptPassportData `json:"passport_data"` ProximityAlertTriggered OptProximityAlertTriggered `json:"proximity_alert_triggered"` VoiceChatScheduled OptVoiceChatScheduled `json:"voice_chat_scheduled"` - VoiceChatStarted OptVoiceChatStarted `json:"voice_chat_started"` + VoiceChatStarted *VoiceChatStarted `json:"voice_chat_started"` VoiceChatEnded OptVoiceChatEnded `json:"voice_chat_ended"` VoiceChatParticipantsInvited OptVoiceChatParticipantsInvited `json:"voice_chat_participants_invited"` ReplyMarkup OptInlineKeyboardMarkup `json:"reply_markup"` @@ -10707,7 +10697,7 @@ func (s *Message) GetVoiceChatScheduled() OptVoiceChatScheduled { } // GetVoiceChatStarted returns the value of VoiceChatStarted. -func (s *Message) GetVoiceChatStarted() OptVoiceChatStarted { +func (s *Message) GetVoiceChatStarted() *VoiceChatStarted { return s.VoiceChatStarted } @@ -10997,7 +10987,7 @@ func (s *Message) SetVoiceChatScheduled(val OptVoiceChatScheduled) { } // SetVoiceChatStarted sets the value of VoiceChatStarted. -func (s *Message) SetVoiceChatStarted(val OptVoiceChatStarted) { +func (s *Message) SetVoiceChatStarted(val *VoiceChatStarted) { s.VoiceChatStarted = val } @@ -11454,52 +11444,6 @@ func (o OptBotCommandScope) Or(d BotCommandScope) BotCommandScope { return d } -// NewOptCallbackGame returns new OptCallbackGame with value set to v. -func NewOptCallbackGame(v CallbackGame) OptCallbackGame { - return OptCallbackGame{ - Value: v, - Set: true, - } -} - -// OptCallbackGame is optional CallbackGame. -type OptCallbackGame struct { - Value CallbackGame - Set bool -} - -// IsSet returns true if OptCallbackGame was set. -func (o OptCallbackGame) IsSet() bool { return o.Set } - -// Reset unsets value. -func (o *OptCallbackGame) Reset() { - var v CallbackGame - o.Value = v - o.Set = false -} - -// SetTo sets value to v. -func (o *OptCallbackGame) SetTo(v CallbackGame) { - o.Set = true - o.Value = v -} - -// Get returns value and boolean that denotes whether value was set. -func (o OptCallbackGame) Get() (v CallbackGame, ok bool) { - if !o.Set { - return v, false - } - return o.Value, true -} - -// Or returns value if set, or given parameter if does not. -func (o OptCallbackGame) Or(d CallbackGame) CallbackGame { - if v, ok := o.Get(); ok { - return v - } - return d -} - // NewOptCallbackQuery returns new OptCallbackQuery with value set to v. func NewOptCallbackQuery(v CallbackQuery) OptCallbackQuery { return OptCallbackQuery{ @@ -14904,52 +14848,6 @@ func (o OptVoiceChatScheduled) Or(d VoiceChatScheduled) VoiceChatScheduled { return d } -// NewOptVoiceChatStarted returns new OptVoiceChatStarted with value set to v. -func NewOptVoiceChatStarted(v VoiceChatStarted) OptVoiceChatStarted { - return OptVoiceChatStarted{ - Value: v, - Set: true, - } -} - -// OptVoiceChatStarted is optional VoiceChatStarted. -type OptVoiceChatStarted struct { - Value VoiceChatStarted - Set bool -} - -// IsSet returns true if OptVoiceChatStarted was set. -func (o OptVoiceChatStarted) IsSet() bool { return o.Set } - -// Reset unsets value. -func (o *OptVoiceChatStarted) Reset() { - var v VoiceChatStarted - o.Value = v - o.Set = false -} - -// SetTo sets value to v. -func (o *OptVoiceChatStarted) SetTo(v VoiceChatStarted) { - o.Set = true - o.Value = v -} - -// Get returns value and boolean that denotes whether value was set. -func (o OptVoiceChatStarted) Get() (v VoiceChatStarted, ok bool) { - if !o.Set { - return v, false - } - return o.Value, true -} - -// Or returns value if set, or given parameter if does not. -func (o OptVoiceChatStarted) Or(d VoiceChatStarted) VoiceChatStarted { - if v, ok := o.Get(); ok { - return v - } - return d -} - // NewOptWebhookInfo returns new OptWebhookInfo with value set to v. func NewOptWebhookInfo(v WebhookInfo) OptWebhookInfo { return OptWebhookInfo{ @@ -23975,16 +23873,7 @@ func (s *VoiceChatScheduled) SetStartDate(val int) { // This object represents a service message about a voice chat started in the chat. Currently holds // no information. // Ref: #/components/schemas/VoiceChatStarted -type VoiceChatStarted map[string]jx.Raw - -func (s *VoiceChatStarted) init() VoiceChatStarted { - m := *s - if m == nil { - m = map[string]jx.Raw{} - *s = m - } - return m -} +type VoiceChatStarted struct{} // Contains information about the current status of a webhook. // Ref: #/components/schemas/WebhookInfo diff --git a/examples/ex_telegram/oas_test_examples_gen_test.go b/examples/ex_telegram/oas_test_examples_gen_test.go index eded0553b..12d905c5f 100644 --- a/examples/ex_telegram/oas_test_examples_gen_test.go +++ b/examples/ex_telegram/oas_test_examples_gen_test.go @@ -241,7 +241,6 @@ func TestBotCommandScopeDefault_EncodeDecode(t *testing.T) { } func TestCallbackGame_EncodeDecode(t *testing.T) { var typ CallbackGame - typ = make(CallbackGame) typ.SetFake() e := jx.Encoder{} @@ -250,7 +249,6 @@ func TestCallbackGame_EncodeDecode(t *testing.T) { require.True(t, std.Valid(data), "Encoded: %s", data) var typ2 CallbackGame - typ2 = make(CallbackGame) require.NoError(t, typ2.Decode(jx.DecodeBytes(data))) } func TestCallbackQuery_EncodeDecode(t *testing.T) { @@ -3003,7 +3001,6 @@ func TestVoiceChatScheduled_EncodeDecode(t *testing.T) { } func TestVoiceChatStarted_EncodeDecode(t *testing.T) { var typ VoiceChatStarted - typ = make(VoiceChatStarted) typ.SetFake() e := jx.Encoder{} @@ -3012,7 +3009,6 @@ func TestVoiceChatStarted_EncodeDecode(t *testing.T) { require.True(t, std.Valid(data), "Encoded: %s", data) var typ2 VoiceChatStarted - typ2 = make(VoiceChatStarted) require.NoError(t, typ2.Decode(jx.DecodeBytes(data))) } func TestWebhookInfo_EncodeDecode(t *testing.T) { diff --git a/examples/ex_test_format/oas_client_gen.go b/examples/ex_test_format/oas_client_gen.go index 68473d6ff..c51b65a46 100644 --- a/examples/ex_test_format/oas_client_gen.go +++ b/examples/ex_test_format/oas_client_gen.go @@ -62,7 +62,7 @@ type Invoker interface { // TestRequestEmptyStruct invokes test_request_EmptyStruct operation. // // POST /test_request_EmptyStruct - TestRequestEmptyStruct(ctx context.Context, request OptTestRequestEmptyStructReq) (*Error, error) + TestRequestEmptyStruct(ctx context.Context, request *TestRequestEmptyStructReq) (*Error, error) // TestRequestFormatTest invokes test_request_FormatTest operation. // // POST /test_request_FormatTest @@ -602,7 +602,7 @@ type Invoker interface { // TestRequestRequiredEmptyStruct invokes test_request_required_EmptyStruct operation. // // POST /test_request_required_EmptyStruct - TestRequestRequiredEmptyStruct(ctx context.Context, request TestRequestRequiredEmptyStructReq) (*Error, error) + TestRequestRequiredEmptyStruct(ctx context.Context, request *TestRequestRequiredEmptyStructReq) (*Error, error) // TestRequestRequiredFormatTest invokes test_request_required_FormatTest operation. // // POST /test_request_required_FormatTest @@ -2774,7 +2774,7 @@ type Invoker interface { // TestResponseEmptyStruct invokes test_response_EmptyStruct operation. // // POST /test_response_EmptyStruct - TestResponseEmptyStruct(ctx context.Context, request string) (TestResponseEmptyStructOK, error) + TestResponseEmptyStruct(ctx context.Context, request string) error // TestResponseFormatTest invokes test_response_FormatTest operation. // // POST /test_response_FormatTest @@ -6775,12 +6775,12 @@ func (c *Client) sendTestRequestBooleanNullableArrayArray(ctx context.Context, r // TestRequestEmptyStruct invokes test_request_EmptyStruct operation. // // POST /test_request_EmptyStruct -func (c *Client) TestRequestEmptyStruct(ctx context.Context, request OptTestRequestEmptyStructReq) (*Error, error) { +func (c *Client) TestRequestEmptyStruct(ctx context.Context, request *TestRequestEmptyStructReq) (*Error, error) { res, err := c.sendTestRequestEmptyStruct(ctx, request) return res, err } -func (c *Client) sendTestRequestEmptyStruct(ctx context.Context, request OptTestRequestEmptyStructReq) (res *Error, err error) { +func (c *Client) sendTestRequestEmptyStruct(ctx context.Context, request *TestRequestEmptyStructReq) (res *Error, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("test_request_EmptyStruct"), semconv.HTTPMethodKey.String("POST"), @@ -16630,12 +16630,12 @@ func (c *Client) sendTestRequestRequiredBooleanNullableArrayArray(ctx context.Co // TestRequestRequiredEmptyStruct invokes test_request_required_EmptyStruct operation. // // POST /test_request_required_EmptyStruct -func (c *Client) TestRequestRequiredEmptyStruct(ctx context.Context, request TestRequestRequiredEmptyStructReq) (*Error, error) { +func (c *Client) TestRequestRequiredEmptyStruct(ctx context.Context, request *TestRequestRequiredEmptyStructReq) (*Error, error) { res, err := c.sendTestRequestRequiredEmptyStruct(ctx, request) return res, err } -func (c *Client) sendTestRequestRequiredEmptyStruct(ctx context.Context, request TestRequestRequiredEmptyStructReq) (res *Error, err error) { +func (c *Client) sendTestRequestRequiredEmptyStruct(ctx context.Context, request *TestRequestRequiredEmptyStructReq) (res *Error, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("test_request_required_EmptyStruct"), semconv.HTTPMethodKey.String("POST"), @@ -56269,12 +56269,12 @@ func (c *Client) sendTestResponseBooleanNullableArrayArray(ctx context.Context, // TestResponseEmptyStruct invokes test_response_EmptyStruct operation. // // POST /test_response_EmptyStruct -func (c *Client) TestResponseEmptyStruct(ctx context.Context, request string) (TestResponseEmptyStructOK, error) { - res, err := c.sendTestResponseEmptyStruct(ctx, request) - return res, err +func (c *Client) TestResponseEmptyStruct(ctx context.Context, request string) error { + _, err := c.sendTestResponseEmptyStruct(ctx, request) + return err } -func (c *Client) sendTestResponseEmptyStruct(ctx context.Context, request string) (res TestResponseEmptyStructOK, err error) { +func (c *Client) sendTestResponseEmptyStruct(ctx context.Context, request string) (res *TestResponseEmptyStructOK, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("test_response_EmptyStruct"), semconv.HTTPMethodKey.String("POST"), diff --git a/examples/ex_test_format/oas_faker_gen.go b/examples/ex_test_format/oas_faker_gen.go index ca98b154a..2b1af2cc9 100644 --- a/examples/ex_test_format/oas_faker_gen.go +++ b/examples/ex_test_format/oas_faker_gen.go @@ -3,7 +3,6 @@ package api import ( - "fmt" "net" "net/netip" "net/url" @@ -814,15 +813,6 @@ func (s *OptStringUnixSeconds) SetFake() { s.SetTo(elem) } -// SetFake set fake values. -func (s *OptTestRequestEmptyStructReq) SetFake() { - var elem TestRequestEmptyStructReq - { - elem.SetFake() - } - s.SetTo(elem) -} - // SetFake set fake values. func (s *OptTestRequestFormatTestReq) SetFake() { var elem TestRequestFormatTestReq @@ -942,13 +932,6 @@ func (s *OptUnixSeconds) SetFake() { // SetFake set fake values. func (s *TestRequestEmptyStructReq) SetFake() { - var ( - elem jx.Raw - m map[string]jx.Raw = s.init() - ) - for i := 0; i < 0; i++ { - m[fmt.Sprintf("fake%d", i)] = elem - } } // SetFake set fake values. @@ -5061,13 +5044,6 @@ func (s *TestRequestFormatTestReq) SetFake() { // SetFake set fake values. func (s *TestRequestRequiredEmptyStructReq) SetFake() { - var ( - elem jx.Raw - m map[string]jx.Raw = s.init() - ) - for i := 0; i < 0; i++ { - m[fmt.Sprintf("fake%d", i)] = elem - } } // SetFake set fake values. @@ -9180,13 +9156,6 @@ func (s *TestRequestRequiredFormatTestReq) SetFake() { // SetFake set fake values. func (s *TestResponseEmptyStructOK) SetFake() { - var ( - elem jx.Raw - m map[string]jx.Raw = s.init() - ) - for i := 0; i < 0; i++ { - m[fmt.Sprintf("fake%d", i)] = elem - } } // SetFake set fake values. diff --git a/examples/ex_test_format/oas_handlers_gen.go b/examples/ex_test_format/oas_handlers_gen.go index a4662d755..c25382659 100644 --- a/examples/ex_test_format/oas_handlers_gen.go +++ b/examples/ex_test_format/oas_handlers_gen.go @@ -1431,7 +1431,7 @@ func (s *Server) handleTestRequestEmptyStructRequest(args [0]string, argsEscaped } type ( - Request = OptTestRequestEmptyStructReq + Request = *TestRequestEmptyStructReq Params = struct{} Response = *Error ) @@ -16281,7 +16281,7 @@ func (s *Server) handleTestRequestRequiredEmptyStructRequest(args [0]string, arg } type ( - Request = TestRequestRequiredEmptyStructReq + Request = *TestRequestRequiredEmptyStructReq Params = struct{} Response = *Error ) @@ -75998,7 +75998,7 @@ func (s *Server) handleTestResponseEmptyStructRequest(args [0]string, argsEscape } }() - var response TestResponseEmptyStructOK + var response *TestResponseEmptyStructOK if m := s.cfg.Middleware; m != nil { mreq := middleware.Request{ Context: ctx, @@ -76013,7 +76013,7 @@ func (s *Server) handleTestResponseEmptyStructRequest(args [0]string, argsEscape type ( Request = string Params = struct{} - Response = TestResponseEmptyStructOK + Response = *TestResponseEmptyStructOK ) response, err = middleware.HookMiddleware[ Request, @@ -76024,12 +76024,12 @@ func (s *Server) handleTestResponseEmptyStructRequest(args [0]string, argsEscape mreq, nil, func(ctx context.Context, request Request, params Params) (response Response, err error) { - response, err = s.h.TestResponseEmptyStruct(ctx, request) + err = s.h.TestResponseEmptyStruct(ctx, request) return response, err }, ) } else { - response, err = s.h.TestResponseEmptyStruct(ctx, request) + err = s.h.TestResponseEmptyStruct(ctx, request) } if err != nil { defer recordError("Internal", err) diff --git a/examples/ex_test_format/oas_json_gen.go b/examples/ex_test_format/oas_json_gen.go index 8ccde0870..475098cf6 100644 --- a/examples/ex_test_format/oas_json_gen.go +++ b/examples/ex_test_format/oas_json_gen.go @@ -5570,40 +5570,6 @@ func (s *OptStringUnixSeconds) UnmarshalJSON(data []byte) error { return s.Decode(d, json.DecodeStringUnixSeconds) } -// Encode encodes TestRequestEmptyStructReq as json. -func (o OptTestRequestEmptyStructReq) Encode(e *jx.Encoder) { - if !o.Set { - return - } - o.Value.Encode(e) -} - -// Decode decodes TestRequestEmptyStructReq from json. -func (o *OptTestRequestEmptyStructReq) Decode(d *jx.Decoder) error { - if o == nil { - return errors.New("invalid: unable to decode OptTestRequestEmptyStructReq to nil") - } - o.Set = true - o.Value = make(TestRequestEmptyStructReq) - if err := o.Value.Decode(d); err != nil { - return err - } - return nil -} - -// MarshalJSON implements stdjson.Marshaler. -func (s OptTestRequestEmptyStructReq) MarshalJSON() ([]byte, error) { - e := jx.Encoder{} - s.Encode(&e) - return e.Bytes(), nil -} - -// UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptTestRequestEmptyStructReq) UnmarshalJSON(data []byte) error { - d := jx.DecodeBytes(data) - return s.Decode(d) -} - // Encode encodes TestRequestFormatTestReq as json. func (o OptTestRequestFormatTestReq) Encode(e *jx.Encoder) { if !o.Set { @@ -6058,43 +6024,29 @@ func (s *OptUnixSeconds) UnmarshalJSON(data []byte) error { } // Encode implements json.Marshaler. -func (s TestRequestEmptyStructReq) Encode(e *jx.Encoder) { +func (s *TestRequestEmptyStructReq) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } -// encodeFields implements json.Marshaler. -func (s TestRequestEmptyStructReq) encodeFields(e *jx.Encoder) { - for k, elem := range s { - e.FieldStart(k) - - if len(elem) != 0 { - e.Raw(elem) - } - } +// encodeFields encodes fields. +func (s *TestRequestEmptyStructReq) encodeFields(e *jx.Encoder) { } +var jsonFieldsNameOfTestRequestEmptyStructReq = [0]string{} + // Decode decodes TestRequestEmptyStructReq from json. func (s *TestRequestEmptyStructReq) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode TestRequestEmptyStructReq to nil") } - m := s.init() + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { - var elem jx.Raw - if err := func() error { - v, err := d.RawAppend(nil) - elem = jx.Raw(v) - if err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrapf(err, "decode field %q", k) - } - m[string(k)] = elem - return nil + switch string(k) { + default: + return d.Skip() + } }); err != nil { return errors.Wrap(err, "decode TestRequestEmptyStructReq") } @@ -6103,7 +6055,7 @@ func (s *TestRequestEmptyStructReq) Decode(d *jx.Decoder) error { } // MarshalJSON implements stdjson.Marshaler. -func (s TestRequestEmptyStructReq) MarshalJSON() ([]byte, error) { +func (s *TestRequestEmptyStructReq) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil @@ -16273,43 +16225,29 @@ func (s *TestRequestFormatTestReq) UnmarshalJSON(data []byte) error { } // Encode implements json.Marshaler. -func (s TestRequestRequiredEmptyStructReq) Encode(e *jx.Encoder) { +func (s *TestRequestRequiredEmptyStructReq) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } -// encodeFields implements json.Marshaler. -func (s TestRequestRequiredEmptyStructReq) encodeFields(e *jx.Encoder) { - for k, elem := range s { - e.FieldStart(k) - - if len(elem) != 0 { - e.Raw(elem) - } - } +// encodeFields encodes fields. +func (s *TestRequestRequiredEmptyStructReq) encodeFields(e *jx.Encoder) { } +var jsonFieldsNameOfTestRequestRequiredEmptyStructReq = [0]string{} + // Decode decodes TestRequestRequiredEmptyStructReq from json. func (s *TestRequestRequiredEmptyStructReq) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode TestRequestRequiredEmptyStructReq to nil") } - m := s.init() + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { - var elem jx.Raw - if err := func() error { - v, err := d.RawAppend(nil) - elem = jx.Raw(v) - if err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrapf(err, "decode field %q", k) - } - m[string(k)] = elem - return nil + switch string(k) { + default: + return d.Skip() + } }); err != nil { return errors.Wrap(err, "decode TestRequestRequiredEmptyStructReq") } @@ -16318,7 +16256,7 @@ func (s *TestRequestRequiredEmptyStructReq) Decode(d *jx.Decoder) error { } // MarshalJSON implements stdjson.Marshaler. -func (s TestRequestRequiredEmptyStructReq) MarshalJSON() ([]byte, error) { +func (s *TestRequestRequiredEmptyStructReq) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil @@ -26488,43 +26426,29 @@ func (s *TestRequestRequiredFormatTestReq) UnmarshalJSON(data []byte) error { } // Encode implements json.Marshaler. -func (s TestResponseEmptyStructOK) Encode(e *jx.Encoder) { +func (s *TestResponseEmptyStructOK) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } -// encodeFields implements json.Marshaler. -func (s TestResponseEmptyStructOK) encodeFields(e *jx.Encoder) { - for k, elem := range s { - e.FieldStart(k) - - if len(elem) != 0 { - e.Raw(elem) - } - } +// encodeFields encodes fields. +func (s *TestResponseEmptyStructOK) encodeFields(e *jx.Encoder) { } +var jsonFieldsNameOfTestResponseEmptyStructOK = [0]string{} + // Decode decodes TestResponseEmptyStructOK from json. func (s *TestResponseEmptyStructOK) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode TestResponseEmptyStructOK to nil") } - m := s.init() + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { - var elem jx.Raw - if err := func() error { - v, err := d.RawAppend(nil) - elem = jx.Raw(v) - if err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrapf(err, "decode field %q", k) - } - m[string(k)] = elem - return nil + switch string(k) { + default: + return d.Skip() + } }); err != nil { return errors.Wrap(err, "decode TestResponseEmptyStructOK") } @@ -26533,7 +26457,7 @@ func (s *TestResponseEmptyStructOK) Decode(d *jx.Decoder) error { } // MarshalJSON implements stdjson.Marshaler. -func (s TestResponseEmptyStructOK) MarshalJSON() ([]byte, error) { +func (s *TestResponseEmptyStructOK) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil diff --git a/examples/ex_test_format/oas_request_decoders_gen.go b/examples/ex_test_format/oas_request_decoders_gen.go index 6d0a5498f..8c514119f 100644 --- a/examples/ex_test_format/oas_request_decoders_gen.go +++ b/examples/ex_test_format/oas_request_decoders_gen.go @@ -650,7 +650,7 @@ func (s *Server) decodeTestRequestBooleanNullableArrayArrayRequest(r *http.Reque } func (s *Server) decodeTestRequestEmptyStructRequest(r *http.Request) ( - req OptTestRequestEmptyStructReq, + req *TestRequestEmptyStructReq, close func() error, rerr error, ) { @@ -692,12 +692,14 @@ func (s *Server) decodeTestRequestEmptyStructRequest(r *http.Request) ( d := jx.DecodeBytes(buf) - var request OptTestRequestEmptyStructReq + var request *TestRequestEmptyStructReq if err := func() error { - request.Reset() - if err := request.Decode(d); err != nil { + request = nil + var elem TestRequestEmptyStructReq + if err := elem.Decode(d); err != nil { return err } + request = &elem if err := d.Skip(); err != io.EOF { return errors.New("unexpected trailing data") } @@ -12098,7 +12100,7 @@ func (s *Server) decodeTestRequestRequiredBooleanNullableArrayArrayRequest(r *ht } func (s *Server) decodeTestRequestRequiredEmptyStructRequest(r *http.Request) ( - req TestRequestRequiredEmptyStructReq, + req *TestRequestRequiredEmptyStructReq, close func() error, rerr error, ) { @@ -12154,7 +12156,7 @@ func (s *Server) decodeTestRequestRequiredEmptyStructRequest(r *http.Request) ( } return req, close, err } - return request, close, nil + return &request, close, nil default: return req, close, validate.InvalidContentType(ct) } diff --git a/examples/ex_test_format/oas_request_encoders_gen.go b/examples/ex_test_format/oas_request_encoders_gen.go index f7314a4f9..b7c012b37 100644 --- a/examples/ex_test_format/oas_request_encoders_gen.go +++ b/examples/ex_test_format/oas_request_encoders_gen.go @@ -176,17 +176,13 @@ func encodeTestRequestBooleanNullableArrayArrayRequest( } func encodeTestRequestEmptyStructRequest( - req OptTestRequestEmptyStructReq, + req *TestRequestEmptyStructReq, r *http.Request, ) error { const contentType = "application/json" - if !req.Set { - // Keep request with empty body if value is not set. - return nil - } e := new(jx.Encoder) { - if req.Set { + if req != nil { req.Encode(e) } } @@ -3032,7 +3028,7 @@ func encodeTestRequestRequiredBooleanNullableArrayArrayRequest( } func encodeTestRequestRequiredEmptyStructRequest( - req TestRequestRequiredEmptyStructReq, + req *TestRequestRequiredEmptyStructReq, r *http.Request, ) error { const contentType = "application/json" diff --git a/examples/ex_test_format/oas_response_decoders_gen.go b/examples/ex_test_format/oas_response_decoders_gen.go index bed2a75e8..8246864c5 100644 --- a/examples/ex_test_format/oas_response_decoders_gen.go +++ b/examples/ex_test_format/oas_response_decoders_gen.go @@ -28273,7 +28273,7 @@ func decodeTestResponseBooleanNullableArrayArrayResponse(resp *http.Response) (r return res, validate.UnexpectedStatusCode(resp.StatusCode) } -func decodeTestResponseEmptyStructResponse(resp *http.Response) (res TestResponseEmptyStructOK, _ error) { +func decodeTestResponseEmptyStructResponse(resp *http.Response) (res *TestResponseEmptyStructOK, _ error) { switch resp.StatusCode { case 200: // Code 200. @@ -28306,7 +28306,7 @@ func decodeTestResponseEmptyStructResponse(resp *http.Response) (res TestRespons } return res, err } - return response, nil + return &response, nil default: return res, validate.InvalidContentType(ct) } diff --git a/examples/ex_test_format/oas_response_encoders_gen.go b/examples/ex_test_format/oas_response_encoders_gen.go index adfe8257a..465f812de 100644 --- a/examples/ex_test_format/oas_response_encoders_gen.go +++ b/examples/ex_test_format/oas_response_encoders_gen.go @@ -9648,7 +9648,7 @@ func encodeTestResponseBooleanNullableArrayArrayResponse(response [][]NilBool, w return nil } -func encodeTestResponseEmptyStructResponse(response TestResponseEmptyStructOK, w http.ResponseWriter, span trace.Span) error { +func encodeTestResponseEmptyStructResponse(response *TestResponseEmptyStructOK, w http.ResponseWriter, span trace.Span) error { w.Header().Set("Content-Type", "application/json; charset=utf-8") w.WriteHeader(200) span.SetStatus(codes.Ok, http.StatusText(200)) diff --git a/examples/ex_test_format/oas_schemas_gen.go b/examples/ex_test_format/oas_schemas_gen.go index a162da6a5..dfc325aa0 100644 --- a/examples/ex_test_format/oas_schemas_gen.go +++ b/examples/ex_test_format/oas_schemas_gen.go @@ -6371,52 +6371,6 @@ func (o OptStringUnixSeconds) Or(d time.Time) time.Time { return d } -// NewOptTestRequestEmptyStructReq returns new OptTestRequestEmptyStructReq with value set to v. -func NewOptTestRequestEmptyStructReq(v TestRequestEmptyStructReq) OptTestRequestEmptyStructReq { - return OptTestRequestEmptyStructReq{ - Value: v, - Set: true, - } -} - -// OptTestRequestEmptyStructReq is optional TestRequestEmptyStructReq. -type OptTestRequestEmptyStructReq struct { - Value TestRequestEmptyStructReq - Set bool -} - -// IsSet returns true if OptTestRequestEmptyStructReq was set. -func (o OptTestRequestEmptyStructReq) IsSet() bool { return o.Set } - -// Reset unsets value. -func (o *OptTestRequestEmptyStructReq) Reset() { - var v TestRequestEmptyStructReq - o.Value = v - o.Set = false -} - -// SetTo sets value to v. -func (o *OptTestRequestEmptyStructReq) SetTo(v TestRequestEmptyStructReq) { - o.Set = true - o.Value = v -} - -// Get returns value and boolean that denotes whether value was set. -func (o OptTestRequestEmptyStructReq) Get() (v TestRequestEmptyStructReq, ok bool) { - if !o.Set { - return v, false - } - return o.Value, true -} - -// Or returns value if set, or given parameter if does not. -func (o OptTestRequestEmptyStructReq) Or(d TestRequestEmptyStructReq) TestRequestEmptyStructReq { - if v, ok := o.Get(); ok { - return v - } - return d -} - // NewOptTestRequestFormatTestReq returns new OptTestRequestFormatTestReq with value set to v. func NewOptTestRequestFormatTestReq(v TestRequestFormatTestReq) OptTestRequestFormatTestReq { return OptTestRequestFormatTestReq{ @@ -7015,16 +6969,7 @@ func (o OptUnixSeconds) Or(d time.Time) time.Time { return d } -type TestRequestEmptyStructReq map[string]jx.Raw - -func (s *TestRequestEmptyStructReq) init() TestRequestEmptyStructReq { - m := *s - if m == nil { - m = map[string]jx.Raw{} - *s = m - } - return m -} +type TestRequestEmptyStructReq struct{} type TestRequestFormatTestReq struct { RequiredAny jx.Raw `json:"required_any"` @@ -10791,16 +10736,7 @@ func (s *TestRequestFormatTestReq) SetOptionalStringUUID(val OptUUID) { s.OptionalStringUUID = val } -type TestRequestRequiredEmptyStructReq map[string]jx.Raw - -func (s *TestRequestRequiredEmptyStructReq) init() TestRequestRequiredEmptyStructReq { - m := *s - if m == nil { - m = map[string]jx.Raw{} - *s = m - } - return m -} +type TestRequestRequiredEmptyStructReq struct{} type TestRequestRequiredFormatTestReq struct { RequiredAny jx.Raw `json:"required_any"` @@ -14567,16 +14503,7 @@ func (s *TestRequestRequiredFormatTestReq) SetOptionalStringUUID(val OptUUID) { s.OptionalStringUUID = val } -type TestResponseEmptyStructOK map[string]jx.Raw - -func (s *TestResponseEmptyStructOK) init() TestResponseEmptyStructOK { - m := *s - if m == nil { - m = map[string]jx.Raw{} - *s = m - } - return m -} +type TestResponseEmptyStructOK struct{} type TestResponseFormatTestOK struct { RequiredAny jx.Raw `json:"required_any"` diff --git a/examples/ex_test_format/oas_server_gen.go b/examples/ex_test_format/oas_server_gen.go index 4e43ea808..5d08d82af 100644 --- a/examples/ex_test_format/oas_server_gen.go +++ b/examples/ex_test_format/oas_server_gen.go @@ -50,7 +50,7 @@ type Handler interface { // TestRequestEmptyStruct implements test_request_EmptyStruct operation. // // POST /test_request_EmptyStruct - TestRequestEmptyStruct(ctx context.Context, req OptTestRequestEmptyStructReq) (*Error, error) + TestRequestEmptyStruct(ctx context.Context, req *TestRequestEmptyStructReq) (*Error, error) // TestRequestFormatTest implements test_request_FormatTest operation. // // POST /test_request_FormatTest @@ -590,7 +590,7 @@ type Handler interface { // TestRequestRequiredEmptyStruct implements test_request_required_EmptyStruct operation. // // POST /test_request_required_EmptyStruct - TestRequestRequiredEmptyStruct(ctx context.Context, req TestRequestRequiredEmptyStructReq) (*Error, error) + TestRequestRequiredEmptyStruct(ctx context.Context, req *TestRequestRequiredEmptyStructReq) (*Error, error) // TestRequestRequiredFormatTest implements test_request_required_FormatTest operation. // // POST /test_request_required_FormatTest @@ -2762,7 +2762,7 @@ type Handler interface { // TestResponseEmptyStruct implements test_response_EmptyStruct operation. // // POST /test_response_EmptyStruct - TestResponseEmptyStruct(ctx context.Context, req string) (TestResponseEmptyStructOK, error) + TestResponseEmptyStruct(ctx context.Context, req string) error // TestResponseFormatTest implements test_response_FormatTest operation. // // POST /test_response_FormatTest diff --git a/examples/ex_test_format/oas_test_examples_gen_test.go b/examples/ex_test_format/oas_test_examples_gen_test.go index 527700f31..07b974188 100644 --- a/examples/ex_test_format/oas_test_examples_gen_test.go +++ b/examples/ex_test_format/oas_test_examples_gen_test.go @@ -25,7 +25,6 @@ func TestError_EncodeDecode(t *testing.T) { } func TestTestRequestEmptyStructReq_EncodeDecode(t *testing.T) { var typ TestRequestEmptyStructReq - typ = make(TestRequestEmptyStructReq) typ.SetFake() e := jx.Encoder{} @@ -34,7 +33,6 @@ func TestTestRequestEmptyStructReq_EncodeDecode(t *testing.T) { require.True(t, std.Valid(data), "Encoded: %s", data) var typ2 TestRequestEmptyStructReq - typ2 = make(TestRequestEmptyStructReq) require.NoError(t, typ2.Decode(jx.DecodeBytes(data))) } func TestTestRequestFormatTestReq_EncodeDecode(t *testing.T) { @@ -51,7 +49,6 @@ func TestTestRequestFormatTestReq_EncodeDecode(t *testing.T) { } func TestTestRequestRequiredEmptyStructReq_EncodeDecode(t *testing.T) { var typ TestRequestRequiredEmptyStructReq - typ = make(TestRequestRequiredEmptyStructReq) typ.SetFake() e := jx.Encoder{} @@ -60,7 +57,6 @@ func TestTestRequestRequiredEmptyStructReq_EncodeDecode(t *testing.T) { require.True(t, std.Valid(data), "Encoded: %s", data) var typ2 TestRequestRequiredEmptyStructReq - typ2 = make(TestRequestRequiredEmptyStructReq) require.NoError(t, typ2.Decode(jx.DecodeBytes(data))) } func TestTestRequestRequiredFormatTestReq_EncodeDecode(t *testing.T) { @@ -77,7 +73,6 @@ func TestTestRequestRequiredFormatTestReq_EncodeDecode(t *testing.T) { } func TestTestResponseEmptyStructOK_EncodeDecode(t *testing.T) { var typ TestResponseEmptyStructOK - typ = make(TestResponseEmptyStructOK) typ.SetFake() e := jx.Encoder{} @@ -86,7 +81,6 @@ func TestTestResponseEmptyStructOK_EncodeDecode(t *testing.T) { require.True(t, std.Valid(data), "Encoded: %s", data) var typ2 TestResponseEmptyStructOK - typ2 = make(TestResponseEmptyStructOK) require.NoError(t, typ2.Decode(jx.DecodeBytes(data))) } func TestTestResponseFormatTestOK_EncodeDecode(t *testing.T) { diff --git a/examples/ex_test_format/oas_unimplemented_gen.go b/examples/ex_test_format/oas_unimplemented_gen.go index dd21a9a7b..775bca2d0 100644 --- a/examples/ex_test_format/oas_unimplemented_gen.go +++ b/examples/ex_test_format/oas_unimplemented_gen.go @@ -79,7 +79,7 @@ func (UnimplementedHandler) TestRequestBooleanNullableArrayArray(ctx context.Con // TestRequestEmptyStruct implements test_request_EmptyStruct operation. // // POST /test_request_EmptyStruct -func (UnimplementedHandler) TestRequestEmptyStruct(ctx context.Context, req OptTestRequestEmptyStructReq) (r *Error, _ error) { +func (UnimplementedHandler) TestRequestEmptyStruct(ctx context.Context, req *TestRequestEmptyStructReq) (r *Error, _ error) { return r, ht.ErrNotImplemented } @@ -1024,7 +1024,7 @@ func (UnimplementedHandler) TestRequestRequiredBooleanNullableArrayArray(ctx con // TestRequestRequiredEmptyStruct implements test_request_required_EmptyStruct operation. // // POST /test_request_required_EmptyStruct -func (UnimplementedHandler) TestRequestRequiredEmptyStruct(ctx context.Context, req TestRequestRequiredEmptyStructReq) (r *Error, _ error) { +func (UnimplementedHandler) TestRequestRequiredEmptyStruct(ctx context.Context, req *TestRequestRequiredEmptyStructReq) (r *Error, _ error) { return r, ht.ErrNotImplemented } @@ -4825,8 +4825,8 @@ func (UnimplementedHandler) TestResponseBooleanNullableArrayArray(ctx context.Co // TestResponseEmptyStruct implements test_response_EmptyStruct operation. // // POST /test_response_EmptyStruct -func (UnimplementedHandler) TestResponseEmptyStruct(ctx context.Context, req string) (r TestResponseEmptyStructOK, _ error) { - return r, ht.ErrNotImplemented +func (UnimplementedHandler) TestResponseEmptyStruct(ctx context.Context, req string) error { + return ht.ErrNotImplemented } // TestResponseFormatTest implements test_response_FormatTest operation. diff --git a/examples/ex_tinkoff/oas_faker_gen.go b/examples/ex_tinkoff/oas_faker_gen.go index 02f8245f9..262d26cc7 100644 --- a/examples/ex_tinkoff/oas_faker_gen.go +++ b/examples/ex_tinkoff/oas_faker_gen.go @@ -3,10 +3,7 @@ package api import ( - "fmt" "time" - - "github.com/go-faster/jx" ) // SetFake set fake values. @@ -169,13 +166,6 @@ func (s *Empty) SetFake() { // SetFake set fake values. func (s *EmptyPayload) SetFake() { - var ( - elem jx.Raw - m map[string]jx.Raw = s.init() - ) - for i := 0; i < 0; i++ { - m[fmt.Sprintf("fake%d", i)] = elem - } } // SetFake set fake values. diff --git a/examples/ex_tinkoff/oas_json_gen.go b/examples/ex_tinkoff/oas_json_gen.go index 3dfece861..d9b6b9aa6 100644 --- a/examples/ex_tinkoff/oas_json_gen.go +++ b/examples/ex_tinkoff/oas_json_gen.go @@ -1009,43 +1009,29 @@ func (s *Empty) UnmarshalJSON(data []byte) error { } // Encode implements json.Marshaler. -func (s EmptyPayload) Encode(e *jx.Encoder) { +func (s *EmptyPayload) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } -// encodeFields implements json.Marshaler. -func (s EmptyPayload) encodeFields(e *jx.Encoder) { - for k, elem := range s { - e.FieldStart(k) - - if len(elem) != 0 { - e.Raw(elem) - } - } +// encodeFields encodes fields. +func (s *EmptyPayload) encodeFields(e *jx.Encoder) { } +var jsonFieldsNameOfEmptyPayload = [0]string{} + // Decode decodes EmptyPayload from json. func (s *EmptyPayload) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode EmptyPayload to nil") } - m := s.init() + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { - var elem jx.Raw - if err := func() error { - v, err := d.RawAppend(nil) - elem = jx.Raw(v) - if err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrapf(err, "decode field %q", k) + switch string(k) { + default: + return d.Skip() } - m[string(k)] = elem - return nil }); err != nil { return errors.Wrap(err, "decode EmptyPayload") } @@ -1054,7 +1040,7 @@ func (s *EmptyPayload) Decode(d *jx.Decoder) error { } // MarshalJSON implements stdjson.Marshaler. -func (s EmptyPayload) MarshalJSON() ([]byte, error) { +func (s *EmptyPayload) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil diff --git a/examples/ex_tinkoff/oas_schemas_gen.go b/examples/ex_tinkoff/oas_schemas_gen.go index 52621732b..b38073ffc 100644 --- a/examples/ex_tinkoff/oas_schemas_gen.go +++ b/examples/ex_tinkoff/oas_schemas_gen.go @@ -6,7 +6,6 @@ import ( "time" "github.com/go-faster/errors" - "github.com/go-faster/jx" ) // Ref: #/components/schemas/BrokerAccountType @@ -523,16 +522,7 @@ func (*Empty) sandboxCurrenciesBalancePostRes() {} func (*Empty) sandboxPositionsBalancePostRes() {} func (*Empty) sandboxRemovePostRes() {} -type EmptyPayload map[string]jx.Raw - -func (s *EmptyPayload) init() EmptyPayload { - m := *s - if m == nil { - m = map[string]jx.Raw{} - *s = m - } - return m -} +type EmptyPayload struct{} // Ref: #/components/schemas/Error type Error struct { diff --git a/examples/ex_tinkoff/oas_test_examples_gen_test.go b/examples/ex_tinkoff/oas_test_examples_gen_test.go index 07271e7ab..a0ab9e49b 100644 --- a/examples/ex_tinkoff/oas_test_examples_gen_test.go +++ b/examples/ex_tinkoff/oas_test_examples_gen_test.go @@ -121,7 +121,6 @@ func TestEmpty_EncodeDecode(t *testing.T) { } func TestEmptyPayload_EncodeDecode(t *testing.T) { var typ EmptyPayload - typ = make(EmptyPayload) typ.SetFake() e := jx.Encoder{} @@ -130,7 +129,6 @@ func TestEmptyPayload_EncodeDecode(t *testing.T) { require.True(t, std.Valid(data), "Encoded: %s", data) var typ2 EmptyPayload - typ2 = make(EmptyPayload) require.NoError(t, typ2.Decode(jx.DecodeBytes(data))) } func TestError_EncodeDecode(t *testing.T) { diff --git a/internal/integration/sample_api/oas_faker_gen.go b/internal/integration/sample_api/oas_faker_gen.go index f5e63beb4..01da7ed48 100644 --- a/internal/integration/sample_api/oas_faker_gen.go +++ b/internal/integration/sample_api/oas_faker_gen.go @@ -780,8 +780,8 @@ func (s *OneOfMappingReferenceB) SetFake() { } } { - { - s.Data.SetFake() + { // Keep pointer nil to prevent infinite recursion. + s.Data = nil } } { @@ -793,13 +793,6 @@ func (s *OneOfMappingReferenceB) SetFake() { // SetFake set fake values. func (s *OneOfMappingReferenceBData) SetFake() { - var ( - elem jx.Raw - m map[string]jx.Raw = s.init() - ) - for i := 0; i < 0; i++ { - m[fmt.Sprintf("fake%d", i)] = elem - } } // SetFake set fake values. @@ -1160,15 +1153,6 @@ func (s *OptOneOfMappingReference) SetFake() { s.SetTo(elem) } -// SetFake set fake values. -func (s *OptOneOfMappingReferenceBData) SetFake() { - var elem OneOfMappingReferenceBData - { - elem.SetFake() - } - s.SetTo(elem) -} - // SetFake set fake values. func (s *OptOneOfUUIDAndIntEnum) SetFake() { var elem OneOfUUIDAndIntEnum diff --git a/internal/integration/sample_api/oas_json_gen.go b/internal/integration/sample_api/oas_json_gen.go index 2240bf44a..be3fdeb67 100644 --- a/internal/integration/sample_api/oas_json_gen.go +++ b/internal/integration/sample_api/oas_json_gen.go @@ -4859,7 +4859,7 @@ func (s OneOfMappingReference) encodeFields(e *jx.Encoder) { } } { - if s.Data.Set { + if s.Data != nil { e.FieldStart("data") s.Data.Encode(e) } @@ -5058,7 +5058,7 @@ func (s *OneOfMappingReferenceB) encodeFields(e *jx.Encoder) { } } { - if s.Data.Set { + if s.Data != nil { e.FieldStart("data") s.Data.Encode(e) } @@ -5108,10 +5108,12 @@ func (s *OneOfMappingReferenceB) Decode(d *jx.Decoder) error { } case "data": if err := func() error { - s.Data.Reset() - if err := s.Data.Decode(d); err != nil { + s.Data = nil + var elem OneOfMappingReferenceBData + if err := elem.Decode(d); err != nil { return err } + s.Data = &elem return nil }(); err != nil { return errors.Wrap(err, "decode field \"data\"") @@ -5151,43 +5153,29 @@ func (s *OneOfMappingReferenceB) UnmarshalJSON(data []byte) error { } // Encode implements json.Marshaler. -func (s OneOfMappingReferenceBData) Encode(e *jx.Encoder) { +func (s *OneOfMappingReferenceBData) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } -// encodeFields implements json.Marshaler. -func (s OneOfMappingReferenceBData) encodeFields(e *jx.Encoder) { - for k, elem := range s { - e.FieldStart(k) - - if len(elem) != 0 { - e.Raw(elem) - } - } +// encodeFields encodes fields. +func (s *OneOfMappingReferenceBData) encodeFields(e *jx.Encoder) { } +var jsonFieldsNameOfOneOfMappingReferenceBData = [0]string{} + // Decode decodes OneOfMappingReferenceBData from json. func (s *OneOfMappingReferenceBData) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode OneOfMappingReferenceBData to nil") } - m := s.init() + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { - var elem jx.Raw - if err := func() error { - v, err := d.RawAppend(nil) - elem = jx.Raw(v) - if err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrapf(err, "decode field %q", k) + switch string(k) { + default: + return d.Skip() } - m[string(k)] = elem - return nil }); err != nil { return errors.Wrap(err, "decode OneOfMappingReferenceBData") } @@ -5196,7 +5184,7 @@ func (s *OneOfMappingReferenceBData) Decode(d *jx.Decoder) error { } // MarshalJSON implements stdjson.Marshaler. -func (s OneOfMappingReferenceBData) MarshalJSON() ([]byte, error) { +func (s *OneOfMappingReferenceBData) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil @@ -6999,40 +6987,6 @@ func (s *OptOneOfMappingReference) UnmarshalJSON(data []byte) error { return s.Decode(d) } -// Encode encodes OneOfMappingReferenceBData as json. -func (o OptOneOfMappingReferenceBData) Encode(e *jx.Encoder) { - if !o.Set { - return - } - o.Value.Encode(e) -} - -// Decode decodes OneOfMappingReferenceBData from json. -func (o *OptOneOfMappingReferenceBData) Decode(d *jx.Decoder) error { - if o == nil { - return errors.New("invalid: unable to decode OptOneOfMappingReferenceBData to nil") - } - o.Set = true - o.Value = make(OneOfMappingReferenceBData) - if err := o.Value.Decode(d); err != nil { - return err - } - return nil -} - -// MarshalJSON implements stdjson.Marshaler. -func (s OptOneOfMappingReferenceBData) MarshalJSON() ([]byte, error) { - e := jx.Encoder{} - s.Encode(&e) - return e.Bytes(), nil -} - -// UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptOneOfMappingReferenceBData) UnmarshalJSON(data []byte) error { - d := jx.DecodeBytes(data) - return s.Decode(d) -} - // Encode encodes OneOfUUIDAndIntEnum as json. func (o OptOneOfUUIDAndIntEnum) Encode(e *jx.Encoder) { if !o.Set { diff --git a/internal/integration/sample_api/oas_schemas_gen.go b/internal/integration/sample_api/oas_schemas_gen.go index ee5b1423c..6856cbbd0 100644 --- a/internal/integration/sample_api/oas_schemas_gen.go +++ b/internal/integration/sample_api/oas_schemas_gen.go @@ -2373,10 +2373,10 @@ func (s *OneOfMappingReferenceA) SetDescription(val OptString) { // Ref: #/components/schemas/OneOfMappingReferenceB type OneOfMappingReferenceB struct { - InfoType OptString `json:"infoType"` - Code OptInt32 `json:"code"` - Data OptOneOfMappingReferenceBData `json:"data"` - Info OptString `json:"info"` + InfoType OptString `json:"infoType"` + Code OptInt32 `json:"code"` + Data *OneOfMappingReferenceBData `json:"data"` + Info OptString `json:"info"` } // GetInfoType returns the value of InfoType. @@ -2390,7 +2390,7 @@ func (s *OneOfMappingReferenceB) GetCode() OptInt32 { } // GetData returns the value of Data. -func (s *OneOfMappingReferenceB) GetData() OptOneOfMappingReferenceBData { +func (s *OneOfMappingReferenceB) GetData() *OneOfMappingReferenceBData { return s.Data } @@ -2410,7 +2410,7 @@ func (s *OneOfMappingReferenceB) SetCode(val OptInt32) { } // SetData sets the value of Data. -func (s *OneOfMappingReferenceB) SetData(val OptOneOfMappingReferenceBData) { +func (s *OneOfMappingReferenceB) SetData(val *OneOfMappingReferenceBData) { s.Data = val } @@ -2419,16 +2419,7 @@ func (s *OneOfMappingReferenceB) SetInfo(val OptString) { s.Info = val } -type OneOfMappingReferenceBData map[string]jx.Raw - -func (s *OneOfMappingReferenceBData) init() OneOfMappingReferenceBData { - m := *s - if m == nil { - m = map[string]jx.Raw{} - *s = m - } - return m -} +type OneOfMappingReferenceBData struct{} // Ref: #/components/schemas/OneOfNullables // OneOfNullables represents sum type. @@ -4253,52 +4244,6 @@ func (o OptOneOfMappingReference) Or(d OneOfMappingReference) OneOfMappingRefere return d } -// NewOptOneOfMappingReferenceBData returns new OptOneOfMappingReferenceBData with value set to v. -func NewOptOneOfMappingReferenceBData(v OneOfMappingReferenceBData) OptOneOfMappingReferenceBData { - return OptOneOfMappingReferenceBData{ - Value: v, - Set: true, - } -} - -// OptOneOfMappingReferenceBData is optional OneOfMappingReferenceBData. -type OptOneOfMappingReferenceBData struct { - Value OneOfMappingReferenceBData - Set bool -} - -// IsSet returns true if OptOneOfMappingReferenceBData was set. -func (o OptOneOfMappingReferenceBData) IsSet() bool { return o.Set } - -// Reset unsets value. -func (o *OptOneOfMappingReferenceBData) Reset() { - var v OneOfMappingReferenceBData - o.Value = v - o.Set = false -} - -// SetTo sets value to v. -func (o *OptOneOfMappingReferenceBData) SetTo(v OneOfMappingReferenceBData) { - o.Set = true - o.Value = v -} - -// Get returns value and boolean that denotes whether value was set. -func (o OptOneOfMappingReferenceBData) Get() (v OneOfMappingReferenceBData, ok bool) { - if !o.Set { - return v, false - } - return o.Value, true -} - -// Or returns value if set, or given parameter if does not. -func (o OptOneOfMappingReferenceBData) Or(d OneOfMappingReferenceBData) OneOfMappingReferenceBData { - if v, ok := o.Get(); ok { - return v - } - return d -} - // NewOptOneOfUUIDAndIntEnum returns new OptOneOfUUIDAndIntEnum with value set to v. func NewOptOneOfUUIDAndIntEnum(v OneOfUUIDAndIntEnum) OptOneOfUUIDAndIntEnum { return OptOneOfUUIDAndIntEnum{ diff --git a/internal/integration/sample_api/oas_test_examples_gen_test.go b/internal/integration/sample_api/oas_test_examples_gen_test.go index 9073af5a3..be1228716 100644 --- a/internal/integration/sample_api/oas_test_examples_gen_test.go +++ b/internal/integration/sample_api/oas_test_examples_gen_test.go @@ -573,7 +573,6 @@ func TestOneOfMappingReferenceB_EncodeDecode(t *testing.T) { } func TestOneOfMappingReferenceBData_EncodeDecode(t *testing.T) { var typ OneOfMappingReferenceBData - typ = make(OneOfMappingReferenceBData) typ.SetFake() e := jx.Encoder{} @@ -582,7 +581,6 @@ func TestOneOfMappingReferenceBData_EncodeDecode(t *testing.T) { require.True(t, std.Valid(data), "Encoded: %s", data) var typ2 OneOfMappingReferenceBData - typ2 = make(OneOfMappingReferenceBData) require.NoError(t, typ2.Decode(jx.DecodeBytes(data))) } func TestOneOfNullables_EncodeDecode(t *testing.T) { diff --git a/internal/integration/sample_api_nc/oas_json_gen.go b/internal/integration/sample_api_nc/oas_json_gen.go index 2240bf44a..be3fdeb67 100644 --- a/internal/integration/sample_api_nc/oas_json_gen.go +++ b/internal/integration/sample_api_nc/oas_json_gen.go @@ -4859,7 +4859,7 @@ func (s OneOfMappingReference) encodeFields(e *jx.Encoder) { } } { - if s.Data.Set { + if s.Data != nil { e.FieldStart("data") s.Data.Encode(e) } @@ -5058,7 +5058,7 @@ func (s *OneOfMappingReferenceB) encodeFields(e *jx.Encoder) { } } { - if s.Data.Set { + if s.Data != nil { e.FieldStart("data") s.Data.Encode(e) } @@ -5108,10 +5108,12 @@ func (s *OneOfMappingReferenceB) Decode(d *jx.Decoder) error { } case "data": if err := func() error { - s.Data.Reset() - if err := s.Data.Decode(d); err != nil { + s.Data = nil + var elem OneOfMappingReferenceBData + if err := elem.Decode(d); err != nil { return err } + s.Data = &elem return nil }(); err != nil { return errors.Wrap(err, "decode field \"data\"") @@ -5151,43 +5153,29 @@ func (s *OneOfMappingReferenceB) UnmarshalJSON(data []byte) error { } // Encode implements json.Marshaler. -func (s OneOfMappingReferenceBData) Encode(e *jx.Encoder) { +func (s *OneOfMappingReferenceBData) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } -// encodeFields implements json.Marshaler. -func (s OneOfMappingReferenceBData) encodeFields(e *jx.Encoder) { - for k, elem := range s { - e.FieldStart(k) - - if len(elem) != 0 { - e.Raw(elem) - } - } +// encodeFields encodes fields. +func (s *OneOfMappingReferenceBData) encodeFields(e *jx.Encoder) { } +var jsonFieldsNameOfOneOfMappingReferenceBData = [0]string{} + // Decode decodes OneOfMappingReferenceBData from json. func (s *OneOfMappingReferenceBData) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode OneOfMappingReferenceBData to nil") } - m := s.init() + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { - var elem jx.Raw - if err := func() error { - v, err := d.RawAppend(nil) - elem = jx.Raw(v) - if err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrapf(err, "decode field %q", k) + switch string(k) { + default: + return d.Skip() } - m[string(k)] = elem - return nil }); err != nil { return errors.Wrap(err, "decode OneOfMappingReferenceBData") } @@ -5196,7 +5184,7 @@ func (s *OneOfMappingReferenceBData) Decode(d *jx.Decoder) error { } // MarshalJSON implements stdjson.Marshaler. -func (s OneOfMappingReferenceBData) MarshalJSON() ([]byte, error) { +func (s *OneOfMappingReferenceBData) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil @@ -6999,40 +6987,6 @@ func (s *OptOneOfMappingReference) UnmarshalJSON(data []byte) error { return s.Decode(d) } -// Encode encodes OneOfMappingReferenceBData as json. -func (o OptOneOfMappingReferenceBData) Encode(e *jx.Encoder) { - if !o.Set { - return - } - o.Value.Encode(e) -} - -// Decode decodes OneOfMappingReferenceBData from json. -func (o *OptOneOfMappingReferenceBData) Decode(d *jx.Decoder) error { - if o == nil { - return errors.New("invalid: unable to decode OptOneOfMappingReferenceBData to nil") - } - o.Set = true - o.Value = make(OneOfMappingReferenceBData) - if err := o.Value.Decode(d); err != nil { - return err - } - return nil -} - -// MarshalJSON implements stdjson.Marshaler. -func (s OptOneOfMappingReferenceBData) MarshalJSON() ([]byte, error) { - e := jx.Encoder{} - s.Encode(&e) - return e.Bytes(), nil -} - -// UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptOneOfMappingReferenceBData) UnmarshalJSON(data []byte) error { - d := jx.DecodeBytes(data) - return s.Decode(d) -} - // Encode encodes OneOfUUIDAndIntEnum as json. func (o OptOneOfUUIDAndIntEnum) Encode(e *jx.Encoder) { if !o.Set { diff --git a/internal/integration/sample_api_nc/oas_schemas_gen.go b/internal/integration/sample_api_nc/oas_schemas_gen.go index ee5b1423c..6856cbbd0 100644 --- a/internal/integration/sample_api_nc/oas_schemas_gen.go +++ b/internal/integration/sample_api_nc/oas_schemas_gen.go @@ -2373,10 +2373,10 @@ func (s *OneOfMappingReferenceA) SetDescription(val OptString) { // Ref: #/components/schemas/OneOfMappingReferenceB type OneOfMappingReferenceB struct { - InfoType OptString `json:"infoType"` - Code OptInt32 `json:"code"` - Data OptOneOfMappingReferenceBData `json:"data"` - Info OptString `json:"info"` + InfoType OptString `json:"infoType"` + Code OptInt32 `json:"code"` + Data *OneOfMappingReferenceBData `json:"data"` + Info OptString `json:"info"` } // GetInfoType returns the value of InfoType. @@ -2390,7 +2390,7 @@ func (s *OneOfMappingReferenceB) GetCode() OptInt32 { } // GetData returns the value of Data. -func (s *OneOfMappingReferenceB) GetData() OptOneOfMappingReferenceBData { +func (s *OneOfMappingReferenceB) GetData() *OneOfMappingReferenceBData { return s.Data } @@ -2410,7 +2410,7 @@ func (s *OneOfMappingReferenceB) SetCode(val OptInt32) { } // SetData sets the value of Data. -func (s *OneOfMappingReferenceB) SetData(val OptOneOfMappingReferenceBData) { +func (s *OneOfMappingReferenceB) SetData(val *OneOfMappingReferenceBData) { s.Data = val } @@ -2419,16 +2419,7 @@ func (s *OneOfMappingReferenceB) SetInfo(val OptString) { s.Info = val } -type OneOfMappingReferenceBData map[string]jx.Raw - -func (s *OneOfMappingReferenceBData) init() OneOfMappingReferenceBData { - m := *s - if m == nil { - m = map[string]jx.Raw{} - *s = m - } - return m -} +type OneOfMappingReferenceBData struct{} // Ref: #/components/schemas/OneOfNullables // OneOfNullables represents sum type. @@ -4253,52 +4244,6 @@ func (o OptOneOfMappingReference) Or(d OneOfMappingReference) OneOfMappingRefere return d } -// NewOptOneOfMappingReferenceBData returns new OptOneOfMappingReferenceBData with value set to v. -func NewOptOneOfMappingReferenceBData(v OneOfMappingReferenceBData) OptOneOfMappingReferenceBData { - return OptOneOfMappingReferenceBData{ - Value: v, - Set: true, - } -} - -// OptOneOfMappingReferenceBData is optional OneOfMappingReferenceBData. -type OptOneOfMappingReferenceBData struct { - Value OneOfMappingReferenceBData - Set bool -} - -// IsSet returns true if OptOneOfMappingReferenceBData was set. -func (o OptOneOfMappingReferenceBData) IsSet() bool { return o.Set } - -// Reset unsets value. -func (o *OptOneOfMappingReferenceBData) Reset() { - var v OneOfMappingReferenceBData - o.Value = v - o.Set = false -} - -// SetTo sets value to v. -func (o *OptOneOfMappingReferenceBData) SetTo(v OneOfMappingReferenceBData) { - o.Set = true - o.Value = v -} - -// Get returns value and boolean that denotes whether value was set. -func (o OptOneOfMappingReferenceBData) Get() (v OneOfMappingReferenceBData, ok bool) { - if !o.Set { - return v, false - } - return o.Value, true -} - -// Or returns value if set, or given parameter if does not. -func (o OptOneOfMappingReferenceBData) Or(d OneOfMappingReferenceBData) OneOfMappingReferenceBData { - if v, ok := o.Get(); ok { - return v - } - return d -} - // NewOptOneOfUUIDAndIntEnum returns new OptOneOfUUIDAndIntEnum with value set to v. func NewOptOneOfUUIDAndIntEnum(v OneOfUUIDAndIntEnum) OptOneOfUUIDAndIntEnum { return OptOneOfUUIDAndIntEnum{ diff --git a/internal/integration/sample_api_no_otel/oas_json_gen.go b/internal/integration/sample_api_no_otel/oas_json_gen.go index 2240bf44a..be3fdeb67 100644 --- a/internal/integration/sample_api_no_otel/oas_json_gen.go +++ b/internal/integration/sample_api_no_otel/oas_json_gen.go @@ -4859,7 +4859,7 @@ func (s OneOfMappingReference) encodeFields(e *jx.Encoder) { } } { - if s.Data.Set { + if s.Data != nil { e.FieldStart("data") s.Data.Encode(e) } @@ -5058,7 +5058,7 @@ func (s *OneOfMappingReferenceB) encodeFields(e *jx.Encoder) { } } { - if s.Data.Set { + if s.Data != nil { e.FieldStart("data") s.Data.Encode(e) } @@ -5108,10 +5108,12 @@ func (s *OneOfMappingReferenceB) Decode(d *jx.Decoder) error { } case "data": if err := func() error { - s.Data.Reset() - if err := s.Data.Decode(d); err != nil { + s.Data = nil + var elem OneOfMappingReferenceBData + if err := elem.Decode(d); err != nil { return err } + s.Data = &elem return nil }(); err != nil { return errors.Wrap(err, "decode field \"data\"") @@ -5151,43 +5153,29 @@ func (s *OneOfMappingReferenceB) UnmarshalJSON(data []byte) error { } // Encode implements json.Marshaler. -func (s OneOfMappingReferenceBData) Encode(e *jx.Encoder) { +func (s *OneOfMappingReferenceBData) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } -// encodeFields implements json.Marshaler. -func (s OneOfMappingReferenceBData) encodeFields(e *jx.Encoder) { - for k, elem := range s { - e.FieldStart(k) - - if len(elem) != 0 { - e.Raw(elem) - } - } +// encodeFields encodes fields. +func (s *OneOfMappingReferenceBData) encodeFields(e *jx.Encoder) { } +var jsonFieldsNameOfOneOfMappingReferenceBData = [0]string{} + // Decode decodes OneOfMappingReferenceBData from json. func (s *OneOfMappingReferenceBData) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode OneOfMappingReferenceBData to nil") } - m := s.init() + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { - var elem jx.Raw - if err := func() error { - v, err := d.RawAppend(nil) - elem = jx.Raw(v) - if err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrapf(err, "decode field %q", k) + switch string(k) { + default: + return d.Skip() } - m[string(k)] = elem - return nil }); err != nil { return errors.Wrap(err, "decode OneOfMappingReferenceBData") } @@ -5196,7 +5184,7 @@ func (s *OneOfMappingReferenceBData) Decode(d *jx.Decoder) error { } // MarshalJSON implements stdjson.Marshaler. -func (s OneOfMappingReferenceBData) MarshalJSON() ([]byte, error) { +func (s *OneOfMappingReferenceBData) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil @@ -6999,40 +6987,6 @@ func (s *OptOneOfMappingReference) UnmarshalJSON(data []byte) error { return s.Decode(d) } -// Encode encodes OneOfMappingReferenceBData as json. -func (o OptOneOfMappingReferenceBData) Encode(e *jx.Encoder) { - if !o.Set { - return - } - o.Value.Encode(e) -} - -// Decode decodes OneOfMappingReferenceBData from json. -func (o *OptOneOfMappingReferenceBData) Decode(d *jx.Decoder) error { - if o == nil { - return errors.New("invalid: unable to decode OptOneOfMappingReferenceBData to nil") - } - o.Set = true - o.Value = make(OneOfMappingReferenceBData) - if err := o.Value.Decode(d); err != nil { - return err - } - return nil -} - -// MarshalJSON implements stdjson.Marshaler. -func (s OptOneOfMappingReferenceBData) MarshalJSON() ([]byte, error) { - e := jx.Encoder{} - s.Encode(&e) - return e.Bytes(), nil -} - -// UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptOneOfMappingReferenceBData) UnmarshalJSON(data []byte) error { - d := jx.DecodeBytes(data) - return s.Decode(d) -} - // Encode encodes OneOfUUIDAndIntEnum as json. func (o OptOneOfUUIDAndIntEnum) Encode(e *jx.Encoder) { if !o.Set { diff --git a/internal/integration/sample_api_no_otel/oas_schemas_gen.go b/internal/integration/sample_api_no_otel/oas_schemas_gen.go index ee5b1423c..6856cbbd0 100644 --- a/internal/integration/sample_api_no_otel/oas_schemas_gen.go +++ b/internal/integration/sample_api_no_otel/oas_schemas_gen.go @@ -2373,10 +2373,10 @@ func (s *OneOfMappingReferenceA) SetDescription(val OptString) { // Ref: #/components/schemas/OneOfMappingReferenceB type OneOfMappingReferenceB struct { - InfoType OptString `json:"infoType"` - Code OptInt32 `json:"code"` - Data OptOneOfMappingReferenceBData `json:"data"` - Info OptString `json:"info"` + InfoType OptString `json:"infoType"` + Code OptInt32 `json:"code"` + Data *OneOfMappingReferenceBData `json:"data"` + Info OptString `json:"info"` } // GetInfoType returns the value of InfoType. @@ -2390,7 +2390,7 @@ func (s *OneOfMappingReferenceB) GetCode() OptInt32 { } // GetData returns the value of Data. -func (s *OneOfMappingReferenceB) GetData() OptOneOfMappingReferenceBData { +func (s *OneOfMappingReferenceB) GetData() *OneOfMappingReferenceBData { return s.Data } @@ -2410,7 +2410,7 @@ func (s *OneOfMappingReferenceB) SetCode(val OptInt32) { } // SetData sets the value of Data. -func (s *OneOfMappingReferenceB) SetData(val OptOneOfMappingReferenceBData) { +func (s *OneOfMappingReferenceB) SetData(val *OneOfMappingReferenceBData) { s.Data = val } @@ -2419,16 +2419,7 @@ func (s *OneOfMappingReferenceB) SetInfo(val OptString) { s.Info = val } -type OneOfMappingReferenceBData map[string]jx.Raw - -func (s *OneOfMappingReferenceBData) init() OneOfMappingReferenceBData { - m := *s - if m == nil { - m = map[string]jx.Raw{} - *s = m - } - return m -} +type OneOfMappingReferenceBData struct{} // Ref: #/components/schemas/OneOfNullables // OneOfNullables represents sum type. @@ -4253,52 +4244,6 @@ func (o OptOneOfMappingReference) Or(d OneOfMappingReference) OneOfMappingRefere return d } -// NewOptOneOfMappingReferenceBData returns new OptOneOfMappingReferenceBData with value set to v. -func NewOptOneOfMappingReferenceBData(v OneOfMappingReferenceBData) OptOneOfMappingReferenceBData { - return OptOneOfMappingReferenceBData{ - Value: v, - Set: true, - } -} - -// OptOneOfMappingReferenceBData is optional OneOfMappingReferenceBData. -type OptOneOfMappingReferenceBData struct { - Value OneOfMappingReferenceBData - Set bool -} - -// IsSet returns true if OptOneOfMappingReferenceBData was set. -func (o OptOneOfMappingReferenceBData) IsSet() bool { return o.Set } - -// Reset unsets value. -func (o *OptOneOfMappingReferenceBData) Reset() { - var v OneOfMappingReferenceBData - o.Value = v - o.Set = false -} - -// SetTo sets value to v. -func (o *OptOneOfMappingReferenceBData) SetTo(v OneOfMappingReferenceBData) { - o.Set = true - o.Value = v -} - -// Get returns value and boolean that denotes whether value was set. -func (o OptOneOfMappingReferenceBData) Get() (v OneOfMappingReferenceBData, ok bool) { - if !o.Set { - return v, false - } - return o.Value, true -} - -// Or returns value if set, or given parameter if does not. -func (o OptOneOfMappingReferenceBData) Or(d OneOfMappingReferenceBData) OneOfMappingReferenceBData { - if v, ok := o.Get(); ok { - return v - } - return d -} - // NewOptOneOfUUIDAndIntEnum returns new OptOneOfUUIDAndIntEnum with value set to v. func NewOptOneOfUUIDAndIntEnum(v OneOfUUIDAndIntEnum) OptOneOfUUIDAndIntEnum { return OptOneOfUUIDAndIntEnum{ diff --git a/internal/integration/sample_api_ns/oas_json_gen.go b/internal/integration/sample_api_ns/oas_json_gen.go index 2240bf44a..be3fdeb67 100644 --- a/internal/integration/sample_api_ns/oas_json_gen.go +++ b/internal/integration/sample_api_ns/oas_json_gen.go @@ -4859,7 +4859,7 @@ func (s OneOfMappingReference) encodeFields(e *jx.Encoder) { } } { - if s.Data.Set { + if s.Data != nil { e.FieldStart("data") s.Data.Encode(e) } @@ -5058,7 +5058,7 @@ func (s *OneOfMappingReferenceB) encodeFields(e *jx.Encoder) { } } { - if s.Data.Set { + if s.Data != nil { e.FieldStart("data") s.Data.Encode(e) } @@ -5108,10 +5108,12 @@ func (s *OneOfMappingReferenceB) Decode(d *jx.Decoder) error { } case "data": if err := func() error { - s.Data.Reset() - if err := s.Data.Decode(d); err != nil { + s.Data = nil + var elem OneOfMappingReferenceBData + if err := elem.Decode(d); err != nil { return err } + s.Data = &elem return nil }(); err != nil { return errors.Wrap(err, "decode field \"data\"") @@ -5151,43 +5153,29 @@ func (s *OneOfMappingReferenceB) UnmarshalJSON(data []byte) error { } // Encode implements json.Marshaler. -func (s OneOfMappingReferenceBData) Encode(e *jx.Encoder) { +func (s *OneOfMappingReferenceBData) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } -// encodeFields implements json.Marshaler. -func (s OneOfMappingReferenceBData) encodeFields(e *jx.Encoder) { - for k, elem := range s { - e.FieldStart(k) - - if len(elem) != 0 { - e.Raw(elem) - } - } +// encodeFields encodes fields. +func (s *OneOfMappingReferenceBData) encodeFields(e *jx.Encoder) { } +var jsonFieldsNameOfOneOfMappingReferenceBData = [0]string{} + // Decode decodes OneOfMappingReferenceBData from json. func (s *OneOfMappingReferenceBData) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode OneOfMappingReferenceBData to nil") } - m := s.init() + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { - var elem jx.Raw - if err := func() error { - v, err := d.RawAppend(nil) - elem = jx.Raw(v) - if err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrapf(err, "decode field %q", k) + switch string(k) { + default: + return d.Skip() } - m[string(k)] = elem - return nil }); err != nil { return errors.Wrap(err, "decode OneOfMappingReferenceBData") } @@ -5196,7 +5184,7 @@ func (s *OneOfMappingReferenceBData) Decode(d *jx.Decoder) error { } // MarshalJSON implements stdjson.Marshaler. -func (s OneOfMappingReferenceBData) MarshalJSON() ([]byte, error) { +func (s *OneOfMappingReferenceBData) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil @@ -6999,40 +6987,6 @@ func (s *OptOneOfMappingReference) UnmarshalJSON(data []byte) error { return s.Decode(d) } -// Encode encodes OneOfMappingReferenceBData as json. -func (o OptOneOfMappingReferenceBData) Encode(e *jx.Encoder) { - if !o.Set { - return - } - o.Value.Encode(e) -} - -// Decode decodes OneOfMappingReferenceBData from json. -func (o *OptOneOfMappingReferenceBData) Decode(d *jx.Decoder) error { - if o == nil { - return errors.New("invalid: unable to decode OptOneOfMappingReferenceBData to nil") - } - o.Set = true - o.Value = make(OneOfMappingReferenceBData) - if err := o.Value.Decode(d); err != nil { - return err - } - return nil -} - -// MarshalJSON implements stdjson.Marshaler. -func (s OptOneOfMappingReferenceBData) MarshalJSON() ([]byte, error) { - e := jx.Encoder{} - s.Encode(&e) - return e.Bytes(), nil -} - -// UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptOneOfMappingReferenceBData) UnmarshalJSON(data []byte) error { - d := jx.DecodeBytes(data) - return s.Decode(d) -} - // Encode encodes OneOfUUIDAndIntEnum as json. func (o OptOneOfUUIDAndIntEnum) Encode(e *jx.Encoder) { if !o.Set { diff --git a/internal/integration/sample_api_ns/oas_schemas_gen.go b/internal/integration/sample_api_ns/oas_schemas_gen.go index ee5b1423c..6856cbbd0 100644 --- a/internal/integration/sample_api_ns/oas_schemas_gen.go +++ b/internal/integration/sample_api_ns/oas_schemas_gen.go @@ -2373,10 +2373,10 @@ func (s *OneOfMappingReferenceA) SetDescription(val OptString) { // Ref: #/components/schemas/OneOfMappingReferenceB type OneOfMappingReferenceB struct { - InfoType OptString `json:"infoType"` - Code OptInt32 `json:"code"` - Data OptOneOfMappingReferenceBData `json:"data"` - Info OptString `json:"info"` + InfoType OptString `json:"infoType"` + Code OptInt32 `json:"code"` + Data *OneOfMappingReferenceBData `json:"data"` + Info OptString `json:"info"` } // GetInfoType returns the value of InfoType. @@ -2390,7 +2390,7 @@ func (s *OneOfMappingReferenceB) GetCode() OptInt32 { } // GetData returns the value of Data. -func (s *OneOfMappingReferenceB) GetData() OptOneOfMappingReferenceBData { +func (s *OneOfMappingReferenceB) GetData() *OneOfMappingReferenceBData { return s.Data } @@ -2410,7 +2410,7 @@ func (s *OneOfMappingReferenceB) SetCode(val OptInt32) { } // SetData sets the value of Data. -func (s *OneOfMappingReferenceB) SetData(val OptOneOfMappingReferenceBData) { +func (s *OneOfMappingReferenceB) SetData(val *OneOfMappingReferenceBData) { s.Data = val } @@ -2419,16 +2419,7 @@ func (s *OneOfMappingReferenceB) SetInfo(val OptString) { s.Info = val } -type OneOfMappingReferenceBData map[string]jx.Raw - -func (s *OneOfMappingReferenceBData) init() OneOfMappingReferenceBData { - m := *s - if m == nil { - m = map[string]jx.Raw{} - *s = m - } - return m -} +type OneOfMappingReferenceBData struct{} // Ref: #/components/schemas/OneOfNullables // OneOfNullables represents sum type. @@ -4253,52 +4244,6 @@ func (o OptOneOfMappingReference) Or(d OneOfMappingReference) OneOfMappingRefere return d } -// NewOptOneOfMappingReferenceBData returns new OptOneOfMappingReferenceBData with value set to v. -func NewOptOneOfMappingReferenceBData(v OneOfMappingReferenceBData) OptOneOfMappingReferenceBData { - return OptOneOfMappingReferenceBData{ - Value: v, - Set: true, - } -} - -// OptOneOfMappingReferenceBData is optional OneOfMappingReferenceBData. -type OptOneOfMappingReferenceBData struct { - Value OneOfMappingReferenceBData - Set bool -} - -// IsSet returns true if OptOneOfMappingReferenceBData was set. -func (o OptOneOfMappingReferenceBData) IsSet() bool { return o.Set } - -// Reset unsets value. -func (o *OptOneOfMappingReferenceBData) Reset() { - var v OneOfMappingReferenceBData - o.Value = v - o.Set = false -} - -// SetTo sets value to v. -func (o *OptOneOfMappingReferenceBData) SetTo(v OneOfMappingReferenceBData) { - o.Set = true - o.Value = v -} - -// Get returns value and boolean that denotes whether value was set. -func (o OptOneOfMappingReferenceBData) Get() (v OneOfMappingReferenceBData, ok bool) { - if !o.Set { - return v, false - } - return o.Value, true -} - -// Or returns value if set, or given parameter if does not. -func (o OptOneOfMappingReferenceBData) Or(d OneOfMappingReferenceBData) OneOfMappingReferenceBData { - if v, ok := o.Get(); ok { - return v - } - return d -} - // NewOptOneOfUUIDAndIntEnum returns new OptOneOfUUIDAndIntEnum with value set to v. func NewOptOneOfUUIDAndIntEnum(v OneOfUUIDAndIntEnum) OptOneOfUUIDAndIntEnum { return OptOneOfUUIDAndIntEnum{ diff --git a/internal/integration/sample_api_nsnc/oas_json_gen.go b/internal/integration/sample_api_nsnc/oas_json_gen.go index 2240bf44a..be3fdeb67 100644 --- a/internal/integration/sample_api_nsnc/oas_json_gen.go +++ b/internal/integration/sample_api_nsnc/oas_json_gen.go @@ -4859,7 +4859,7 @@ func (s OneOfMappingReference) encodeFields(e *jx.Encoder) { } } { - if s.Data.Set { + if s.Data != nil { e.FieldStart("data") s.Data.Encode(e) } @@ -5058,7 +5058,7 @@ func (s *OneOfMappingReferenceB) encodeFields(e *jx.Encoder) { } } { - if s.Data.Set { + if s.Data != nil { e.FieldStart("data") s.Data.Encode(e) } @@ -5108,10 +5108,12 @@ func (s *OneOfMappingReferenceB) Decode(d *jx.Decoder) error { } case "data": if err := func() error { - s.Data.Reset() - if err := s.Data.Decode(d); err != nil { + s.Data = nil + var elem OneOfMappingReferenceBData + if err := elem.Decode(d); err != nil { return err } + s.Data = &elem return nil }(); err != nil { return errors.Wrap(err, "decode field \"data\"") @@ -5151,43 +5153,29 @@ func (s *OneOfMappingReferenceB) UnmarshalJSON(data []byte) error { } // Encode implements json.Marshaler. -func (s OneOfMappingReferenceBData) Encode(e *jx.Encoder) { +func (s *OneOfMappingReferenceBData) Encode(e *jx.Encoder) { e.ObjStart() s.encodeFields(e) e.ObjEnd() } -// encodeFields implements json.Marshaler. -func (s OneOfMappingReferenceBData) encodeFields(e *jx.Encoder) { - for k, elem := range s { - e.FieldStart(k) - - if len(elem) != 0 { - e.Raw(elem) - } - } +// encodeFields encodes fields. +func (s *OneOfMappingReferenceBData) encodeFields(e *jx.Encoder) { } +var jsonFieldsNameOfOneOfMappingReferenceBData = [0]string{} + // Decode decodes OneOfMappingReferenceBData from json. func (s *OneOfMappingReferenceBData) Decode(d *jx.Decoder) error { if s == nil { return errors.New("invalid: unable to decode OneOfMappingReferenceBData to nil") } - m := s.init() + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { - var elem jx.Raw - if err := func() error { - v, err := d.RawAppend(nil) - elem = jx.Raw(v) - if err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrapf(err, "decode field %q", k) + switch string(k) { + default: + return d.Skip() } - m[string(k)] = elem - return nil }); err != nil { return errors.Wrap(err, "decode OneOfMappingReferenceBData") } @@ -5196,7 +5184,7 @@ func (s *OneOfMappingReferenceBData) Decode(d *jx.Decoder) error { } // MarshalJSON implements stdjson.Marshaler. -func (s OneOfMappingReferenceBData) MarshalJSON() ([]byte, error) { +func (s *OneOfMappingReferenceBData) MarshalJSON() ([]byte, error) { e := jx.Encoder{} s.Encode(&e) return e.Bytes(), nil @@ -6999,40 +6987,6 @@ func (s *OptOneOfMappingReference) UnmarshalJSON(data []byte) error { return s.Decode(d) } -// Encode encodes OneOfMappingReferenceBData as json. -func (o OptOneOfMappingReferenceBData) Encode(e *jx.Encoder) { - if !o.Set { - return - } - o.Value.Encode(e) -} - -// Decode decodes OneOfMappingReferenceBData from json. -func (o *OptOneOfMappingReferenceBData) Decode(d *jx.Decoder) error { - if o == nil { - return errors.New("invalid: unable to decode OptOneOfMappingReferenceBData to nil") - } - o.Set = true - o.Value = make(OneOfMappingReferenceBData) - if err := o.Value.Decode(d); err != nil { - return err - } - return nil -} - -// MarshalJSON implements stdjson.Marshaler. -func (s OptOneOfMappingReferenceBData) MarshalJSON() ([]byte, error) { - e := jx.Encoder{} - s.Encode(&e) - return e.Bytes(), nil -} - -// UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptOneOfMappingReferenceBData) UnmarshalJSON(data []byte) error { - d := jx.DecodeBytes(data) - return s.Decode(d) -} - // Encode encodes OneOfUUIDAndIntEnum as json. func (o OptOneOfUUIDAndIntEnum) Encode(e *jx.Encoder) { if !o.Set { diff --git a/internal/integration/sample_api_nsnc/oas_schemas_gen.go b/internal/integration/sample_api_nsnc/oas_schemas_gen.go index ee5b1423c..6856cbbd0 100644 --- a/internal/integration/sample_api_nsnc/oas_schemas_gen.go +++ b/internal/integration/sample_api_nsnc/oas_schemas_gen.go @@ -2373,10 +2373,10 @@ func (s *OneOfMappingReferenceA) SetDescription(val OptString) { // Ref: #/components/schemas/OneOfMappingReferenceB type OneOfMappingReferenceB struct { - InfoType OptString `json:"infoType"` - Code OptInt32 `json:"code"` - Data OptOneOfMappingReferenceBData `json:"data"` - Info OptString `json:"info"` + InfoType OptString `json:"infoType"` + Code OptInt32 `json:"code"` + Data *OneOfMappingReferenceBData `json:"data"` + Info OptString `json:"info"` } // GetInfoType returns the value of InfoType. @@ -2390,7 +2390,7 @@ func (s *OneOfMappingReferenceB) GetCode() OptInt32 { } // GetData returns the value of Data. -func (s *OneOfMappingReferenceB) GetData() OptOneOfMappingReferenceBData { +func (s *OneOfMappingReferenceB) GetData() *OneOfMappingReferenceBData { return s.Data } @@ -2410,7 +2410,7 @@ func (s *OneOfMappingReferenceB) SetCode(val OptInt32) { } // SetData sets the value of Data. -func (s *OneOfMappingReferenceB) SetData(val OptOneOfMappingReferenceBData) { +func (s *OneOfMappingReferenceB) SetData(val *OneOfMappingReferenceBData) { s.Data = val } @@ -2419,16 +2419,7 @@ func (s *OneOfMappingReferenceB) SetInfo(val OptString) { s.Info = val } -type OneOfMappingReferenceBData map[string]jx.Raw - -func (s *OneOfMappingReferenceBData) init() OneOfMappingReferenceBData { - m := *s - if m == nil { - m = map[string]jx.Raw{} - *s = m - } - return m -} +type OneOfMappingReferenceBData struct{} // Ref: #/components/schemas/OneOfNullables // OneOfNullables represents sum type. @@ -4253,52 +4244,6 @@ func (o OptOneOfMappingReference) Or(d OneOfMappingReference) OneOfMappingRefere return d } -// NewOptOneOfMappingReferenceBData returns new OptOneOfMappingReferenceBData with value set to v. -func NewOptOneOfMappingReferenceBData(v OneOfMappingReferenceBData) OptOneOfMappingReferenceBData { - return OptOneOfMappingReferenceBData{ - Value: v, - Set: true, - } -} - -// OptOneOfMappingReferenceBData is optional OneOfMappingReferenceBData. -type OptOneOfMappingReferenceBData struct { - Value OneOfMappingReferenceBData - Set bool -} - -// IsSet returns true if OptOneOfMappingReferenceBData was set. -func (o OptOneOfMappingReferenceBData) IsSet() bool { return o.Set } - -// Reset unsets value. -func (o *OptOneOfMappingReferenceBData) Reset() { - var v OneOfMappingReferenceBData - o.Value = v - o.Set = false -} - -// SetTo sets value to v. -func (o *OptOneOfMappingReferenceBData) SetTo(v OneOfMappingReferenceBData) { - o.Set = true - o.Value = v -} - -// Get returns value and boolean that denotes whether value was set. -func (o OptOneOfMappingReferenceBData) Get() (v OneOfMappingReferenceBData, ok bool) { - if !o.Set { - return v, false - } - return o.Value, true -} - -// Or returns value if set, or given parameter if does not. -func (o OptOneOfMappingReferenceBData) Or(d OneOfMappingReferenceBData) OneOfMappingReferenceBData { - if v, ok := o.Get(); ok { - return v - } - return d -} - // NewOptOneOfUUIDAndIntEnum returns new OptOneOfUUIDAndIntEnum with value set to v. func NewOptOneOfUUIDAndIntEnum(v OneOfUUIDAndIntEnum) OptOneOfUUIDAndIntEnum { return OptOneOfUUIDAndIntEnum{ From 31300cd2d9a16b98c4923807d3ef38c77a9d0fd7 Mon Sep 17 00:00:00 2001 From: tdakkota Date: Wed, 12 Jun 2024 00:32:49 +0300 Subject: [PATCH 4/4] test: add regression test for issue 1255 --- _testdata/positive/issue1255.yaml | 51 +++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 _testdata/positive/issue1255.yaml diff --git a/_testdata/positive/issue1255.yaml b/_testdata/positive/issue1255.yaml new file mode 100644 index 000000000..575ee0afd --- /dev/null +++ b/_testdata/positive/issue1255.yaml @@ -0,0 +1,51 @@ +openapi: 3.0.3 +info: + title: API + version: 0.1.0 +paths: + /test: + get: + operationId: test + responses: + "200": + description: Teste + content: + application/json: + schema: + $ref: "#/components/schemas/HistoryEntry" +components: + schemas: + HistoryEntry: + description: "Properties common for each entry in the scaling history." + type: object + oneOf: + - $ref: "#/components/schemas/HistoryErrorEntry" + - $ref: "#/components/schemas/HistoryIgnoreEntry" + - $ref: "#/components/schemas/HistorySuccessEntry" + properties: + message: + type: string + description: Textual information about the scaling event. + example: app + HistoryErrorEntry: + description: Description of a failed scaling even in history. + type: object + properties: + error: + type: string + description: | + In case the scaling failed, the reason is provided in this field. + example: failed to compute new app instances + HistoryIgnoreEntry: + description: Description of an ignored scaling event in history. + type: object + properties: + ignore_reason: + type: string + description: | + In case the scaling was ignored, the reason is provided in this field. + example: app in cooldown period + HistorySuccessEntry: + description: Description of a successful scaling event event in history. + type: object + properties: {} # No extra fields needed in this variant