Skip to content

Commit

Permalink
Adding coditions to handle when response, http method is incorrect
Browse files Browse the repository at this point in the history
  • Loading branch information
bsneha90TW committed Jul 31, 2017
1 parent d559185 commit 6e2a327
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/swagger/parser/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
public class Constants {

public static final String INCORRECT_PATH = "Path not found in specification";

public static final String INCORRECT_HTTP_MTHHOD ="HTTP method is inccorect" ;
public static final String INCORRECT_HTTP_MTHHOD ="HTTP method is incorrect" ;
public static final String INCORRECT_RESPONSE_TYPE ="Response type is incorrect" ;
}
6 changes: 4 additions & 2 deletions src/main/java/com/swagger/parser/SwaggerSchemaParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ public class SwaggerSchemaParser {
private Swagger swagger;
private SwaggerParser swaggerParser;
private HashMap<String, JsonNode> parsedSchema;
private HashMap<String, HashMap<String, JsonNode>> parsedSchemaPerResponseType = new HashMap<>();
ObjectMapper mapper = new ObjectMapper();
private HashMap<String, HashMap<String, JsonNode>> parsedSchemaPerResponseType;
ObjectMapper mapper;
SwaggerParserHelper swaggerParserHelper;
String swaggerJsonUrl;

public void initializeParser(String swaggerJsonUrl) {
parsedSchemaPerResponseType = new HashMap<>();
mapper = new ObjectMapper();
this.swaggerJsonUrl = swaggerJsonUrl;
swaggerParser = new SwaggerParser();
swagger = swaggerParser.read(swaggerJsonUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ public SwaggerResponseSchema parseReponseForGivenPathHTTPMethodAndResponseType(S
HashMap<String, SwaggerSchema> swaggerStructurePerReponseType = new HashMap<>();
Path swaggerPath = swagger.getPaths().get(path);
SwaggerResponseSchema swaggerResponseSchema = new SwaggerResponseSchema();
if(swaggerPath==null){
if (swaggerPath == null) {
swaggerResponseSchema.setErrorMessage(Constants.INCORRECT_PATH);
return swaggerResponseSchema;
}
Operation httpOperation = swaggerPath.getOperationMap().get(httpMethod);
if(httpOperation ==null){
if (httpOperation == null) {
swaggerResponseSchema.setErrorMessage(Constants.INCORRECT_HTTP_MTHHOD);
return swaggerResponseSchema;
}
Map<String, Response> responses = httpOperation.getResponses();
Map<String, Response> responses = httpOperation.getResponses();
if (ResponseType.All == responseType) {
responses.forEach((responseCode, response) -> {
SwaggerSchema swaggerStructureForReponse = null;
Expand All @@ -63,7 +63,12 @@ public SwaggerResponseSchema parseReponseForGivenPathHTTPMethodAndResponseType(S
String responseCode = responseType.getCodeValue();
SwaggerSchema swaggerStructureForReponse = null;
try {
swaggerStructureForReponse = getSchemaStructureFromResponse(responses.get(responseCode));
Response response = responses.get(responseCode);
if (response == null) {
swaggerResponseSchema.setErrorMessage(Constants.INCORRECT_RESPONSE_TYPE);
return swaggerResponseSchema;
}
swaggerStructureForReponse = getSchemaStructureFromResponse(response);
} catch (IOException e) {
e.printStackTrace();
}
Expand Down

0 comments on commit 6e2a327

Please sign in to comment.