diff --git a/internal/converter/gnostic/convertions.go b/internal/converter/gnostic/convertions.go index 6b558e3..f067c13 100644 --- a/internal/converter/gnostic/convertions.go +++ b/internal/converter/gnostic/convertions.go @@ -360,13 +360,16 @@ func toMediaTypes(items *goa3.MediaTypes) *orderedmap.Map[string, *v3.MediaType] } content := orderedmap.New[string, *v3.MediaType]() for _, item := range items.GetAdditionalProperties() { - content.Set(item.Name, &v3.MediaType{ + mt := &v3.MediaType{ Schema: toSchemaOrReference(item.Value.Schema), - Example: item.Value.Example.ToRawInfo(), Examples: toExamples(item.Value.GetExamples()), Encoding: toEncodings(item.Value.GetEncoding()), Extensions: toExtensions(item.Value.GetSpecificationExtension()), - }) + } + if val := item.GetValue().Example; val != nil { + mt.Example = val.ToRawInfo() + } + content.Set(item.Name, mt) } return content } @@ -403,7 +406,11 @@ func toHeaders(v *goa3.HeadersOrReferences) *orderedmap.Map[string, *v3.Header] func toCodes(responses []*goa3.NamedResponseOrReference) *orderedmap.Map[string, *v3.Response] { resps := orderedmap.New[string, *v3.Response]() for _, resp := range responses { - resps.Set(resp.Name, toResponse(resp.Value.GetResponse())) + switch tt := resp.GetValue().Oneof.(type) { + case *goa3.ResponseOrReference_Reference: + case *goa3.ResponseOrReference_Response: + resps.Set(resp.Name, toResponse(tt.Response)) + } } return resps } diff --git a/internal/converter/gnostic/paths.go b/internal/converter/gnostic/paths.go index b922003..6b55bbc 100644 --- a/internal/converter/gnostic/paths.go +++ b/internal/converter/gnostic/paths.go @@ -34,7 +34,16 @@ func PathItemWithMethodAnnotations(item *v3.PathItem, md protoreflect.MethodDesc } if opts.Responses != nil { - oper.Responses = toResponses(opts.Responses) + responses := toResponses(opts.Responses) + for pair := responses.Codes.First(); pair != nil; pair = pair.Next() { + oper.Responses.Codes.Set(pair.Key(), pair.Value()) + } + if responses.Default != nil { + oper.Responses.Default = responses.Default + } + for pair := responses.Extensions.First(); pair != nil; pair = pair.Next() { + oper.Responses.Extensions.Set(pair.Key(), pair.Value()) + } } if opts.Callbacks != nil { diff --git a/internal/converter/testdata/fileset.binpb b/internal/converter/testdata/fileset.binpb index 14124e0..faa69c2 100644 Binary files a/internal/converter/testdata/fileset.binpb and b/internal/converter/testdata/fileset.binpb differ diff --git a/internal/converter/testdata/standard/gnostic.proto b/internal/converter/testdata/standard/gnostic.proto index e2f172e..178e61e 100644 --- a/internal/converter/testdata/standard/gnostic.proto +++ b/internal/converter/testdata/standard/gnostic.proto @@ -42,6 +42,26 @@ service Greeter { rpc SayHello(HelloRequest) returns (HelloReply) { option idempotency_level = NO_SIDE_EFFECTS; option (gnostic.openapi.v3.operation) = { + responses: { + response_or_reference: { + name: "404" + value: { + response: { + description: "user is not found" + content: { + additional_properties: { + name: "application/json" + value: { + schema: { + reference: {_ref: "#/components/schemas/connect.error"} + } + } + } + } + } + } + } + } deprecated: true security: [ { diff --git a/internal/converter/testdata/standard/output/gnostic.openapi.json b/internal/converter/testdata/standard/output/gnostic.openapi.json index 8003fa8..a4e5526 100644 --- a/internal/converter/testdata/standard/output/gnostic.openapi.json +++ b/internal/converter/testdata/standard/output/gnostic.openapi.json @@ -115,6 +115,16 @@ } } } + }, + "404": { + "description": "user is not found", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/connect.error" + } + } + } } }, "deprecated": true, @@ -178,6 +188,16 @@ } } } + }, + "404": { + "description": "user is not found", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/connect.error" + } + } + } } }, "deprecated": true, diff --git a/internal/converter/testdata/standard/output/gnostic.openapi.yaml b/internal/converter/testdata/standard/output/gnostic.openapi.yaml index 317eff2..4f8ea16 100644 --- a/internal/converter/testdata/standard/output/gnostic.openapi.yaml +++ b/internal/converter/testdata/standard/output/gnostic.openapi.yaml @@ -71,6 +71,12 @@ paths: application/json: schema: $ref: '#/components/schemas/example_with_gnostic.HelloReply' + "404": + description: user is not found + content: + application/json: + schema: + $ref: '#/components/schemas/connect.error' deprecated: true security: - BasicAuth: [] @@ -109,6 +115,12 @@ paths: application/json: schema: $ref: '#/components/schemas/example_with_gnostic.HelloReply' + "404": + description: user is not found + content: + application/json: + schema: + $ref: '#/components/schemas/connect.error' deprecated: true security: - BasicAuth: []