Skip to content

Commit

Permalink
Fix for issue #1375
Browse files Browse the repository at this point in the history
Empty and blank query parameter examples were parsed to null.
Now they are parsed to an empty and blank string respectively.
  • Loading branch information
mih-kopylov committed May 16, 2020
1 parent 6b9d848 commit a4ba9fb
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1727,10 +1727,7 @@ public Object getAnyExample(String nodeKey,ObjectNode node, String location, Par
JsonNode example = node.get(nodeKey);
if (example != null) {
if (example.getNodeType().equals(JsonNodeType.STRING)) {
String value = getString(nodeKey, node, false, location, result);
if (StringUtils.isNotBlank(value)) {
return value;
}
return getString(nodeKey, node, false, location, result);
} if (example.getNodeType().equals(JsonNodeType.NUMBER)) {
Integer integerExample = getInteger(nodeKey, node, false, location, result);
if (integerExample != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2326,6 +2326,26 @@ public void testIssue1335() {
assertNotNull(result.getOpenAPI().getComponents().getExamples().get("ex1"));
}

@Test
public void testEmptyQueryParameterExample() {
final ParseOptions options = new ParseOptions();
options.setResolve(true);

SwaggerParseResult result = new OpenAPIV3Parser()
.readLocation("src/test/resources/emptyQueryParameter.yaml", null, options);
assertEquals("", result.getOpenAPI().getPaths().get("/foo").getGet().getParameters().get(0).getExample());
}

@Test
public void testBlankQueryParameterExample() {
final ParseOptions options = new ParseOptions();
options.setResolve(true);

SwaggerParseResult result = new OpenAPIV3Parser()
.readLocation("src/test/resources/blankQueryParameter.yaml", null, options);
assertEquals(" ", result.getOpenAPI().getPaths().get("/foo").getGet().getParameters().get(0).getExample());
}

@Test
public void testRegressionIssue1236() {
final ParseOptions options = new ParseOptions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2384,7 +2384,7 @@ public void readContentObject(JsonNode rootNode) throws Exception {
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().get(0).getContent().get("text/plain").getExamples().get("list").getSummary(),"List of names");
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().get(0).getContent().get("text/plain").getExamples().get("list").getValue(),"Bob,Diane,Mary,Bill");
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().get(0).getContent().get("text/plain").getExamples().get("empty").getSummary(),"Empty");
Assert.assertNull(petByStatusEndpoint.getGet().getParameters().get(0).getContent().get("text/plain").getExamples().get("empty").getValue());
Assert.assertEquals(petByStatusEndpoint.getGet().getParameters().get(0).getContent().get("text/plain").getExamples().get("empty").getValue(),"");

PathItem petEndpoint = paths.get("/pet");
Assert.assertNotNull(petEndpoint.getPut());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
openapi: 3.0.2
info:
title: Example references
version: 1.0.0
paths:
/foo:
get:
parameters:
- name: paramName
in: query
example: " "
responses:
'200':
description: success
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
openapi: 3.0.2
info:
title: Example references
version: 1.0.0
paths:
/foo:
get:
parameters:
- name: paramName
in: query
example: ""
responses:
'200':
description: success

0 comments on commit a4ba9fb

Please sign in to comment.