From 34afe31c09d809a6abc0fd04b3d27ebc947defdc Mon Sep 17 00:00:00 2001 From: tdakkota Date: Tue, 10 Sep 2024 16:12:52 +0300 Subject: [PATCH] chore: commit generated files --- examples/ex_openai/oas_json_gen.go | 4 + .../integration/sample_api/oas_client_gen.go | 74 ++++++++ .../integration/sample_api/oas_faker_gen.go | 32 ++++ .../sample_api/oas_handlers_gen.go | 91 +++++++++ .../integration/sample_api/oas_json_gen.go | 175 ++++++++++++++++++ .../sample_api/oas_response_decoders_gen.go | 41 ++++ .../sample_api/oas_response_encoders_gen.go | 14 ++ .../integration/sample_api/oas_router_gen.go | 122 +++++++++--- .../integration/sample_api/oas_schemas_gen.go | 91 +++++++++ .../integration/sample_api/oas_server_gen.go | 4 + .../sample_api/oas_test_examples_gen_test.go | 24 +++ .../sample_api/oas_unimplemented_gen.go | 7 + .../sample_api_nc/oas_handlers_gen.go | 91 +++++++++ .../integration/sample_api_nc/oas_json_gen.go | 175 ++++++++++++++++++ .../oas_response_encoders_gen.go | 14 ++ .../sample_api_nc/oas_router_gen.go | 122 +++++++++--- .../sample_api_nc/oas_schemas_gen.go | 91 +++++++++ .../sample_api_nc/oas_server_gen.go | 4 + .../sample_api_nc/oas_unimplemented_gen.go | 7 + .../sample_api_no_otel/oas_client_gen.go | 38 ++++ .../sample_api_no_otel/oas_handlers_gen.go | 58 ++++++ .../sample_api_no_otel/oas_json_gen.go | 175 ++++++++++++++++++ .../oas_response_decoders_gen.go | 41 ++++ .../oas_response_encoders_gen.go | 13 ++ .../sample_api_no_otel/oas_router_gen.go | 122 +++++++++--- .../sample_api_no_otel/oas_schemas_gen.go | 91 +++++++++ .../sample_api_no_otel/oas_server_gen.go | 4 + .../oas_unimplemented_gen.go | 7 + .../sample_api_ns/oas_client_gen.go | 74 ++++++++ .../integration/sample_api_ns/oas_json_gen.go | 175 ++++++++++++++++++ .../oas_response_decoders_gen.go | 41 ++++ .../sample_api_ns/oas_schemas_gen.go | 91 +++++++++ .../sample_api_nsnc/oas_json_gen.go | 175 ++++++++++++++++++ .../sample_api_nsnc/oas_schemas_gen.go | 91 +++++++++ 34 files changed, 2310 insertions(+), 69 deletions(-) diff --git a/examples/ex_openai/oas_json_gen.go b/examples/ex_openai/oas_json_gen.go index 86457d2a2..ce6186961 100644 --- a/examples/ex_openai/oas_json_gen.go +++ b/examples/ex_openai/oas_json_gen.go @@ -8225,6 +8225,7 @@ func (o *OptCreateAnswerRequestLogitBias) Decode(d *jx.Decoder) error { return errors.New("invalid: unable to decode OptCreateAnswerRequestLogitBias to nil") } o.Set = true + o.Value = new(CreateAnswerRequestLogitBias) if err := o.Value.Decode(d); err != nil { return err } @@ -8258,6 +8259,7 @@ func (o *OptCreateChatCompletionRequestLogitBias) Decode(d *jx.Decoder) error { return errors.New("invalid: unable to decode OptCreateChatCompletionRequestLogitBias to nil") } o.Set = true + o.Value = new(CreateChatCompletionRequestLogitBias) if err := o.Value.Decode(d); err != nil { return err } @@ -8324,6 +8326,7 @@ func (o *OptCreateClassificationRequestLogitBias) Decode(d *jx.Decoder) error { return errors.New("invalid: unable to decode OptCreateClassificationRequestLogitBias to nil") } o.Set = true + o.Value = new(CreateClassificationRequestLogitBias) if err := o.Value.Decode(d); err != nil { return err } @@ -8357,6 +8360,7 @@ func (o *OptCreateCompletionRequestLogitBias) Decode(d *jx.Decoder) error { return errors.New("invalid: unable to decode OptCreateCompletionRequestLogitBias to nil") } o.Set = true + o.Value = new(CreateCompletionRequestLogitBias) if err := o.Value.Decode(d); err != nil { return err } diff --git a/internal/integration/sample_api/oas_client_gen.go b/internal/integration/sample_api/oas_client_gen.go index fa5e73a30..3458c856d 100644 --- a/internal/integration/sample_api/oas_client_gen.go +++ b/internal/integration/sample_api/oas_client_gen.go @@ -153,6 +153,10 @@ type Invoker interface { // // GET /testInlineOneof TestInlineOneof(ctx context.Context) (*TestInlineOneOf, error) + // TestIssue1310 invokes testIssue1310 operation. + // + // GET /testIssue1310 + TestIssue1310(ctx context.Context) (*Issue1310, error) // TestNullableOneofs invokes testNullableOneofs operation. // // GET /testNullableOneofs @@ -2545,6 +2549,76 @@ func (c *Client) sendTestInlineOneof(ctx context.Context) (res *TestInlineOneOf, return result, nil } +// TestIssue1310 invokes testIssue1310 operation. +// +// GET /testIssue1310 +func (c *Client) TestIssue1310(ctx context.Context) (*Issue1310, error) { + res, err := c.sendTestIssue1310(ctx) + return res, err +} + +func (c *Client) sendTestIssue1310(ctx context.Context) (res *Issue1310, err error) { + otelAttrs := []attribute.KeyValue{ + otelogen.OperationID("testIssue1310"), + semconv.HTTPRequestMethodKey.String("GET"), + semconv.HTTPRouteKey.String("/testIssue1310"), + } + + // 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, "TestIssue1310", + 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] = "/testIssue1310" + 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 := decodeTestIssue1310Response(resp) + if err != nil { + return res, errors.Wrap(err, "decode response") + } + + return result, nil +} + // TestNullableOneofs invokes testNullableOneofs operation. // // GET /testNullableOneofs diff --git a/internal/integration/sample_api/oas_faker_gen.go b/internal/integration/sample_api/oas_faker_gen.go index 01da7ed48..8ede2dc6c 100644 --- a/internal/integration/sample_api/oas_faker_gen.go +++ b/internal/integration/sample_api/oas_faker_gen.go @@ -355,6 +355,29 @@ func (s *InlineUniqueFieldsOneOfSum) SetFake() { s.SetInlineOneOfFoo(variant) } +// SetFake set fake values. +func (s *Issue1310) SetFake() { + { + { + s.Title.SetFake() + } + } + { + { + s.Details.SetFake() + } + } + { + { + s.Properties.SetFake() + } + } +} + +// SetFake set fake values. +func (s *Issue1310Properties) SetFake() { +} + // SetFake set fake values. func (s *Issue143) SetFake() { var variant Issue1430 @@ -1060,6 +1083,15 @@ func (s *OptInt32) SetFake() { s.SetTo(elem) } +// SetFake set fake values. +func (s *OptIssue1310Properties) SetFake() { + var elem *Issue1310Properties + { // Keep pointer nil to prevent infinite recursion. + elem = nil + } + s.SetTo(elem) +} + // SetFake set fake values. func (s *OptIssue943) SetFake() { var elem Issue943 diff --git a/internal/integration/sample_api/oas_handlers_gen.go b/internal/integration/sample_api/oas_handlers_gen.go index 37e682779..dd160d324 100644 --- a/internal/integration/sample_api/oas_handlers_gen.go +++ b/internal/integration/sample_api/oas_handlers_gen.go @@ -2817,6 +2817,97 @@ func (s *Server) handleTestInlineOneofRequest(args [0]string, argsEscaped bool, } } +// handleTestIssue1310Request handles testIssue1310 operation. +// +// GET /testIssue1310 +func (s *Server) handleTestIssue1310Request(args [0]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) { + otelAttrs := []attribute.KeyValue{ + otelogen.OperationID("testIssue1310"), + semconv.HTTPRequestMethodKey.String("GET"), + semconv.HTTPRouteKey.String("/testIssue1310"), + } + + // Start a span for this request. + ctx, span := s.cfg.Tracer.Start(r.Context(), "TestIssue1310", + 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 *Issue1310 + if m := s.cfg.Middleware; m != nil { + mreq := middleware.Request{ + Context: ctx, + OperationName: "TestIssue1310", + OperationSummary: "", + OperationID: "testIssue1310", + Body: nil, + Params: middleware.Parameters{}, + Raw: r, + } + + type ( + Request = struct{} + Params = struct{} + Response = *Issue1310 + ) + 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.TestIssue1310(ctx) + return response, err + }, + ) + } else { + response, err = s.h.TestIssue1310(ctx) + } + if err != nil { + defer recordError("Internal", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + + if err := encodeTestIssue1310Response(response, w, span); err != nil { + defer recordError("EncodeResponse", err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } + return + } +} + // handleTestNullableOneofsRequest handles testNullableOneofs operation. // // GET /testNullableOneofs diff --git a/internal/integration/sample_api/oas_json_gen.go b/internal/integration/sample_api/oas_json_gen.go index be3fdeb67..e93e727fa 100644 --- a/internal/integration/sample_api/oas_json_gen.go +++ b/internal/integration/sample_api/oas_json_gen.go @@ -1995,6 +1995,147 @@ func (s *InlineUniqueFieldsOneOfSum) UnmarshalJSON(data []byte) error { return s.Decode(d) } +// Encode implements json.Marshaler. +func (s *Issue1310) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *Issue1310) encodeFields(e *jx.Encoder) { + { + if s.Title.Set { + e.FieldStart("title") + s.Title.Encode(e) + } + } + { + if s.Details.Set { + e.FieldStart("details") + s.Details.Encode(e) + } + } + { + if s.Properties.Set { + e.FieldStart("properties") + s.Properties.Encode(e) + } + } +} + +var jsonFieldsNameOfIssue1310 = [3]string{ + 0: "title", + 1: "details", + 2: "properties", +} + +// Decode decodes Issue1310 from json. +func (s *Issue1310) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode Issue1310 to nil") + } + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + case "title": + if err := func() error { + s.Title.Reset() + if err := s.Title.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"title\"") + } + case "details": + if err := func() error { + s.Details.Reset() + if err := s.Details.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"details\"") + } + case "properties": + if err := func() error { + s.Properties.Reset() + if err := s.Properties.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"properties\"") + } + default: + return d.Skip() + } + return nil + }); err != nil { + return errors.Wrap(err, "decode Issue1310") + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *Issue1310) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *Issue1310) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode implements json.Marshaler. +func (s *Issue1310Properties) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *Issue1310Properties) encodeFields(e *jx.Encoder) { +} + +var jsonFieldsNameOfIssue1310Properties = [0]string{} + +// Decode decodes Issue1310Properties from json. +func (s *Issue1310Properties) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode Issue1310Properties to nil") + } + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + default: + return d.Skip() + } + }); err != nil { + return errors.Wrap(err, "decode Issue1310Properties") + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *Issue1310Properties) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *Issue1310Properties) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + // Encode encodes Issue143 as json. func (s Issue143) Encode(e *jx.Encoder) { switch s.Type { @@ -6575,6 +6716,40 @@ func (s *OptInt32) UnmarshalJSON(data []byte) error { return s.Decode(d) } +// Encode encodes *Issue1310Properties as json. +func (o OptIssue1310Properties) Encode(e *jx.Encoder) { + if !o.Set { + return + } + o.Value.Encode(e) +} + +// Decode decodes *Issue1310Properties from json. +func (o *OptIssue1310Properties) Decode(d *jx.Decoder) error { + if o == nil { + return errors.New("invalid: unable to decode OptIssue1310Properties to nil") + } + o.Set = true + o.Value = new(Issue1310Properties) + if err := o.Value.Decode(d); err != nil { + return err + } + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s OptIssue1310Properties) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *OptIssue1310Properties) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + // Encode encodes Issue943 as json. func (o OptIssue943) Encode(e *jx.Encoder) { if !o.Set { diff --git a/internal/integration/sample_api/oas_response_decoders_gen.go b/internal/integration/sample_api/oas_response_decoders_gen.go index 4f3915a85..9204a09e2 100644 --- a/internal/integration/sample_api/oas_response_decoders_gen.go +++ b/internal/integration/sample_api/oas_response_decoders_gen.go @@ -1185,6 +1185,47 @@ func decodeTestInlineOneofResponse(resp *http.Response) (res *TestInlineOneOf, _ return res, validate.UnexpectedStatusCode(resp.StatusCode) } +func decodeTestIssue1310Response(resp *http.Response) (res *Issue1310, _ error) { + switch resp.StatusCode { + case 200: + // Code 200. + 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 Issue1310 + 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 &response, nil + default: + return res, validate.InvalidContentType(ct) + } + } + return res, validate.UnexpectedStatusCode(resp.StatusCode) +} + func decodeTestNullableOneofsResponse(resp *http.Response) (res TestNullableOneofsRes, _ error) { switch resp.StatusCode { case 200: diff --git a/internal/integration/sample_api/oas_response_encoders_gen.go b/internal/integration/sample_api/oas_response_encoders_gen.go index e4c65da5d..0b7bb8a82 100644 --- a/internal/integration/sample_api/oas_response_encoders_gen.go +++ b/internal/integration/sample_api/oas_response_encoders_gen.go @@ -645,6 +645,20 @@ func encodeTestInlineOneofResponse(response *TestInlineOneOf, w http.ResponseWri return nil } +func encodeTestIssue1310Response(response *Issue1310, 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)) + + e := new(jx.Encoder) + response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil +} + func encodeTestNullableOneofsResponse(response TestNullableOneofsRes, w http.ResponseWriter, span trace.Span) error { switch response := response.(type) { case *TestNullableOneofsOK: diff --git a/internal/integration/sample_api/oas_router_gen.go b/internal/integration/sample_api/oas_router_gen.go index 33e3eb847..9587c8995 100644 --- a/internal/integration/sample_api/oas_router_gen.go +++ b/internal/integration/sample_api/oas_router_gen.go @@ -724,24 +724,60 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { } elem = origElem - case 'I': // Prefix: "InlineOneof" + case 'I': // Prefix: "I" origElem := elem - if l := len("InlineOneof"); len(elem) >= l && elem[0:l] == "InlineOneof" { + if l := len("I"); len(elem) >= l && elem[0:l] == "I" { elem = elem[l:] } else { break } if len(elem) == 0 { - // Leaf node. - switch r.Method { - case "GET": - s.handleTestInlineOneofRequest([0]string{}, elemIsEscaped, w, r) - default: - s.notAllowed(w, r, "GET") + break + } + switch elem[0] { + case 'n': // Prefix: "nlineOneof" + origElem := elem + if l := len("nlineOneof"); len(elem) >= l && elem[0:l] == "nlineOneof" { + elem = elem[l:] + } else { + break } - return + if len(elem) == 0 { + // Leaf node. + switch r.Method { + case "GET": + s.handleTestInlineOneofRequest([0]string{}, elemIsEscaped, w, r) + default: + s.notAllowed(w, r, "GET") + } + + return + } + + elem = origElem + case 's': // Prefix: "ssue1310" + origElem := elem + if l := len("ssue1310"); len(elem) >= l && elem[0:l] == "ssue1310" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch r.Method { + case "GET": + s.handleTestIssue1310Request([0]string{}, elemIsEscaped, w, r) + default: + s.notAllowed(w, r, "GET") + } + + return + } + + elem = origElem } elem = origElem @@ -1685,28 +1721,68 @@ func (s *Server) FindPath(method string, u *url.URL) (r Route, _ bool) { } elem = origElem - case 'I': // Prefix: "InlineOneof" + case 'I': // Prefix: "I" origElem := elem - if l := len("InlineOneof"); len(elem) >= l && elem[0:l] == "InlineOneof" { + if l := len("I"); len(elem) >= l && elem[0:l] == "I" { elem = elem[l:] } else { break } if len(elem) == 0 { - // Leaf node. - switch method { - case "GET": - r.name = "TestInlineOneof" - r.summary = "" - r.operationID = "testInlineOneof" - r.pathPattern = "/testInlineOneof" - r.args = args - r.count = 0 - return r, true - default: - return + break + } + switch elem[0] { + case 'n': // Prefix: "nlineOneof" + origElem := elem + if l := len("nlineOneof"); len(elem) >= l && elem[0:l] == "nlineOneof" { + elem = elem[l:] + } else { + break } + + if len(elem) == 0 { + // Leaf node. + switch method { + case "GET": + r.name = "TestInlineOneof" + r.summary = "" + r.operationID = "testInlineOneof" + r.pathPattern = "/testInlineOneof" + r.args = args + r.count = 0 + return r, true + default: + return + } + } + + elem = origElem + case 's': // Prefix: "ssue1310" + origElem := elem + if l := len("ssue1310"); len(elem) >= l && elem[0:l] == "ssue1310" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch method { + case "GET": + r.name = "TestIssue1310" + r.summary = "" + r.operationID = "testIssue1310" + r.pathPattern = "/testIssue1310" + r.args = args + r.count = 0 + return r, true + default: + return + } + } + + elem = origElem } elem = origElem diff --git a/internal/integration/sample_api/oas_schemas_gen.go b/internal/integration/sample_api/oas_schemas_gen.go index 6856cbbd0..f6724fba0 100644 --- a/internal/integration/sample_api/oas_schemas_gen.go +++ b/internal/integration/sample_api/oas_schemas_gen.go @@ -911,6 +911,51 @@ func NewInlineOneOfBarInlineUniqueFieldsOneOfSum(v InlineOneOfBar) InlineUniqueF return s } +// An API error. +// Ref: #/components/schemas/Issue1310 +type Issue1310 struct { + // A short, human-readable summary of the problem type. This value should not change between + // occurrences of the error. + Title OptString `json:"title"` + // A human-readable explanation specific to this occurrence of the problem. + Details OptString `json:"details"` + // Optional map of properties. + Properties OptIssue1310Properties `json:"properties"` +} + +// GetTitle returns the value of Title. +func (s *Issue1310) GetTitle() OptString { + return s.Title +} + +// GetDetails returns the value of Details. +func (s *Issue1310) GetDetails() OptString { + return s.Details +} + +// GetProperties returns the value of Properties. +func (s *Issue1310) GetProperties() OptIssue1310Properties { + return s.Properties +} + +// SetTitle sets the value of Title. +func (s *Issue1310) SetTitle(val OptString) { + s.Title = val +} + +// SetDetails sets the value of Details. +func (s *Issue1310) SetDetails(val OptString) { + s.Details = val +} + +// SetProperties sets the value of Properties. +func (s *Issue1310) SetProperties(val OptIssue1310Properties) { + s.Properties = val +} + +// Optional map of properties. +type Issue1310Properties struct{} + // Ref: #/components/schemas/Issue143 // Issue143 represents sum type. type Issue143 struct { @@ -3704,6 +3749,52 @@ func (o OptInt32) Or(d int32) int32 { return d } +// NewOptIssue1310Properties returns new OptIssue1310Properties with value set to v. +func NewOptIssue1310Properties(v *Issue1310Properties) OptIssue1310Properties { + return OptIssue1310Properties{ + Value: v, + Set: true, + } +} + +// OptIssue1310Properties is optional *Issue1310Properties. +type OptIssue1310Properties struct { + Value *Issue1310Properties + Set bool +} + +// IsSet returns true if OptIssue1310Properties was set. +func (o OptIssue1310Properties) IsSet() bool { return o.Set } + +// Reset unsets value. +func (o *OptIssue1310Properties) Reset() { + var v *Issue1310Properties + o.Value = v + o.Set = false +} + +// SetTo sets value to v. +func (o *OptIssue1310Properties) SetTo(v *Issue1310Properties) { + o.Set = true + o.Value = v +} + +// Get returns value and boolean that denotes whether value was set. +func (o OptIssue1310Properties) Get() (v *Issue1310Properties, 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 OptIssue1310Properties) Or(d *Issue1310Properties) *Issue1310Properties { + if v, ok := o.Get(); ok { + return v + } + return d +} + // NewOptIssue943 returns new OptIssue943 with value set to v. func NewOptIssue943(v Issue943) OptIssue943 { return OptIssue943{ diff --git a/internal/integration/sample_api/oas_server_gen.go b/internal/integration/sample_api/oas_server_gen.go index 0d0f1661f..ae6cc1a30 100644 --- a/internal/integration/sample_api/oas_server_gen.go +++ b/internal/integration/sample_api/oas_server_gen.go @@ -136,6 +136,10 @@ type Handler interface { // // GET /testInlineOneof TestInlineOneof(ctx context.Context) (*TestInlineOneOf, error) + // TestIssue1310 implements testIssue1310 operation. + // + // GET /testIssue1310 + TestIssue1310(ctx context.Context) (*Issue1310, error) // TestNullableOneofs implements testNullableOneofs operation. // // GET /testNullableOneofs 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 be1228716..0caa9297d 100644 --- a/internal/integration/sample_api/oas_test_examples_gen_test.go +++ b/internal/integration/sample_api/oas_test_examples_gen_test.go @@ -217,6 +217,30 @@ func TestInlineUniqueFieldsOneOfSum_EncodeDecode(t *testing.T) { var typ2 InlineUniqueFieldsOneOfSum require.NoError(t, typ2.Decode(jx.DecodeBytes(data))) } +func TestIssue1310_EncodeDecode(t *testing.T) { + var typ Issue1310 + typ.SetFake() + + e := jx.Encoder{} + typ.Encode(&e) + data := e.Bytes() + require.True(t, std.Valid(data), "Encoded: %s", data) + + var typ2 Issue1310 + require.NoError(t, typ2.Decode(jx.DecodeBytes(data))) +} +func TestIssue1310Properties_EncodeDecode(t *testing.T) { + var typ Issue1310Properties + typ.SetFake() + + e := jx.Encoder{} + typ.Encode(&e) + data := e.Bytes() + require.True(t, std.Valid(data), "Encoded: %s", data) + + var typ2 Issue1310Properties + require.NoError(t, typ2.Decode(jx.DecodeBytes(data))) +} func TestIssue143_EncodeDecode(t *testing.T) { var typ Issue143 typ.SetFake() diff --git a/internal/integration/sample_api/oas_unimplemented_gen.go b/internal/integration/sample_api/oas_unimplemented_gen.go index 0e76e9b88..1d27ef04f 100644 --- a/internal/integration/sample_api/oas_unimplemented_gen.go +++ b/internal/integration/sample_api/oas_unimplemented_gen.go @@ -219,6 +219,13 @@ func (UnimplementedHandler) TestInlineOneof(ctx context.Context) (r *TestInlineO return r, ht.ErrNotImplemented } +// TestIssue1310 implements testIssue1310 operation. +// +// GET /testIssue1310 +func (UnimplementedHandler) TestIssue1310(ctx context.Context) (r *Issue1310, _ error) { + return r, ht.ErrNotImplemented +} + // TestNullableOneofs implements testNullableOneofs operation. // // GET /testNullableOneofs diff --git a/internal/integration/sample_api_nc/oas_handlers_gen.go b/internal/integration/sample_api_nc/oas_handlers_gen.go index 37e682779..dd160d324 100644 --- a/internal/integration/sample_api_nc/oas_handlers_gen.go +++ b/internal/integration/sample_api_nc/oas_handlers_gen.go @@ -2817,6 +2817,97 @@ func (s *Server) handleTestInlineOneofRequest(args [0]string, argsEscaped bool, } } +// handleTestIssue1310Request handles testIssue1310 operation. +// +// GET /testIssue1310 +func (s *Server) handleTestIssue1310Request(args [0]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) { + otelAttrs := []attribute.KeyValue{ + otelogen.OperationID("testIssue1310"), + semconv.HTTPRequestMethodKey.String("GET"), + semconv.HTTPRouteKey.String("/testIssue1310"), + } + + // Start a span for this request. + ctx, span := s.cfg.Tracer.Start(r.Context(), "TestIssue1310", + 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 *Issue1310 + if m := s.cfg.Middleware; m != nil { + mreq := middleware.Request{ + Context: ctx, + OperationName: "TestIssue1310", + OperationSummary: "", + OperationID: "testIssue1310", + Body: nil, + Params: middleware.Parameters{}, + Raw: r, + } + + type ( + Request = struct{} + Params = struct{} + Response = *Issue1310 + ) + 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.TestIssue1310(ctx) + return response, err + }, + ) + } else { + response, err = s.h.TestIssue1310(ctx) + } + if err != nil { + defer recordError("Internal", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + + if err := encodeTestIssue1310Response(response, w, span); err != nil { + defer recordError("EncodeResponse", err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } + return + } +} + // handleTestNullableOneofsRequest handles testNullableOneofs operation. // // GET /testNullableOneofs diff --git a/internal/integration/sample_api_nc/oas_json_gen.go b/internal/integration/sample_api_nc/oas_json_gen.go index be3fdeb67..e93e727fa 100644 --- a/internal/integration/sample_api_nc/oas_json_gen.go +++ b/internal/integration/sample_api_nc/oas_json_gen.go @@ -1995,6 +1995,147 @@ func (s *InlineUniqueFieldsOneOfSum) UnmarshalJSON(data []byte) error { return s.Decode(d) } +// Encode implements json.Marshaler. +func (s *Issue1310) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *Issue1310) encodeFields(e *jx.Encoder) { + { + if s.Title.Set { + e.FieldStart("title") + s.Title.Encode(e) + } + } + { + if s.Details.Set { + e.FieldStart("details") + s.Details.Encode(e) + } + } + { + if s.Properties.Set { + e.FieldStart("properties") + s.Properties.Encode(e) + } + } +} + +var jsonFieldsNameOfIssue1310 = [3]string{ + 0: "title", + 1: "details", + 2: "properties", +} + +// Decode decodes Issue1310 from json. +func (s *Issue1310) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode Issue1310 to nil") + } + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + case "title": + if err := func() error { + s.Title.Reset() + if err := s.Title.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"title\"") + } + case "details": + if err := func() error { + s.Details.Reset() + if err := s.Details.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"details\"") + } + case "properties": + if err := func() error { + s.Properties.Reset() + if err := s.Properties.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"properties\"") + } + default: + return d.Skip() + } + return nil + }); err != nil { + return errors.Wrap(err, "decode Issue1310") + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *Issue1310) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *Issue1310) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode implements json.Marshaler. +func (s *Issue1310Properties) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *Issue1310Properties) encodeFields(e *jx.Encoder) { +} + +var jsonFieldsNameOfIssue1310Properties = [0]string{} + +// Decode decodes Issue1310Properties from json. +func (s *Issue1310Properties) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode Issue1310Properties to nil") + } + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + default: + return d.Skip() + } + }); err != nil { + return errors.Wrap(err, "decode Issue1310Properties") + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *Issue1310Properties) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *Issue1310Properties) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + // Encode encodes Issue143 as json. func (s Issue143) Encode(e *jx.Encoder) { switch s.Type { @@ -6575,6 +6716,40 @@ func (s *OptInt32) UnmarshalJSON(data []byte) error { return s.Decode(d) } +// Encode encodes *Issue1310Properties as json. +func (o OptIssue1310Properties) Encode(e *jx.Encoder) { + if !o.Set { + return + } + o.Value.Encode(e) +} + +// Decode decodes *Issue1310Properties from json. +func (o *OptIssue1310Properties) Decode(d *jx.Decoder) error { + if o == nil { + return errors.New("invalid: unable to decode OptIssue1310Properties to nil") + } + o.Set = true + o.Value = new(Issue1310Properties) + if err := o.Value.Decode(d); err != nil { + return err + } + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s OptIssue1310Properties) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *OptIssue1310Properties) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + // Encode encodes Issue943 as json. func (o OptIssue943) Encode(e *jx.Encoder) { if !o.Set { diff --git a/internal/integration/sample_api_nc/oas_response_encoders_gen.go b/internal/integration/sample_api_nc/oas_response_encoders_gen.go index e11fed8ff..17838470c 100644 --- a/internal/integration/sample_api_nc/oas_response_encoders_gen.go +++ b/internal/integration/sample_api_nc/oas_response_encoders_gen.go @@ -589,6 +589,20 @@ func encodeTestInlineOneofResponse(response *TestInlineOneOf, w http.ResponseWri return nil } +func encodeTestIssue1310Response(response *Issue1310, 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)) + + e := new(jx.Encoder) + response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil +} + func encodeTestNullableOneofsResponse(response TestNullableOneofsRes, w http.ResponseWriter, span trace.Span) error { switch response := response.(type) { case *TestNullableOneofsOK: diff --git a/internal/integration/sample_api_nc/oas_router_gen.go b/internal/integration/sample_api_nc/oas_router_gen.go index 33e3eb847..9587c8995 100644 --- a/internal/integration/sample_api_nc/oas_router_gen.go +++ b/internal/integration/sample_api_nc/oas_router_gen.go @@ -724,24 +724,60 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { } elem = origElem - case 'I': // Prefix: "InlineOneof" + case 'I': // Prefix: "I" origElem := elem - if l := len("InlineOneof"); len(elem) >= l && elem[0:l] == "InlineOneof" { + if l := len("I"); len(elem) >= l && elem[0:l] == "I" { elem = elem[l:] } else { break } if len(elem) == 0 { - // Leaf node. - switch r.Method { - case "GET": - s.handleTestInlineOneofRequest([0]string{}, elemIsEscaped, w, r) - default: - s.notAllowed(w, r, "GET") + break + } + switch elem[0] { + case 'n': // Prefix: "nlineOneof" + origElem := elem + if l := len("nlineOneof"); len(elem) >= l && elem[0:l] == "nlineOneof" { + elem = elem[l:] + } else { + break } - return + if len(elem) == 0 { + // Leaf node. + switch r.Method { + case "GET": + s.handleTestInlineOneofRequest([0]string{}, elemIsEscaped, w, r) + default: + s.notAllowed(w, r, "GET") + } + + return + } + + elem = origElem + case 's': // Prefix: "ssue1310" + origElem := elem + if l := len("ssue1310"); len(elem) >= l && elem[0:l] == "ssue1310" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch r.Method { + case "GET": + s.handleTestIssue1310Request([0]string{}, elemIsEscaped, w, r) + default: + s.notAllowed(w, r, "GET") + } + + return + } + + elem = origElem } elem = origElem @@ -1685,28 +1721,68 @@ func (s *Server) FindPath(method string, u *url.URL) (r Route, _ bool) { } elem = origElem - case 'I': // Prefix: "InlineOneof" + case 'I': // Prefix: "I" origElem := elem - if l := len("InlineOneof"); len(elem) >= l && elem[0:l] == "InlineOneof" { + if l := len("I"); len(elem) >= l && elem[0:l] == "I" { elem = elem[l:] } else { break } if len(elem) == 0 { - // Leaf node. - switch method { - case "GET": - r.name = "TestInlineOneof" - r.summary = "" - r.operationID = "testInlineOneof" - r.pathPattern = "/testInlineOneof" - r.args = args - r.count = 0 - return r, true - default: - return + break + } + switch elem[0] { + case 'n': // Prefix: "nlineOneof" + origElem := elem + if l := len("nlineOneof"); len(elem) >= l && elem[0:l] == "nlineOneof" { + elem = elem[l:] + } else { + break } + + if len(elem) == 0 { + // Leaf node. + switch method { + case "GET": + r.name = "TestInlineOneof" + r.summary = "" + r.operationID = "testInlineOneof" + r.pathPattern = "/testInlineOneof" + r.args = args + r.count = 0 + return r, true + default: + return + } + } + + elem = origElem + case 's': // Prefix: "ssue1310" + origElem := elem + if l := len("ssue1310"); len(elem) >= l && elem[0:l] == "ssue1310" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch method { + case "GET": + r.name = "TestIssue1310" + r.summary = "" + r.operationID = "testIssue1310" + r.pathPattern = "/testIssue1310" + r.args = args + r.count = 0 + return r, true + default: + return + } + } + + elem = origElem } elem = origElem diff --git a/internal/integration/sample_api_nc/oas_schemas_gen.go b/internal/integration/sample_api_nc/oas_schemas_gen.go index 6856cbbd0..f6724fba0 100644 --- a/internal/integration/sample_api_nc/oas_schemas_gen.go +++ b/internal/integration/sample_api_nc/oas_schemas_gen.go @@ -911,6 +911,51 @@ func NewInlineOneOfBarInlineUniqueFieldsOneOfSum(v InlineOneOfBar) InlineUniqueF return s } +// An API error. +// Ref: #/components/schemas/Issue1310 +type Issue1310 struct { + // A short, human-readable summary of the problem type. This value should not change between + // occurrences of the error. + Title OptString `json:"title"` + // A human-readable explanation specific to this occurrence of the problem. + Details OptString `json:"details"` + // Optional map of properties. + Properties OptIssue1310Properties `json:"properties"` +} + +// GetTitle returns the value of Title. +func (s *Issue1310) GetTitle() OptString { + return s.Title +} + +// GetDetails returns the value of Details. +func (s *Issue1310) GetDetails() OptString { + return s.Details +} + +// GetProperties returns the value of Properties. +func (s *Issue1310) GetProperties() OptIssue1310Properties { + return s.Properties +} + +// SetTitle sets the value of Title. +func (s *Issue1310) SetTitle(val OptString) { + s.Title = val +} + +// SetDetails sets the value of Details. +func (s *Issue1310) SetDetails(val OptString) { + s.Details = val +} + +// SetProperties sets the value of Properties. +func (s *Issue1310) SetProperties(val OptIssue1310Properties) { + s.Properties = val +} + +// Optional map of properties. +type Issue1310Properties struct{} + // Ref: #/components/schemas/Issue143 // Issue143 represents sum type. type Issue143 struct { @@ -3704,6 +3749,52 @@ func (o OptInt32) Or(d int32) int32 { return d } +// NewOptIssue1310Properties returns new OptIssue1310Properties with value set to v. +func NewOptIssue1310Properties(v *Issue1310Properties) OptIssue1310Properties { + return OptIssue1310Properties{ + Value: v, + Set: true, + } +} + +// OptIssue1310Properties is optional *Issue1310Properties. +type OptIssue1310Properties struct { + Value *Issue1310Properties + Set bool +} + +// IsSet returns true if OptIssue1310Properties was set. +func (o OptIssue1310Properties) IsSet() bool { return o.Set } + +// Reset unsets value. +func (o *OptIssue1310Properties) Reset() { + var v *Issue1310Properties + o.Value = v + o.Set = false +} + +// SetTo sets value to v. +func (o *OptIssue1310Properties) SetTo(v *Issue1310Properties) { + o.Set = true + o.Value = v +} + +// Get returns value and boolean that denotes whether value was set. +func (o OptIssue1310Properties) Get() (v *Issue1310Properties, 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 OptIssue1310Properties) Or(d *Issue1310Properties) *Issue1310Properties { + if v, ok := o.Get(); ok { + return v + } + return d +} + // NewOptIssue943 returns new OptIssue943 with value set to v. func NewOptIssue943(v Issue943) OptIssue943 { return OptIssue943{ diff --git a/internal/integration/sample_api_nc/oas_server_gen.go b/internal/integration/sample_api_nc/oas_server_gen.go index 0d0f1661f..ae6cc1a30 100644 --- a/internal/integration/sample_api_nc/oas_server_gen.go +++ b/internal/integration/sample_api_nc/oas_server_gen.go @@ -136,6 +136,10 @@ type Handler interface { // // GET /testInlineOneof TestInlineOneof(ctx context.Context) (*TestInlineOneOf, error) + // TestIssue1310 implements testIssue1310 operation. + // + // GET /testIssue1310 + TestIssue1310(ctx context.Context) (*Issue1310, error) // TestNullableOneofs implements testNullableOneofs operation. // // GET /testNullableOneofs diff --git a/internal/integration/sample_api_nc/oas_unimplemented_gen.go b/internal/integration/sample_api_nc/oas_unimplemented_gen.go index 0e76e9b88..1d27ef04f 100644 --- a/internal/integration/sample_api_nc/oas_unimplemented_gen.go +++ b/internal/integration/sample_api_nc/oas_unimplemented_gen.go @@ -219,6 +219,13 @@ func (UnimplementedHandler) TestInlineOneof(ctx context.Context) (r *TestInlineO return r, ht.ErrNotImplemented } +// TestIssue1310 implements testIssue1310 operation. +// +// GET /testIssue1310 +func (UnimplementedHandler) TestIssue1310(ctx context.Context) (r *Issue1310, _ error) { + return r, ht.ErrNotImplemented +} + // TestNullableOneofs implements testNullableOneofs operation. // // GET /testNullableOneofs diff --git a/internal/integration/sample_api_no_otel/oas_client_gen.go b/internal/integration/sample_api_no_otel/oas_client_gen.go index ebfe9f788..c89176a8a 100644 --- a/internal/integration/sample_api_no_otel/oas_client_gen.go +++ b/internal/integration/sample_api_no_otel/oas_client_gen.go @@ -145,6 +145,10 @@ type Invoker interface { // // GET /testInlineOneof TestInlineOneof(ctx context.Context) (*TestInlineOneOf, error) + // TestIssue1310 invokes testIssue1310 operation. + // + // GET /testIssue1310 + TestIssue1310(ctx context.Context) (*Issue1310, error) // TestNullableOneofs invokes testNullableOneofs operation. // // GET /testNullableOneofs @@ -1503,6 +1507,40 @@ func (c *Client) sendTestInlineOneof(ctx context.Context) (res *TestInlineOneOf, return result, nil } +// TestIssue1310 invokes testIssue1310 operation. +// +// GET /testIssue1310 +func (c *Client) TestIssue1310(ctx context.Context) (*Issue1310, error) { + res, err := c.sendTestIssue1310(ctx) + return res, err +} + +func (c *Client) sendTestIssue1310(ctx context.Context) (res *Issue1310, err error) { + + u := uri.Clone(c.requestURL(ctx)) + var pathParts [1]string + pathParts[0] = "/testIssue1310" + uri.AddPathParts(u, pathParts[:]...) + + r, err := ht.NewRequest(ctx, "GET", u) + if err != nil { + return res, errors.Wrap(err, "create request") + } + + resp, err := c.cfg.Client.Do(r) + if err != nil { + return res, errors.Wrap(err, "do request") + } + defer resp.Body.Close() + + result, err := decodeTestIssue1310Response(resp) + if err != nil { + return res, errors.Wrap(err, "decode response") + } + + return result, nil +} + // TestNullableOneofs invokes testNullableOneofs operation. // // GET /testNullableOneofs diff --git a/internal/integration/sample_api_no_otel/oas_handlers_gen.go b/internal/integration/sample_api_no_otel/oas_handlers_gen.go index a4bc47696..ac7bcf793 100644 --- a/internal/integration/sample_api_no_otel/oas_handlers_gen.go +++ b/internal/integration/sample_api_no_otel/oas_handlers_gen.go @@ -1961,6 +1961,64 @@ func (s *Server) handleTestInlineOneofRequest(args [0]string, argsEscaped bool, } } +// handleTestIssue1310Request handles testIssue1310 operation. +// +// GET /testIssue1310 +func (s *Server) handleTestIssue1310Request(args [0]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) { + ctx := r.Context() + + var ( + err error + ) + + var response *Issue1310 + if m := s.cfg.Middleware; m != nil { + mreq := middleware.Request{ + Context: ctx, + OperationName: "TestIssue1310", + OperationSummary: "", + OperationID: "testIssue1310", + Body: nil, + Params: middleware.Parameters{}, + Raw: r, + } + + type ( + Request = struct{} + Params = struct{} + Response = *Issue1310 + ) + 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.TestIssue1310(ctx) + return response, err + }, + ) + } else { + response, err = s.h.TestIssue1310(ctx) + } + if err != nil { + defer recordError("Internal", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + + if err := encodeTestIssue1310Response(response, w); err != nil { + defer recordError("EncodeResponse", err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } + return + } +} + // handleTestNullableOneofsRequest handles testNullableOneofs operation. // // GET /testNullableOneofs 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 be3fdeb67..e93e727fa 100644 --- a/internal/integration/sample_api_no_otel/oas_json_gen.go +++ b/internal/integration/sample_api_no_otel/oas_json_gen.go @@ -1995,6 +1995,147 @@ func (s *InlineUniqueFieldsOneOfSum) UnmarshalJSON(data []byte) error { return s.Decode(d) } +// Encode implements json.Marshaler. +func (s *Issue1310) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *Issue1310) encodeFields(e *jx.Encoder) { + { + if s.Title.Set { + e.FieldStart("title") + s.Title.Encode(e) + } + } + { + if s.Details.Set { + e.FieldStart("details") + s.Details.Encode(e) + } + } + { + if s.Properties.Set { + e.FieldStart("properties") + s.Properties.Encode(e) + } + } +} + +var jsonFieldsNameOfIssue1310 = [3]string{ + 0: "title", + 1: "details", + 2: "properties", +} + +// Decode decodes Issue1310 from json. +func (s *Issue1310) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode Issue1310 to nil") + } + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + case "title": + if err := func() error { + s.Title.Reset() + if err := s.Title.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"title\"") + } + case "details": + if err := func() error { + s.Details.Reset() + if err := s.Details.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"details\"") + } + case "properties": + if err := func() error { + s.Properties.Reset() + if err := s.Properties.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"properties\"") + } + default: + return d.Skip() + } + return nil + }); err != nil { + return errors.Wrap(err, "decode Issue1310") + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *Issue1310) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *Issue1310) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode implements json.Marshaler. +func (s *Issue1310Properties) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *Issue1310Properties) encodeFields(e *jx.Encoder) { +} + +var jsonFieldsNameOfIssue1310Properties = [0]string{} + +// Decode decodes Issue1310Properties from json. +func (s *Issue1310Properties) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode Issue1310Properties to nil") + } + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + default: + return d.Skip() + } + }); err != nil { + return errors.Wrap(err, "decode Issue1310Properties") + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *Issue1310Properties) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *Issue1310Properties) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + // Encode encodes Issue143 as json. func (s Issue143) Encode(e *jx.Encoder) { switch s.Type { @@ -6575,6 +6716,40 @@ func (s *OptInt32) UnmarshalJSON(data []byte) error { return s.Decode(d) } +// Encode encodes *Issue1310Properties as json. +func (o OptIssue1310Properties) Encode(e *jx.Encoder) { + if !o.Set { + return + } + o.Value.Encode(e) +} + +// Decode decodes *Issue1310Properties from json. +func (o *OptIssue1310Properties) Decode(d *jx.Decoder) error { + if o == nil { + return errors.New("invalid: unable to decode OptIssue1310Properties to nil") + } + o.Set = true + o.Value = new(Issue1310Properties) + if err := o.Value.Decode(d); err != nil { + return err + } + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s OptIssue1310Properties) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *OptIssue1310Properties) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + // Encode encodes Issue943 as json. func (o OptIssue943) Encode(e *jx.Encoder) { if !o.Set { diff --git a/internal/integration/sample_api_no_otel/oas_response_decoders_gen.go b/internal/integration/sample_api_no_otel/oas_response_decoders_gen.go index 4f3915a85..9204a09e2 100644 --- a/internal/integration/sample_api_no_otel/oas_response_decoders_gen.go +++ b/internal/integration/sample_api_no_otel/oas_response_decoders_gen.go @@ -1185,6 +1185,47 @@ func decodeTestInlineOneofResponse(resp *http.Response) (res *TestInlineOneOf, _ return res, validate.UnexpectedStatusCode(resp.StatusCode) } +func decodeTestIssue1310Response(resp *http.Response) (res *Issue1310, _ error) { + switch resp.StatusCode { + case 200: + // Code 200. + 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 Issue1310 + 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 &response, nil + default: + return res, validate.InvalidContentType(ct) + } + } + return res, validate.UnexpectedStatusCode(resp.StatusCode) +} + func decodeTestNullableOneofsResponse(resp *http.Response) (res TestNullableOneofsRes, _ error) { switch resp.StatusCode { case 200: diff --git a/internal/integration/sample_api_no_otel/oas_response_encoders_gen.go b/internal/integration/sample_api_no_otel/oas_response_encoders_gen.go index 2ec606c86..435446e1f 100644 --- a/internal/integration/sample_api_no_otel/oas_response_encoders_gen.go +++ b/internal/integration/sample_api_no_otel/oas_response_encoders_gen.go @@ -511,6 +511,19 @@ func encodeTestInlineOneofResponse(response *TestInlineOneOf, w http.ResponseWri return nil } +func encodeTestIssue1310Response(response *Issue1310, w http.ResponseWriter) error { + w.Header().Set("Content-Type", "application/json; charset=utf-8") + w.WriteHeader(200) + + e := new(jx.Encoder) + response.Encode(e) + if _, err := e.WriteTo(w); err != nil { + return errors.Wrap(err, "write") + } + + return nil +} + func encodeTestNullableOneofsResponse(response TestNullableOneofsRes, w http.ResponseWriter) error { switch response := response.(type) { case *TestNullableOneofsOK: diff --git a/internal/integration/sample_api_no_otel/oas_router_gen.go b/internal/integration/sample_api_no_otel/oas_router_gen.go index 33e3eb847..9587c8995 100644 --- a/internal/integration/sample_api_no_otel/oas_router_gen.go +++ b/internal/integration/sample_api_no_otel/oas_router_gen.go @@ -724,24 +724,60 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { } elem = origElem - case 'I': // Prefix: "InlineOneof" + case 'I': // Prefix: "I" origElem := elem - if l := len("InlineOneof"); len(elem) >= l && elem[0:l] == "InlineOneof" { + if l := len("I"); len(elem) >= l && elem[0:l] == "I" { elem = elem[l:] } else { break } if len(elem) == 0 { - // Leaf node. - switch r.Method { - case "GET": - s.handleTestInlineOneofRequest([0]string{}, elemIsEscaped, w, r) - default: - s.notAllowed(w, r, "GET") + break + } + switch elem[0] { + case 'n': // Prefix: "nlineOneof" + origElem := elem + if l := len("nlineOneof"); len(elem) >= l && elem[0:l] == "nlineOneof" { + elem = elem[l:] + } else { + break } - return + if len(elem) == 0 { + // Leaf node. + switch r.Method { + case "GET": + s.handleTestInlineOneofRequest([0]string{}, elemIsEscaped, w, r) + default: + s.notAllowed(w, r, "GET") + } + + return + } + + elem = origElem + case 's': // Prefix: "ssue1310" + origElem := elem + if l := len("ssue1310"); len(elem) >= l && elem[0:l] == "ssue1310" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch r.Method { + case "GET": + s.handleTestIssue1310Request([0]string{}, elemIsEscaped, w, r) + default: + s.notAllowed(w, r, "GET") + } + + return + } + + elem = origElem } elem = origElem @@ -1685,28 +1721,68 @@ func (s *Server) FindPath(method string, u *url.URL) (r Route, _ bool) { } elem = origElem - case 'I': // Prefix: "InlineOneof" + case 'I': // Prefix: "I" origElem := elem - if l := len("InlineOneof"); len(elem) >= l && elem[0:l] == "InlineOneof" { + if l := len("I"); len(elem) >= l && elem[0:l] == "I" { elem = elem[l:] } else { break } if len(elem) == 0 { - // Leaf node. - switch method { - case "GET": - r.name = "TestInlineOneof" - r.summary = "" - r.operationID = "testInlineOneof" - r.pathPattern = "/testInlineOneof" - r.args = args - r.count = 0 - return r, true - default: - return + break + } + switch elem[0] { + case 'n': // Prefix: "nlineOneof" + origElem := elem + if l := len("nlineOneof"); len(elem) >= l && elem[0:l] == "nlineOneof" { + elem = elem[l:] + } else { + break } + + if len(elem) == 0 { + // Leaf node. + switch method { + case "GET": + r.name = "TestInlineOneof" + r.summary = "" + r.operationID = "testInlineOneof" + r.pathPattern = "/testInlineOneof" + r.args = args + r.count = 0 + return r, true + default: + return + } + } + + elem = origElem + case 's': // Prefix: "ssue1310" + origElem := elem + if l := len("ssue1310"); len(elem) >= l && elem[0:l] == "ssue1310" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch method { + case "GET": + r.name = "TestIssue1310" + r.summary = "" + r.operationID = "testIssue1310" + r.pathPattern = "/testIssue1310" + r.args = args + r.count = 0 + return r, true + default: + return + } + } + + elem = origElem } elem = origElem 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 6856cbbd0..f6724fba0 100644 --- a/internal/integration/sample_api_no_otel/oas_schemas_gen.go +++ b/internal/integration/sample_api_no_otel/oas_schemas_gen.go @@ -911,6 +911,51 @@ func NewInlineOneOfBarInlineUniqueFieldsOneOfSum(v InlineOneOfBar) InlineUniqueF return s } +// An API error. +// Ref: #/components/schemas/Issue1310 +type Issue1310 struct { + // A short, human-readable summary of the problem type. This value should not change between + // occurrences of the error. + Title OptString `json:"title"` + // A human-readable explanation specific to this occurrence of the problem. + Details OptString `json:"details"` + // Optional map of properties. + Properties OptIssue1310Properties `json:"properties"` +} + +// GetTitle returns the value of Title. +func (s *Issue1310) GetTitle() OptString { + return s.Title +} + +// GetDetails returns the value of Details. +func (s *Issue1310) GetDetails() OptString { + return s.Details +} + +// GetProperties returns the value of Properties. +func (s *Issue1310) GetProperties() OptIssue1310Properties { + return s.Properties +} + +// SetTitle sets the value of Title. +func (s *Issue1310) SetTitle(val OptString) { + s.Title = val +} + +// SetDetails sets the value of Details. +func (s *Issue1310) SetDetails(val OptString) { + s.Details = val +} + +// SetProperties sets the value of Properties. +func (s *Issue1310) SetProperties(val OptIssue1310Properties) { + s.Properties = val +} + +// Optional map of properties. +type Issue1310Properties struct{} + // Ref: #/components/schemas/Issue143 // Issue143 represents sum type. type Issue143 struct { @@ -3704,6 +3749,52 @@ func (o OptInt32) Or(d int32) int32 { return d } +// NewOptIssue1310Properties returns new OptIssue1310Properties with value set to v. +func NewOptIssue1310Properties(v *Issue1310Properties) OptIssue1310Properties { + return OptIssue1310Properties{ + Value: v, + Set: true, + } +} + +// OptIssue1310Properties is optional *Issue1310Properties. +type OptIssue1310Properties struct { + Value *Issue1310Properties + Set bool +} + +// IsSet returns true if OptIssue1310Properties was set. +func (o OptIssue1310Properties) IsSet() bool { return o.Set } + +// Reset unsets value. +func (o *OptIssue1310Properties) Reset() { + var v *Issue1310Properties + o.Value = v + o.Set = false +} + +// SetTo sets value to v. +func (o *OptIssue1310Properties) SetTo(v *Issue1310Properties) { + o.Set = true + o.Value = v +} + +// Get returns value and boolean that denotes whether value was set. +func (o OptIssue1310Properties) Get() (v *Issue1310Properties, 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 OptIssue1310Properties) Or(d *Issue1310Properties) *Issue1310Properties { + if v, ok := o.Get(); ok { + return v + } + return d +} + // NewOptIssue943 returns new OptIssue943 with value set to v. func NewOptIssue943(v Issue943) OptIssue943 { return OptIssue943{ diff --git a/internal/integration/sample_api_no_otel/oas_server_gen.go b/internal/integration/sample_api_no_otel/oas_server_gen.go index 0d0f1661f..ae6cc1a30 100644 --- a/internal/integration/sample_api_no_otel/oas_server_gen.go +++ b/internal/integration/sample_api_no_otel/oas_server_gen.go @@ -136,6 +136,10 @@ type Handler interface { // // GET /testInlineOneof TestInlineOneof(ctx context.Context) (*TestInlineOneOf, error) + // TestIssue1310 implements testIssue1310 operation. + // + // GET /testIssue1310 + TestIssue1310(ctx context.Context) (*Issue1310, error) // TestNullableOneofs implements testNullableOneofs operation. // // GET /testNullableOneofs diff --git a/internal/integration/sample_api_no_otel/oas_unimplemented_gen.go b/internal/integration/sample_api_no_otel/oas_unimplemented_gen.go index 0e76e9b88..1d27ef04f 100644 --- a/internal/integration/sample_api_no_otel/oas_unimplemented_gen.go +++ b/internal/integration/sample_api_no_otel/oas_unimplemented_gen.go @@ -219,6 +219,13 @@ func (UnimplementedHandler) TestInlineOneof(ctx context.Context) (r *TestInlineO return r, ht.ErrNotImplemented } +// TestIssue1310 implements testIssue1310 operation. +// +// GET /testIssue1310 +func (UnimplementedHandler) TestIssue1310(ctx context.Context) (r *Issue1310, _ error) { + return r, ht.ErrNotImplemented +} + // TestNullableOneofs implements testNullableOneofs operation. // // GET /testNullableOneofs diff --git a/internal/integration/sample_api_ns/oas_client_gen.go b/internal/integration/sample_api_ns/oas_client_gen.go index 97a621880..a227d4967 100644 --- a/internal/integration/sample_api_ns/oas_client_gen.go +++ b/internal/integration/sample_api_ns/oas_client_gen.go @@ -152,6 +152,10 @@ type Invoker interface { // // GET /testInlineOneof TestInlineOneof(ctx context.Context) (*TestInlineOneOf, error) + // TestIssue1310 invokes testIssue1310 operation. + // + // GET /testIssue1310 + TestIssue1310(ctx context.Context) (*Issue1310, error) // TestNullableOneofs invokes testNullableOneofs operation. // // GET /testNullableOneofs @@ -2441,6 +2445,76 @@ func (c *Client) sendTestInlineOneof(ctx context.Context) (res *TestInlineOneOf, return result, nil } +// TestIssue1310 invokes testIssue1310 operation. +// +// GET /testIssue1310 +func (c *Client) TestIssue1310(ctx context.Context) (*Issue1310, error) { + res, err := c.sendTestIssue1310(ctx) + return res, err +} + +func (c *Client) sendTestIssue1310(ctx context.Context) (res *Issue1310, err error) { + otelAttrs := []attribute.KeyValue{ + otelogen.OperationID("testIssue1310"), + semconv.HTTPRequestMethodKey.String("GET"), + semconv.HTTPRouteKey.String("/testIssue1310"), + } + + // 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, "TestIssue1310", + 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] = "/testIssue1310" + 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 := decodeTestIssue1310Response(resp) + if err != nil { + return res, errors.Wrap(err, "decode response") + } + + return result, nil +} + // TestNullableOneofs invokes testNullableOneofs operation. // // GET /testNullableOneofs diff --git a/internal/integration/sample_api_ns/oas_json_gen.go b/internal/integration/sample_api_ns/oas_json_gen.go index be3fdeb67..e93e727fa 100644 --- a/internal/integration/sample_api_ns/oas_json_gen.go +++ b/internal/integration/sample_api_ns/oas_json_gen.go @@ -1995,6 +1995,147 @@ func (s *InlineUniqueFieldsOneOfSum) UnmarshalJSON(data []byte) error { return s.Decode(d) } +// Encode implements json.Marshaler. +func (s *Issue1310) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *Issue1310) encodeFields(e *jx.Encoder) { + { + if s.Title.Set { + e.FieldStart("title") + s.Title.Encode(e) + } + } + { + if s.Details.Set { + e.FieldStart("details") + s.Details.Encode(e) + } + } + { + if s.Properties.Set { + e.FieldStart("properties") + s.Properties.Encode(e) + } + } +} + +var jsonFieldsNameOfIssue1310 = [3]string{ + 0: "title", + 1: "details", + 2: "properties", +} + +// Decode decodes Issue1310 from json. +func (s *Issue1310) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode Issue1310 to nil") + } + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + case "title": + if err := func() error { + s.Title.Reset() + if err := s.Title.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"title\"") + } + case "details": + if err := func() error { + s.Details.Reset() + if err := s.Details.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"details\"") + } + case "properties": + if err := func() error { + s.Properties.Reset() + if err := s.Properties.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"properties\"") + } + default: + return d.Skip() + } + return nil + }); err != nil { + return errors.Wrap(err, "decode Issue1310") + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *Issue1310) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *Issue1310) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode implements json.Marshaler. +func (s *Issue1310Properties) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *Issue1310Properties) encodeFields(e *jx.Encoder) { +} + +var jsonFieldsNameOfIssue1310Properties = [0]string{} + +// Decode decodes Issue1310Properties from json. +func (s *Issue1310Properties) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode Issue1310Properties to nil") + } + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + default: + return d.Skip() + } + }); err != nil { + return errors.Wrap(err, "decode Issue1310Properties") + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *Issue1310Properties) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *Issue1310Properties) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + // Encode encodes Issue143 as json. func (s Issue143) Encode(e *jx.Encoder) { switch s.Type { @@ -6575,6 +6716,40 @@ func (s *OptInt32) UnmarshalJSON(data []byte) error { return s.Decode(d) } +// Encode encodes *Issue1310Properties as json. +func (o OptIssue1310Properties) Encode(e *jx.Encoder) { + if !o.Set { + return + } + o.Value.Encode(e) +} + +// Decode decodes *Issue1310Properties from json. +func (o *OptIssue1310Properties) Decode(d *jx.Decoder) error { + if o == nil { + return errors.New("invalid: unable to decode OptIssue1310Properties to nil") + } + o.Set = true + o.Value = new(Issue1310Properties) + if err := o.Value.Decode(d); err != nil { + return err + } + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s OptIssue1310Properties) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *OptIssue1310Properties) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + // Encode encodes Issue943 as json. func (o OptIssue943) Encode(e *jx.Encoder) { if !o.Set { diff --git a/internal/integration/sample_api_ns/oas_response_decoders_gen.go b/internal/integration/sample_api_ns/oas_response_decoders_gen.go index 4f3915a85..9204a09e2 100644 --- a/internal/integration/sample_api_ns/oas_response_decoders_gen.go +++ b/internal/integration/sample_api_ns/oas_response_decoders_gen.go @@ -1185,6 +1185,47 @@ func decodeTestInlineOneofResponse(resp *http.Response) (res *TestInlineOneOf, _ return res, validate.UnexpectedStatusCode(resp.StatusCode) } +func decodeTestIssue1310Response(resp *http.Response) (res *Issue1310, _ error) { + switch resp.StatusCode { + case 200: + // Code 200. + 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 Issue1310 + 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 &response, nil + default: + return res, validate.InvalidContentType(ct) + } + } + return res, validate.UnexpectedStatusCode(resp.StatusCode) +} + func decodeTestNullableOneofsResponse(resp *http.Response) (res TestNullableOneofsRes, _ error) { switch resp.StatusCode { case 200: diff --git a/internal/integration/sample_api_ns/oas_schemas_gen.go b/internal/integration/sample_api_ns/oas_schemas_gen.go index 6856cbbd0..f6724fba0 100644 --- a/internal/integration/sample_api_ns/oas_schemas_gen.go +++ b/internal/integration/sample_api_ns/oas_schemas_gen.go @@ -911,6 +911,51 @@ func NewInlineOneOfBarInlineUniqueFieldsOneOfSum(v InlineOneOfBar) InlineUniqueF return s } +// An API error. +// Ref: #/components/schemas/Issue1310 +type Issue1310 struct { + // A short, human-readable summary of the problem type. This value should not change between + // occurrences of the error. + Title OptString `json:"title"` + // A human-readable explanation specific to this occurrence of the problem. + Details OptString `json:"details"` + // Optional map of properties. + Properties OptIssue1310Properties `json:"properties"` +} + +// GetTitle returns the value of Title. +func (s *Issue1310) GetTitle() OptString { + return s.Title +} + +// GetDetails returns the value of Details. +func (s *Issue1310) GetDetails() OptString { + return s.Details +} + +// GetProperties returns the value of Properties. +func (s *Issue1310) GetProperties() OptIssue1310Properties { + return s.Properties +} + +// SetTitle sets the value of Title. +func (s *Issue1310) SetTitle(val OptString) { + s.Title = val +} + +// SetDetails sets the value of Details. +func (s *Issue1310) SetDetails(val OptString) { + s.Details = val +} + +// SetProperties sets the value of Properties. +func (s *Issue1310) SetProperties(val OptIssue1310Properties) { + s.Properties = val +} + +// Optional map of properties. +type Issue1310Properties struct{} + // Ref: #/components/schemas/Issue143 // Issue143 represents sum type. type Issue143 struct { @@ -3704,6 +3749,52 @@ func (o OptInt32) Or(d int32) int32 { return d } +// NewOptIssue1310Properties returns new OptIssue1310Properties with value set to v. +func NewOptIssue1310Properties(v *Issue1310Properties) OptIssue1310Properties { + return OptIssue1310Properties{ + Value: v, + Set: true, + } +} + +// OptIssue1310Properties is optional *Issue1310Properties. +type OptIssue1310Properties struct { + Value *Issue1310Properties + Set bool +} + +// IsSet returns true if OptIssue1310Properties was set. +func (o OptIssue1310Properties) IsSet() bool { return o.Set } + +// Reset unsets value. +func (o *OptIssue1310Properties) Reset() { + var v *Issue1310Properties + o.Value = v + o.Set = false +} + +// SetTo sets value to v. +func (o *OptIssue1310Properties) SetTo(v *Issue1310Properties) { + o.Set = true + o.Value = v +} + +// Get returns value and boolean that denotes whether value was set. +func (o OptIssue1310Properties) Get() (v *Issue1310Properties, 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 OptIssue1310Properties) Or(d *Issue1310Properties) *Issue1310Properties { + if v, ok := o.Get(); ok { + return v + } + return d +} + // NewOptIssue943 returns new OptIssue943 with value set to v. func NewOptIssue943(v Issue943) OptIssue943 { return OptIssue943{ diff --git a/internal/integration/sample_api_nsnc/oas_json_gen.go b/internal/integration/sample_api_nsnc/oas_json_gen.go index be3fdeb67..e93e727fa 100644 --- a/internal/integration/sample_api_nsnc/oas_json_gen.go +++ b/internal/integration/sample_api_nsnc/oas_json_gen.go @@ -1995,6 +1995,147 @@ func (s *InlineUniqueFieldsOneOfSum) UnmarshalJSON(data []byte) error { return s.Decode(d) } +// Encode implements json.Marshaler. +func (s *Issue1310) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *Issue1310) encodeFields(e *jx.Encoder) { + { + if s.Title.Set { + e.FieldStart("title") + s.Title.Encode(e) + } + } + { + if s.Details.Set { + e.FieldStart("details") + s.Details.Encode(e) + } + } + { + if s.Properties.Set { + e.FieldStart("properties") + s.Properties.Encode(e) + } + } +} + +var jsonFieldsNameOfIssue1310 = [3]string{ + 0: "title", + 1: "details", + 2: "properties", +} + +// Decode decodes Issue1310 from json. +func (s *Issue1310) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode Issue1310 to nil") + } + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + case "title": + if err := func() error { + s.Title.Reset() + if err := s.Title.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"title\"") + } + case "details": + if err := func() error { + s.Details.Reset() + if err := s.Details.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"details\"") + } + case "properties": + if err := func() error { + s.Properties.Reset() + if err := s.Properties.Decode(d); err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"properties\"") + } + default: + return d.Skip() + } + return nil + }); err != nil { + return errors.Wrap(err, "decode Issue1310") + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *Issue1310) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *Issue1310) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + +// Encode implements json.Marshaler. +func (s *Issue1310Properties) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *Issue1310Properties) encodeFields(e *jx.Encoder) { +} + +var jsonFieldsNameOfIssue1310Properties = [0]string{} + +// Decode decodes Issue1310Properties from json. +func (s *Issue1310Properties) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode Issue1310Properties to nil") + } + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + default: + return d.Skip() + } + }); err != nil { + return errors.Wrap(err, "decode Issue1310Properties") + } + + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *Issue1310Properties) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *Issue1310Properties) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + // Encode encodes Issue143 as json. func (s Issue143) Encode(e *jx.Encoder) { switch s.Type { @@ -6575,6 +6716,40 @@ func (s *OptInt32) UnmarshalJSON(data []byte) error { return s.Decode(d) } +// Encode encodes *Issue1310Properties as json. +func (o OptIssue1310Properties) Encode(e *jx.Encoder) { + if !o.Set { + return + } + o.Value.Encode(e) +} + +// Decode decodes *Issue1310Properties from json. +func (o *OptIssue1310Properties) Decode(d *jx.Decoder) error { + if o == nil { + return errors.New("invalid: unable to decode OptIssue1310Properties to nil") + } + o.Set = true + o.Value = new(Issue1310Properties) + if err := o.Value.Decode(d); err != nil { + return err + } + return nil +} + +// MarshalJSON implements stdjson.Marshaler. +func (s OptIssue1310Properties) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *OptIssue1310Properties) UnmarshalJSON(data []byte) error { + d := jx.DecodeBytes(data) + return s.Decode(d) +} + // Encode encodes Issue943 as json. func (o OptIssue943) 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 6856cbbd0..f6724fba0 100644 --- a/internal/integration/sample_api_nsnc/oas_schemas_gen.go +++ b/internal/integration/sample_api_nsnc/oas_schemas_gen.go @@ -911,6 +911,51 @@ func NewInlineOneOfBarInlineUniqueFieldsOneOfSum(v InlineOneOfBar) InlineUniqueF return s } +// An API error. +// Ref: #/components/schemas/Issue1310 +type Issue1310 struct { + // A short, human-readable summary of the problem type. This value should not change between + // occurrences of the error. + Title OptString `json:"title"` + // A human-readable explanation specific to this occurrence of the problem. + Details OptString `json:"details"` + // Optional map of properties. + Properties OptIssue1310Properties `json:"properties"` +} + +// GetTitle returns the value of Title. +func (s *Issue1310) GetTitle() OptString { + return s.Title +} + +// GetDetails returns the value of Details. +func (s *Issue1310) GetDetails() OptString { + return s.Details +} + +// GetProperties returns the value of Properties. +func (s *Issue1310) GetProperties() OptIssue1310Properties { + return s.Properties +} + +// SetTitle sets the value of Title. +func (s *Issue1310) SetTitle(val OptString) { + s.Title = val +} + +// SetDetails sets the value of Details. +func (s *Issue1310) SetDetails(val OptString) { + s.Details = val +} + +// SetProperties sets the value of Properties. +func (s *Issue1310) SetProperties(val OptIssue1310Properties) { + s.Properties = val +} + +// Optional map of properties. +type Issue1310Properties struct{} + // Ref: #/components/schemas/Issue143 // Issue143 represents sum type. type Issue143 struct { @@ -3704,6 +3749,52 @@ func (o OptInt32) Or(d int32) int32 { return d } +// NewOptIssue1310Properties returns new OptIssue1310Properties with value set to v. +func NewOptIssue1310Properties(v *Issue1310Properties) OptIssue1310Properties { + return OptIssue1310Properties{ + Value: v, + Set: true, + } +} + +// OptIssue1310Properties is optional *Issue1310Properties. +type OptIssue1310Properties struct { + Value *Issue1310Properties + Set bool +} + +// IsSet returns true if OptIssue1310Properties was set. +func (o OptIssue1310Properties) IsSet() bool { return o.Set } + +// Reset unsets value. +func (o *OptIssue1310Properties) Reset() { + var v *Issue1310Properties + o.Value = v + o.Set = false +} + +// SetTo sets value to v. +func (o *OptIssue1310Properties) SetTo(v *Issue1310Properties) { + o.Set = true + o.Value = v +} + +// Get returns value and boolean that denotes whether value was set. +func (o OptIssue1310Properties) Get() (v *Issue1310Properties, 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 OptIssue1310Properties) Or(d *Issue1310Properties) *Issue1310Properties { + if v, ok := o.Get(); ok { + return v + } + return d +} + // NewOptIssue943 returns new OptIssue943 with value set to v. func NewOptIssue943(v Issue943) OptIssue943 { return OptIssue943{