Repository navigation
Disable Gson HTML escaping when prettifying generated API docs - #192
Open
mattiagualtieri wants to merge 1 commit into
Open
mattiagualtieri wants to merge 1 commit into
mattiagualtieri wants to merge 1 commit into
Conversation
generateOpenApiDocs always writes its output to a file, never embeds it in HTML/JS, so Gson's default HTML-safe escaping only hurts readability and diffability here: '=' becomes '\u003d', '<' becomes '\u003c', etc. Adds disableHtmlEscaping() to the same GsonBuilder used in prettifyJson(), plus a regression test mirroring the one added for the sibling serializeNulls() fix (springdoc#151). Signed-off-by: mattia.gualtieri <mattia.gualtieri@mollie.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
generateOpenApiDocs'sprettifyJson()re-serializes the fetched API docs response throughGsonBuilder().setPrettyPrinting().serializeNulls().create(). Gson's default HTML-safe escaping means characters like=,<,>get written as\u003d,\u003c,\u003ein the output file.This plugin only ever writes the result to a file on disk — it's never embedded into an HTML page or
<script>tag, which is the only reason Gson enables this escaping by default. It just makes the generated file harder to read and noisier to diff (e.g.application/vnd.oai.openapi;version=3.1.0becomesapplication/vnd.oai.openapi;version\u003d3.1.0).Change: adds
.disableHtmlEscaping()to the sameGsonBuilderchain.Testing: added
HtmlCharactersController(mirroring the existingNullValuesControllerfixture from #151) and a testnot html-escaping special characters in the api docs, following the same pattern askeeping null values in the api docs. Confirmed it fails without the fix and passes with it. Full existing suite still passes.Open question: I went with an unconditional change since there's no real scenario where HTML-escaped JSON is wanted in a file-output tool, and it matches how #151's
serializeNulls()fix was also shipped unconditionally. But if you'd rather not change the default output for existing users, I'm happy to make it opt-in instead (e.g. adisableHtmlEscapingproperty on theopenApi { }extension, defaulting tofalse) — let me know which you'd prefer and I'll update the PR.