Skip to content

Commit

Permalink
Merge pull request #1376 from mih-kopylov/bug/1375-empty-blank-parame…
Browse files Browse the repository at this point in the history
…ter-example

Fix for issue #1375
  • Loading branch information
gracekarina authored May 25, 2020
2 parents d0ad044 + ebe8b2a commit e5dadac
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 e5dadac

Please sign in to comment.