Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issue #1375 #1376

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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