Skip to content

Commit f5f8392

Browse files
author
christianc
committed
do not split and re-join YAML document
This fixes issue #2320 for YAML documents. The original code surprisingly overrides the behavior of SwaggerSerializers.java to needlessly split and join a YAML document. This was originally done to remove some kind of comment line from the YAML, but this has been removed long ago, making split/join-code pointless.
1 parent 3bce461 commit f5f8392

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

modules/swagger-jaxrs/src/main/java/io/swagger/jaxrs/listing/BaseApiListingResource.java

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -139,19 +139,9 @@ protected Response getListingYamlResponse(
139139
HttpHeaders headers,
140140
UriInfo uriInfo) {
141141
Swagger swagger = process(app, servletContext, servletConfig, headers, uriInfo);
142-
try {
143-
if (swagger != null) {
144-
String yaml = Yaml.mapper().writeValueAsString(swagger);
145-
StringBuilder b = new StringBuilder();
146-
String[] parts = yaml.split("\n");
147-
for (String part : parts) {
148-
b.append(part);
149-
b.append("\n");
150-
}
151-
return Response.ok().entity(b.toString()).type("application/yaml").build();
152-
}
153-
} catch (Exception e) {
154-
e.printStackTrace();
142+
143+
if (swagger != null) {
144+
return Response.ok().entity(swagger).type("application/yaml").build();
155145
}
156146
return Response.status(404).build();
157147
}
@@ -165,10 +155,9 @@ protected Response getListingJsonResponse(
165155
Swagger swagger = process(app, servletContext, servletConfig, headers, uriInfo);
166156

167157
if (swagger != null) {
168-
return Response.ok().entity(swagger).build();
169-
} else {
170-
return Response.status(404).build();
158+
return Response.ok().entity(swagger).type(MediaType.APPLICATION_JSON).build();
171159
}
160+
return Response.status(404).build();
172161
}
173162

174163
private static Map<String, List<String>> getQueryParams(MultivaluedMap<String, String> params) {

0 commit comments

Comments
 (0)