Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ open class OpenApiGeneratorTask : DefaultTask() {
}

private fun prettifyJson(response: String): String {
val gson = GsonBuilder().setPrettyPrinting().serializeNulls().create()
val gson = GsonBuilder().setPrettyPrinting().serializeNulls().disableHtmlEscaping().create()
try {
val googleJsonObject = gson.fromJson(response, JsonObject::class.java)
return gson.toJson(googleJsonObject)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,28 @@ class OpenApiGradlePluginTest {
assertTrue(example.containsKey("errorMessage"))
}

@Test
fun `not html-escaping special characters in the api docs`() {
buildFile.writeText(
"""$baseBuildGradle
bootRun {
args = ["--spring.profiles.active=html-characters"]
}
openApi {
apiDocsUrl = "http://localhost:8080/html-characters-api-docs"
}
""".trimMargin()
)

assertEquals(TaskOutcome.SUCCESS, openApiDocsTask(runTheBuild()).outcome)
val rawJson = File(projectBuildDir, DEFAULT_OPEN_API_FILE_NAME).readText()
assertTrue(rawJson.contains("a=b <c> & d"))
assertFalse(rawJson.contains("\\u003d"))
assertFalse(rawJson.contains("\\u003c"))
assertFalse(rawJson.contains("\\u003e"))
assertFalse(rawJson.contains("\\u0026"))
}

@Test
fun `applying the plugin from a script plugin`() {
// The script plugin loads this plugin (and its own Spring Boot plugin classes) in a separate classloader
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.example.demo.endpoints;

import org.springframework.context.annotation.Profile;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@Profile("html-characters")
@RestController
public class HtmlCharactersController {

@GetMapping(value = "/html-characters-api-docs", produces = MediaType.APPLICATION_JSON_VALUE)
public String apiDocs() {
return "{\"openapi\":\"3.0.1\",\"paths\":{\"/\":{\"get\":{\"responses\":{\"200\":{\"description\":"
+ "\"a=b <c> & d\"}}}}}}";
}
}