-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Unify emitter/consumer mediatype filter #2420
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # yaml-language-server: $schema=../../../../configuration-schema.json | ||
| package: issue2389 | ||
| output: api.gen.go | ||
| generate: | ||
| models: true | ||
| client: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| package issue2389 | ||
|
|
||
| //go:generate go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen --config=cfg.yaml spec.yaml |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| package issue2389 | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| // When a components/responses entry exposes the same schema under more than one | ||
| // content type (here application/json + application/xml), the client response | ||
| // wrapper grows one field per content type (JSON500, XML500). The regression in | ||
| // issue #2389 typed those fields as undefined per-content-type names | ||
| // (*ErrorResponseApplicationJSON / *ErrorResponseApplicationXML), so the | ||
| // generated package failed to compile. Both fields must instead point at the | ||
| // single declared component type, ErrorResponse. | ||
| // | ||
| // This test exists primarily to prove the generated package compiles; the | ||
| // assignments below would not type-check if either field had a different (or | ||
| // undefined) type. | ||
| func TestResponseComponentMultipleContentTypesShareDeclaredType(t *testing.T) { | ||
| body := &ErrorResponse{} | ||
|
|
||
| resp := GetThingResponse{ | ||
| JSON500: body, | ||
| XML500: body, | ||
| } | ||
|
|
||
| assert.Same(t, resp.JSON500, resp.XML500) | ||
| } | ||
|
|
||
| // A component response only declares a Go type for its JSON content, so an | ||
| // XML-only component response has no declared base type. The wrapper field must | ||
| // point at the XML content's own schema type (XmlError); pointing at the | ||
| // component base type would reference an undeclared name and fail to compile. | ||
| func TestResponseComponentXMLOnlyUsesContentSchemaType(t *testing.T) { | ||
| resp := GetXMLOnlyResponse{ | ||
| XML500: &XmlError{}, | ||
| } | ||
|
|
||
| assert.NotNil(t, resp.XML500) | ||
| } | ||
|
|
||
| // When the JSON and XML content of a component response resolve to different | ||
| // schemas, the two wrapper fields must keep distinct types: JSON uses the | ||
| // declared component type (MixedError) and XML keeps its own schema type | ||
| // (XmlError). The regression shared the JSON type for both, which would | ||
| // silently decode XML into the JSON-shaped type. These statements would not | ||
| // type-check if the fields shared a type. | ||
| func TestResponseComponentMixedDifferingSchemasKeepDistinctTypes(t *testing.T) { | ||
| resp := GetMixedResponse{ | ||
| JSON500: &MixedError{}, | ||
| XML500: &XmlError{}, | ||
| } | ||
|
|
||
| assert.NotNil(t, resp.JSON500) | ||
| assert.NotNil(t, resp.XML500) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| openapi: "3.0.0" | ||
| info: | ||
| title: issue-2389 | ||
| version: 1.0.0 | ||
| paths: | ||
| /thing: | ||
| get: | ||
| operationId: getThing | ||
| responses: | ||
| "200": | ||
| description: ok | ||
| content: | ||
| application/json: | ||
| schema: | ||
| type: string | ||
| "500": | ||
| $ref: '#/components/responses/error' | ||
| /xml-only: | ||
| get: | ||
| operationId: getXMLOnly | ||
| responses: | ||
| "200": | ||
| description: ok | ||
| content: | ||
| application/json: | ||
| schema: | ||
| type: string | ||
| "500": | ||
| $ref: '#/components/responses/xmlOnlyError' | ||
| /mixed: | ||
| get: | ||
| operationId: getMixed | ||
| responses: | ||
| "200": | ||
| description: ok | ||
| content: | ||
| application/json: | ||
| schema: | ||
| type: string | ||
| "500": | ||
| $ref: '#/components/responses/mixedError' | ||
| components: | ||
| schemas: | ||
| errorResponse: | ||
| type: object | ||
| properties: | ||
| code: | ||
| type: integer | ||
| format: int32 | ||
| message: | ||
| type: string | ||
| jsonError: | ||
| type: object | ||
| properties: | ||
| code: | ||
| type: integer | ||
| xmlError: | ||
| type: object | ||
| properties: | ||
| reason: | ||
| type: string | ||
| responses: | ||
| error: | ||
| description: Error response | ||
| x-go-name: ErrorResponse | ||
| # A single response component exposing the same schema under more than | ||
| # one content type. Both content types must reference the one declared | ||
| # Go type (ErrorResponse); the regression generated undefined | ||
| # per-content-type names (ErrorResponseApplicationJSON / ...XML). | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: '#/components/schemas/errorResponse' | ||
| application/xml: | ||
| schema: | ||
| $ref: '#/components/schemas/errorResponse' | ||
| xmlOnlyError: | ||
| description: XML-only response component | ||
| # No JSON content. GenerateTypesForResponses only declares a Go type for | ||
| # JSON media, so the wrapper field must point at the XML content's own | ||
| # schema type (XmlError), not the (never-declared) component base type. | ||
| content: | ||
| application/xml: | ||
| schema: | ||
| $ref: '#/components/schemas/xmlError' | ||
| mixedError: | ||
| description: JSON and XML content with different schemas | ||
| # The JSON and XML content types resolve to different schemas. The JSON | ||
| # field uses the declared component type; the XML field must keep its own | ||
| # schema type (XmlError) rather than silently decoding XML into the JSON | ||
| # type. | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: '#/components/schemas/jsonError' | ||
| application/xml: | ||
| schema: | ||
| $ref: '#/components/schemas/xmlError' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.