Skip to content

Respect charsets in JSON content types#1294

Closed
christiannicola wants to merge 1 commit intooapi-codegen:masterfrom
christiannicola:json-support-charset
Closed

Respect charsets in JSON content types#1294
christiannicola wants to merge 1 commit intooapi-codegen:masterfrom
christiannicola:json-support-charset

Conversation

@christiannicola
Copy link
Copy Markdown

This commit fixes an issue with the codegeneration - when specifying a charset in a JSON content type, the resulting request / response bodies are missing the JSON serializer.

The charset is usually redundant, since JSON should usually be encoded using UTF-8 (see https://www.rfc-editor.org/rfc/rfc8259#section-8.1), however there are some code generators out there that do not honor this (for example: OpenAPITools/openapi-generator#12797)

This commit fixes an issue with the codegeneration - when specifying a
charset in a JSON content type, the resulting request / response bodies
are missing the JSON serializer.

The charset is usually redundant, since JSON should usually be encoded
using UTF-8 (see https://www.rfc-editor.org/rfc/rfc8259#section-8.1),
however there are some code generators out there that do not honor this
(for example: OpenAPITools/openapi-generator#12797)
@jamietanna
Copy link
Copy Markdown
Member

Just to confirm, why are we needing to add this? Because some code generators default to adding the charset so we want to make sure this aligns?

Or because you're integrating this project with a generator that adds the charset and therefore can't interact with this?

This may make sense (for some of this) to be an opt-in feature in a compatability option, but let's see

@christiannicola
Copy link
Copy Markdown
Author

@jamietanna The code generation does not correctly handle a content type like application/json; charset=utf8 - The generated source code returns structs without the JSON serializer.

That alone would be an improvement.

Defining a charset for JSON request / response bodies is usually redundant, since JSON should be encoded using UTF-8 anyway, but it is a valid approach for defining JSON payloads within an OpenAPI schema.

@jamietanna
Copy link
Copy Markdown
Member

Gotcha, thanks for confirming!

@jamietanna
Copy link
Copy Markdown
Member

Hey @christiannicola apologies for the delay on this one, this will now be handled correctly due to #1385 🚀

@jamietanna jamietanna closed this Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants