Skip to content

Fix: Allow multiple JSON types to be generated#1159

Merged
1 commit merged into
masterfrom
defect/multi-json
Jul 31, 2023
Merged

Fix: Allow multiple JSON types to be generated#1159
1 commit merged into
masterfrom
defect/multi-json

Conversation

@jamietanna

@jamietanna jamietanna commented Jul 31, 2023

Copy link
Copy Markdown
Member

As flagged in #1127, the use of IsMediaTypeJson leads to potentially
having duplicate types generated, leading to compilation errors.

We can instead only generate i.e. CreateWhateverJSONRequestBody for
the application/json type, and then construct a specific type for each
media type with a matching name.

This requires we add a new utility method IsJSON to simplify our
checks, and wire it in in each place that requires we render
JSON-specific code.

Closes #1127.

@jamietanna
jamietanna requested a review from a user July 31, 2023 11:51
@jamietanna
jamietanna marked this pull request as draft July 31, 2023 12:03
@jamietanna
jamietanna force-pushed the defect/multi-json branch 2 times, most recently from 6f1df5d to 911d90a Compare July 31, 2023 13:18
As flagged in #1127, the use of `IsMediaTypeJson` leads to potentially
having duplicate types generated, leading to compilation errors.

We can instead only generate i.e. `CreateWhateverJSONRequestBody` for
the `application/json` type, and then construct a specific type for each
media type with a matching name.

This requires we add a new utility method `IsJSON` to simplify our
checks, and wire it in in each place that requires we render
JSON-specific code.

Closes #1127.
@jamietanna
jamietanna marked this pull request as ready for review July 31, 2023 13:58
@ghost
ghost merged commit b248b1d into master Jul 31, 2023
@jamietanna
jamietanna deleted the defect/multi-json branch July 31, 2023 20:16
debuggerpk pushed a commit to breuHQ/oapi-codegen that referenced this pull request Sep 18, 2023
As flagged in oapi-codegen#1127, the use of `IsMediaTypeJson` leads to potentially
having duplicate types generated, leading to compilation errors.

We can instead only generate i.e. `CreateWhateverJSONRequestBody` for
the `application/json` type, and then construct a specific type for each
media type with a matching name.

This requires we add a new utility method `IsJSON` to simplify our
checks, and wire it in in each place that requires we render
JSON-specific code.

Closes oapi-codegen#1127.
danicc097 pushed a commit to danicc097/oapi-codegen that referenced this pull request Aug 31, 2024
As flagged in oapi-codegen#1127, the use of `IsMediaTypeJson` leads to potentially
having duplicate types generated, leading to compilation errors.

We can instead only generate i.e. `CreateWhateverJSONRequestBody` for
the `application/json` type, and then construct a specific type for each
media type with a matching name.

This requires we add a new utility method `IsJSON` to simplify our
checks, and wire it in in each place that requires we render
JSON-specific code.

Closes oapi-codegen#1127.
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Multiple json content types in a single requestBody or response lead to duplicate types and client interface functions

1 participant