Skip to content

Commit f8b92ac

Browse files
authored
Merge pull request #2349 from ChristianCiach/issue2320
Revert pointless commit to fix #2320
2 parents 45000b5 + f5f8392 commit f8b92ac

File tree

4 files changed

+10
-26
lines changed

4 files changed

+10
-26
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.swagger.jaxrs.listing;
22

3-
import com.fasterxml.jackson.core.JsonProcessingException;
43
import io.swagger.annotations.ApiOperation;
54

65
import javax.servlet.ServletConfig;
@@ -26,7 +25,7 @@ public Response getListingJson(
2625
@Context Application app,
2726
@Context ServletConfig sc,
2827
@Context HttpHeaders headers,
29-
@Context UriInfo uriInfo) throws JsonProcessingException {
28+
@Context UriInfo uriInfo) {
3029
return getListingJsonResponse(app, context, sc, headers, uriInfo);
3130
}
3231

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.swagger.jaxrs.listing;
22

3-
import com.fasterxml.jackson.core.JsonProcessingException;
43
import io.swagger.annotations.ApiOperation;
54
import org.apache.commons.lang3.StringUtils;
65

@@ -26,7 +25,7 @@ public Response getListing(
2625
@Context ServletConfig sc,
2726
@Context HttpHeaders headers,
2827
@Context UriInfo uriInfo,
29-
@PathParam("type") String type) throws JsonProcessingException {
28+
@PathParam("type") String type) {
3029
if (StringUtils.isNotBlank(type) && type.trim().equalsIgnoreCase("yaml")) {
3130
return getListingYamlResponse(app, context, sc, headers, uriInfo);
3231
} else {

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

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.swagger.jaxrs.listing;
22

3-
import com.fasterxml.jackson.core.JsonProcessingException;
43
import io.swagger.config.FilterFactory;
54
import io.swagger.config.Scanner;
65
import io.swagger.config.SwaggerConfig;
@@ -11,7 +10,6 @@
1110
import io.swagger.jaxrs.config.ReaderConfigUtils;
1211
import io.swagger.jaxrs.config.SwaggerContextService;
1312
import io.swagger.models.Swagger;
14-
import io.swagger.util.Json;
1513
import io.swagger.util.Yaml;
1614
import org.slf4j.Logger;
1715
import org.slf4j.LoggerFactory;
@@ -141,19 +139,9 @@ protected Response getListingYamlResponse(
141139
HttpHeaders headers,
142140
UriInfo uriInfo) {
143141
Swagger swagger = process(app, servletContext, servletConfig, headers, uriInfo);
144-
try {
145-
if (swagger != null) {
146-
String yaml = Yaml.mapper().writeValueAsString(swagger);
147-
StringBuilder b = new StringBuilder();
148-
String[] parts = yaml.split("\n");
149-
for (String part : parts) {
150-
b.append(part);
151-
b.append("\n");
152-
}
153-
return Response.ok().entity(b.toString()).type("application/yaml").build();
154-
}
155-
} catch (Exception e) {
156-
e.printStackTrace();
142+
143+
if (swagger != null) {
144+
return Response.ok().entity(swagger).type("application/yaml").build();
157145
}
158146
return Response.status(404).build();
159147
}
@@ -163,14 +151,13 @@ protected Response getListingJsonResponse(
163151
ServletContext servletContext,
164152
ServletConfig servletConfig,
165153
HttpHeaders headers,
166-
UriInfo uriInfo) throws JsonProcessingException {
154+
UriInfo uriInfo) {
167155
Swagger swagger = process(app, servletContext, servletConfig, headers, uriInfo);
168156

169157
if (swagger != null) {
170-
return Response.ok().entity(Json.mapper().writeValueAsString(swagger)).type(MediaType.APPLICATION_JSON_TYPE).build();
171-
} else {
172-
return Response.status(404).build();
158+
return Response.ok().entity(swagger).type(MediaType.APPLICATION_JSON).build();
173159
}
160+
return Response.status(404).build();
174161
}
175162

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

modules/swagger-jaxrs/src/test/java/io/swagger/ApiListingResourceTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.swagger;
22

3-
import com.fasterxml.jackson.core.JsonProcessingException;
43
import io.swagger.jaxrs.Reader;
54
import io.swagger.jaxrs.listing.ApiListingResource;
65
import io.swagger.models.Swagger;
@@ -25,7 +24,7 @@ public void shouldCheckModelsSet() {
2524
}
2625

2726
@Test
28-
public void shouldHandleNullServletConfig_issue1689() throws JsonProcessingException {
27+
public void shouldHandleNullServletConfig_issue1689() {
2928
ApiListingResource a = new ApiListingResource();
3029
try {
3130
a.getListing(null, null, null, null, "json");
@@ -39,7 +38,7 @@ public void shouldHandleNullServletConfig_issue1689() throws JsonProcessingExcep
3938

4039
}
4140
@Test
42-
public void shouldHandleErrorServletConfig_issue1691() throws JsonProcessingException {
41+
public void shouldHandleErrorServletConfig_issue1691() {
4342

4443
ServletConfig sc = new ServletConfig() {
4544
@Override

0 commit comments

Comments
 (0)