Skip to content

Commit

Permalink
do not split and re-join YAML document
Browse files Browse the repository at this point in the history
This fixes issue swagger-api#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.
  • Loading branch information
christianc committed Aug 3, 2017
1 parent 3bce461 commit f5f8392
Showing 1 changed file with 5 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,9 @@ protected Response getListingYamlResponse(
HttpHeaders headers,
UriInfo uriInfo) {
Swagger swagger = process(app, servletContext, servletConfig, headers, uriInfo);
try {
if (swagger != null) {
String yaml = Yaml.mapper().writeValueAsString(swagger);
StringBuilder b = new StringBuilder();
String[] parts = yaml.split("\n");
for (String part : parts) {
b.append(part);
b.append("\n");
}
return Response.ok().entity(b.toString()).type("application/yaml").build();
}
} catch (Exception e) {
e.printStackTrace();

if (swagger != null) {
return Response.ok().entity(swagger).type("application/yaml").build();
}
return Response.status(404).build();
}
Expand All @@ -165,10 +155,9 @@ protected Response getListingJsonResponse(
Swagger swagger = process(app, servletContext, servletConfig, headers, uriInfo);

if (swagger != null) {
return Response.ok().entity(swagger).build();
} else {
return Response.status(404).build();
return Response.ok().entity(swagger).type(MediaType.APPLICATION_JSON).build();
}
return Response.status(404).build();
}

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

0 comments on commit f5f8392

Please sign in to comment.