Skip to content

Commit fcce8cc

Browse files
author
bnasslahsen
committed
Syntax highlighting in Swagger-ui can't be configured in Springdoc. Fixes #877.
1 parent c49419f commit fcce8cc

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

springdoc-openapi-common/src/main/java/org/springdoc/ui/AbstractSwaggerIndexTransformer.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
*/
4141
public class AbstractSwaggerIndexTransformer {
4242

43+
private static final String PRESETS = "presets: [";
44+
4345
/**
4446
* The Swagger ui o auth properties.
4547
*/
@@ -165,8 +167,8 @@ protected String addCSRF(String html) {
165167
stringBuilder.append("'] = parts.pop().split(';').shift();\n");
166168
stringBuilder.append("return request;\n");
167169
stringBuilder.append("},\n");
168-
stringBuilder.append("presets: [");
169-
return html.replace("presets: [", stringBuilder.toString());
170+
stringBuilder.append(PRESETS);
171+
return html.replace(PRESETS, stringBuilder.toString());
170172
}
171173

172174
protected String addSyntaxHighlight(String html) {
@@ -184,8 +186,8 @@ protected String addSyntaxHighlight(String html) {
184186
stringBuilder.append("\"");
185187
}
186188
stringBuilder.append("},\n");
187-
stringBuilder.append("presets: [");
188-
return html.replace("presets: [", stringBuilder.toString());
189+
stringBuilder.append(PRESETS);
190+
return html.replace(PRESETS, stringBuilder.toString());
189191
}
190192

191193
}

springdoc-openapi-ui/src/test/java/test/org/springdoc/ui/app12/SpringDocApp12Test.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232

3333
@TestPropertySource(properties = { "springdoc.swagger-ui.syntaxHighlight.activated=false",
3434
"springdoc.swagger-ui.syntaxHighlight.theme=monokai" })
35-
public class SpringDocApp12Test extends AbstractSpringDocTest {
35+
class SpringDocApp12Test extends AbstractSpringDocTest {
3636

3737
@Test
38-
public void transformed_index_with_oauth() throws Exception {
38+
void transformed_index_with_oauth() throws Exception {
3939
MvcResult mvcResult = mockMvc.perform(get("/swagger-ui/index.html")).andExpect(status().isOk()).andReturn();
4040
String transformedIndex = mvcResult.getResponse().getContentAsString();
4141
assertTrue(transformedIndex.contains("Swagger UI"));

0 commit comments

Comments
 (0)