From f64ed37b0452e9db971ce71d4a1784b27bb5233e Mon Sep 17 00:00:00 2001 From: gracekarina Date: Sat, 9 Oct 2021 13:09:14 -0500 Subject: [PATCH 1/4] empty strings validation --- .../v3/parser/util/OpenAPIDeserializer.java | 38 ++++++------- .../v3/parser/test/OpenAPIV3ParserTest.java | 16 ++++++ .../src/test/resources/empty-strings.yaml | 55 +++++++++++++++++++ 3 files changed, 90 insertions(+), 19 deletions(-) create mode 100644 modules/swagger-parser-v3/src/test/resources/empty-strings.yaml diff --git a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java index 542b30878b..4839763c00 100644 --- a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java +++ b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java @@ -391,7 +391,7 @@ public Tag getTag(ObjectNode obj, String location, ParseResult result) { Tag tag = new Tag(); String value = getString("name", obj, true, location, result); - if (StringUtils.isNotBlank(value)) { + if (value != null) { tag.setName(value); } @@ -470,7 +470,7 @@ public Server getServer(ObjectNode obj, String location, ParseResult result, Str } String value = getString("url", obj, true, location, result); - if (StringUtils.isNotBlank(value)) { + if (value != null) { if (!isValidURL(value) && path != null) { try { final URI absURI = new URI(path.replaceAll("\\\\", "/")); @@ -558,7 +558,7 @@ public ServerVariable getServerVariable(ObjectNode obj, String location, ParseRe } } String value = getString("default", obj, true, String.format("%s.%s", location, "default"), result); - if (StringUtils.isNotBlank(value)) { + if (value != null) { serverVariable.setDefault(value); } @@ -814,7 +814,7 @@ public ExternalDocumentation getExternalDocs(ObjectNode node, String location, P } value = getString("url", node, true, location, result); - if (StringUtils.isNotBlank(value)) { + if (value != null) { externalDocs.url(value); } @@ -901,7 +901,7 @@ public Info getInfo(ObjectNode node, String location, ParseResult result) { Info info = new Info(); String value = getString("title", node, true, location, result); - if (StringUtils.isNotBlank(value)) { + if (value != null) { info.setTitle(value); } @@ -927,7 +927,7 @@ public Info getInfo(ObjectNode node, String location, ParseResult result) { } value = getString("version", node, true, location, result); - if (StringUtils.isNotBlank(value)) { + if (value != null) { info.setVersion(value); } @@ -953,7 +953,7 @@ public License getLicense(ObjectNode node, String location, ParseResult result) License license = new License(); String value = getString("name", node, true, location, result); - if (StringUtils.isNotBlank(value)) { + if (value != null) { license.setName(value); } @@ -1605,7 +1605,7 @@ public Parameter getParameter(ObjectNode obj, String location, ParseResult resul parameter.setIn(value); value = getString("name", obj, true, location, result); - if (StringUtils.isNotBlank(value)) { + if (value != null) { parameter.setName(value); } @@ -1911,7 +1911,7 @@ public SecurityScheme getSecurityScheme(ObjectNode node, String location, ParseR openIdConnectRequired = false; String value = getString("type", node, true, location, result); - if (StringUtils.isNotBlank(value)) { + if (value != null) { if (SecurityScheme.Type.APIKEY.toString().equals(value)) { securityScheme.setType(SecurityScheme.Type.APIKEY); nameRequired = inRequired = true; @@ -1929,12 +1929,12 @@ public SecurityScheme getSecurityScheme(ObjectNode node, String location, ParseR } } value = getString("description", node, descriptionRequired, location, result); - if (StringUtils.isNotBlank(value)) { + if (value != null) { securityScheme.setDescription(value); } value = getString("name", node, nameRequired, location, result); - if (StringUtils.isNotBlank(value)) { + if (value != null) { securityScheme.setName(value); } @@ -1946,12 +1946,12 @@ public SecurityScheme getSecurityScheme(ObjectNode node, String location, ParseR securityScheme.setIn(matchingIn.orElse(null)); value = getString("scheme", node, schemeRequired, location, result); - if (StringUtils.isNotBlank(value)) { + if (value != null) { securityScheme.setScheme(value); } value = getString("bearerFormat", node, bearerFormatRequired, location, result); - if (StringUtils.isNotBlank(value)) { + if (value != null) { securityScheme.setBearerFormat(value); } @@ -1961,7 +1961,7 @@ public SecurityScheme getSecurityScheme(ObjectNode node, String location, ParseR } value = getString("openIdConnectUrl", node, openIdConnectRequired, location, result); - if (StringUtils.isNotBlank(value)) { + if (value != null) { securityScheme.setOpenIdConnectUrl(value); } @@ -2049,17 +2049,17 @@ public OAuthFlow getOAuthFlow(String oAuthFlowType, ObjectNode node, String loca } String value = getString("authorizationUrl", node, authorizationUrlRequired, location, result); - if (StringUtils.isNotBlank(value)) { + if (value != null) { oAuthFlow.setAuthorizationUrl(value); } value = getString("tokenUrl", node, tokenUrlRequired, location, result); - if (StringUtils.isNotBlank(value)) { + if (value != null) { oAuthFlow.setTokenUrl(value); } value = getString("refreshUrl", node, refreshUrlRequired, location, result); - if (StringUtils.isNotBlank(value)) { + if (value != null) { oAuthFlow.setRefreshUrl(value); } @@ -2125,7 +2125,7 @@ public Discriminator getDiscriminator(ObjectNode node, String location, ParseRes Discriminator discriminator = new Discriminator(); String value = getString("propertyName", node, true, location, result); - if (StringUtils.isNotBlank(value)) { + if (value != null) { discriminator.setPropertyName(value); } @@ -2835,7 +2835,7 @@ public ApiResponse getResponse(ObjectNode node, String location, ParseResult res } String value = getString("description", node, true, location, result); - if (StringUtils.isNotBlank(value)) { + if (value != null) { apiResponse.description(value); } diff --git a/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java index 4b63a6d9f5..3b556d5449 100644 --- a/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java +++ b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java @@ -83,6 +83,22 @@ public class OpenAPIV3ParserTest { protected int serverPort = getDynamicPort(); protected WireMockServer wireMockServer; + + @Test + public void testEmptyRequiredStrings() throws Exception{ + ParseOptions options = new ParseOptions(); + SwaggerParseResult result = new OpenAPIV3Parser().readLocation("src/test/resources/empty-strings.yaml", null, options ); + + Assert.assertNotNull(result); + Assert.assertNotNull(result.getOpenAPI()); + OpenAPI openAPI = result.getOpenAPI(); + assertNotNull(openAPI.getInfo().getTitle()); + assertNotNull(openAPI.getPaths().get("/something").getGet().getResponses().get("200").getDescription()); + assertNotNull(openAPI.getPaths().get("/something").getGet().getParameters().get(0).getDescription()); + Yaml.prettyPrint(result); + } + + @Test public void testIssue1561() { ParseOptions options = new ParseOptions(); diff --git a/modules/swagger-parser-v3/src/test/resources/empty-strings.yaml b/modules/swagger-parser-v3/src/test/resources/empty-strings.yaml new file mode 100644 index 0000000000..015e88ea4e --- /dev/null +++ b/modules/swagger-parser-v3/src/test/resources/empty-strings.yaml @@ -0,0 +1,55 @@ +openapi: 3.0.0 +info: + title: '' + description: '' + version: 1.0.0 + license: + name: '' + contact: + name: '' + +externalDocs: + url: https://example.com + description: '' + +servers: + - url: https://example.com + description: '' + +tags: + - name: tag1 + description: '' + +paths: + /something: + summary: '' + description: '' + get: + summary: '' + description: '' + parameters: + - name: role + in: query + schema: + type: string + example: '' + description: '' + example: '' + responses: + '200': + description: '' + content: + application/json: + schema: + $ref: '#/components/schemas/Foo' + +components: + schemas: + Foo: + type: object + description: '' + properties: + foo: + type: string + description: '' + example: '' \ No newline at end of file From 2d129e7140b0fed45699e08c0c32b3a4bb819dfb Mon Sep 17 00:00:00 2001 From: gracekarina Date: Tue, 12 Oct 2021 16:20:11 -0500 Subject: [PATCH 2/4] option to allow empty string as valid for deserialization --- .../v3/parser/core/models/ParseOptions.java | 9 ++ .../io/swagger/v3/parser/OpenAPIV3Parser.java | 12 +- .../v3/parser/util/OpenAPIDeserializer.java | 138 +++++++++++------- .../v3/parser/test/OpenAPIV3ParserTest.java | 26 +++- .../parser/util/OpenAPIDeserializerTest.java | 7 +- 5 files changed, 126 insertions(+), 66 deletions(-) diff --git a/modules/swagger-parser-core/src/main/java/io/swagger/v3/parser/core/models/ParseOptions.java b/modules/swagger-parser-core/src/main/java/io/swagger/v3/parser/core/models/ParseOptions.java index 9814dde6d2..526f732cff 100644 --- a/modules/swagger-parser-core/src/main/java/io/swagger/v3/parser/core/models/ParseOptions.java +++ b/modules/swagger-parser-core/src/main/java/io/swagger/v3/parser/core/models/ParseOptions.java @@ -8,6 +8,7 @@ public class ParseOptions { private boolean flattenComposedSchemas; private boolean camelCaseFlattenNaming; private boolean skipMatches; + private boolean allowEmptyStrings = true; public boolean isResolve() { return resolve; @@ -59,4 +60,12 @@ public boolean isCamelCaseFlattenNaming() { public void setCamelCaseFlattenNaming(boolean camelCaseFlattenNaming) { this.camelCaseFlattenNaming = camelCaseFlattenNaming; } + + public boolean isAllowEmptyString() { + return allowEmptyStrings; + } + + public void setAllowEmptyString(boolean allowEmptyStrings) { + this.allowEmptyStrings = allowEmptyStrings; + } } diff --git a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/OpenAPIV3Parser.java b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/OpenAPIV3Parser.java index be40ade290..2e1335def7 100644 --- a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/OpenAPIV3Parser.java +++ b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/OpenAPIV3Parser.java @@ -131,7 +131,10 @@ public SwaggerParseResult readWithInfo(String path, JsonNode node) { } public SwaggerParseResult parseJsonNode(String path, JsonNode node) { - return new OpenAPIDeserializer().deserialize(node, path); + return new OpenAPIDeserializer().deserialize(node, path,true); + } + public SwaggerParseResult parseJsonNode(String path, JsonNode node, ParseOptions options) { + return new OpenAPIDeserializer().deserialize(node, path, options.isAllowEmptyString()); } public SwaggerParseResult readContents(String yaml) { @@ -149,7 +152,12 @@ private SwaggerParseResult readContents(String swaggerAsString, List warnings = new ArrayList<>(); private List unique = new ArrayList<>(); private List uniqueTags = new ArrayList<>(); + private boolean allowEmptyStrings = true; public ParseResult() { } + public boolean isAllowEmptyStrings() { + return this.allowEmptyStrings; + } + + public void setAllowEmptyStrings(boolean allowEmptyStrings) { + this.allowEmptyStrings = allowEmptyStrings; + } + + public ParseResult allowEmptyStrings(boolean allowEmptyStrings) { + this.allowEmptyStrings = allowEmptyStrings; + return this; + } + public void unsupported(String location, String key, JsonNode value) { unsupported.put(new Location(location, key), value); } @@ -3186,6 +3213,7 @@ public boolean isValid() { return this.valid; } + public List getMessages() { List messages = new ArrayList(); for (Location l : extra.keySet()) { diff --git a/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java index 3b556d5449..d8487c3da1 100644 --- a/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java +++ b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java @@ -85,17 +85,34 @@ public class OpenAPIV3ParserTest { @Test - public void testEmptyRequiredStrings() throws Exception{ + public void testEmptyStrings_False() throws Exception{ ParseOptions options = new ParseOptions(); - SwaggerParseResult result = new OpenAPIV3Parser().readLocation("src/test/resources/empty-strings.yaml", null, options ); + options.setAllowEmptyString(false); + SwaggerParseResult result = new OpenAPIV3Parser().readLocation("src/test/resources/empty-strings.yaml", null, options); + + Assert.assertNotNull(result); + Assert.assertNotNull(result.getOpenAPI()); + OpenAPI openAPI = result.getOpenAPI(); + assertNull(openAPI.getInfo().getTitle()); + assertNull(openAPI.getInfo().getLicense().getName()); + assertNull(openAPI.getPaths().get("/something").getGet().getResponses().get("200").getDescription()); + assertNull(openAPI.getPaths().get("/something").getGet().getParameters().get(0).getDescription()); + } + + + @Test + public void testEmptyStrings_True() throws Exception{ + ParseOptions options = new ParseOptions(); + options.setAllowEmptyString(true); + SwaggerParseResult result = new OpenAPIV3Parser().readLocation("src/test/resources/empty-strings.yaml", null, options); Assert.assertNotNull(result); Assert.assertNotNull(result.getOpenAPI()); OpenAPI openAPI = result.getOpenAPI(); assertNotNull(openAPI.getInfo().getTitle()); + assertNotNull(openAPI.getInfo().getLicense().getName()); assertNotNull(openAPI.getPaths().get("/something").getGet().getResponses().get("200").getDescription()); assertNotNull(openAPI.getPaths().get("/something").getGet().getParameters().get(0).getDescription()); - Yaml.prettyPrint(result); } @@ -1042,8 +1059,7 @@ public void test30(@Injectable final List auths) throws Exce pathFile = pathFile.replace("${dynamicPort}", String.valueOf(this.serverPort)); ParseOptions options = new ParseOptions(); options.setResolve(true); - - SwaggerParseResult result = new OpenAPIV3Parser().readContents(pathFile, auths, options ); + SwaggerParseResult result = new OpenAPIV3Parser().readContents(pathFile, auths, options); Assert.assertNotNull(result); Assert.assertNotNull(result.getOpenAPI()); diff --git a/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/util/OpenAPIDeserializerTest.java b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/util/OpenAPIDeserializerTest.java index 9672fd5500..7d52415f59 100644 --- a/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/util/OpenAPIDeserializerTest.java +++ b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/util/OpenAPIDeserializerTest.java @@ -2966,7 +2966,6 @@ public void readPathsObject(JsonNode rootNode) throws Exception { final OpenAPI openAPI = result.getOpenAPI(); Assert.assertNotNull(openAPI); - //System.out.println(openAPI); final Paths paths = openAPI.getPaths(); Assert.assertNotNull(paths); @@ -2992,7 +2991,7 @@ public void readPathsObject(JsonNode rootNode) throws Exception { Assert.assertNotNull(petEndpoint.getPost().getTags()); Assert.assertEquals(petEndpoint.getPost().getTags().size(), 1); Assert.assertEquals(petEndpoint.getPost().getSummary(), "Add a new pet to the store"); - Assert.assertNull(petEndpoint.getPost().getDescription()); + Assert.assertEquals(petEndpoint.getPost().getDescription(), ""); Assert.assertEquals(petEndpoint.getPost().getOperationId(), "addPet"); Assert.assertNotNull(petEndpoint.getServers()); Assert.assertEquals(petEndpoint.getServers().size(), 1); @@ -3150,7 +3149,7 @@ public void readOAS(/*JsonNode rootNode*/) throws Exception { Assert.assertNotNull(stripe.getPost()); - Assert.assertNull(stripe.getPost().getDescription()); + Assert.assertEquals(stripe.getPost().getDescription(), ""); Assert.assertEquals(stripe.getPost().getOperationId(), "Create3DSecure"); Assert.assertNotNull(stripe.getPost().getParameters()); @@ -3169,7 +3168,7 @@ public void readOAS(/*JsonNode rootNode*/) throws Exception { Assert.assertNotNull(stripeGet.getGet()); - Assert.assertNull(stripeGet.getGet().getDescription()); + Assert.assertEquals(stripeGet.getGet().getDescription(), ""); Assert.assertEquals(stripeGet.getGet().getOperationId(), "AllAccountExternalAccounts"); Assert.assertNotNull(stripeGet.getGet().getParameters()); From ce26cf1ca41560c903e9d79ec9de1b9aa424f9b0 Mon Sep 17 00:00:00 2001 From: gracekarina Date: Thu, 14 Oct 2021 14:04:38 -0500 Subject: [PATCH 3/4] make changes in comments --- .../io/swagger/v3/parser/OpenAPIV3Parser.java | 4 +- .../v3/parser/util/OpenAPIDeserializer.java | 109 +++++++++--------- .../v3/parser/test/OpenAPIV3ParserTest.java | 1 + 3 files changed, 58 insertions(+), 56 deletions(-) diff --git a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/OpenAPIV3Parser.java b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/OpenAPIV3Parser.java index 2e1335def7..719bd2e669 100644 --- a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/OpenAPIV3Parser.java +++ b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/OpenAPIV3Parser.java @@ -131,10 +131,10 @@ public SwaggerParseResult readWithInfo(String path, JsonNode node) { } public SwaggerParseResult parseJsonNode(String path, JsonNode node) { - return new OpenAPIDeserializer().deserialize(node, path,true); + return new OpenAPIDeserializer().deserialize(node, path,new ParseOptions()); } public SwaggerParseResult parseJsonNode(String path, JsonNode node, ParseOptions options) { - return new OpenAPIDeserializer().deserialize(node, path, options.isAllowEmptyString()); + return new OpenAPIDeserializer().deserialize(node, path, options); } public SwaggerParseResult readContents(String yaml) { diff --git a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java index a599afcd11..6a2d4addc4 100644 --- a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java +++ b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java @@ -50,6 +50,7 @@ import io.swagger.v3.oas.models.servers.Server; import io.swagger.v3.oas.models.servers.ServerVariable; import io.swagger.v3.oas.models.servers.ServerVariables; +import io.swagger.v3.parser.core.models.ParseOptions; import io.swagger.v3.parser.core.models.SwaggerParseResult; import io.swagger.v3.core.util.Json; @@ -144,13 +145,13 @@ public SwaggerParseResult deserialize(JsonNode rootNode) { } public SwaggerParseResult deserialize(JsonNode rootNode, String path) { - return deserialize(rootNode,path, true); + return deserialize(rootNode,path, new ParseOptions()); } - public SwaggerParseResult deserialize(JsonNode rootNode, String path, boolean allowEmptyStrings) { + public SwaggerParseResult deserialize(JsonNode rootNode, String path, ParseOptions options) { SwaggerParseResult result = new SwaggerParseResult(); ParseResult rootParse = new ParseResult(); - rootParse.setAllowEmptyStrings(allowEmptyStrings); + rootParse.setAllowEmptyStrings(options.isAllowEmptyString()); OpenAPI api = parseRoot(rootNode, rootParse, path); result.setOpenAPI(api); result.setMessages(rootParse.getMessages()); @@ -396,12 +397,12 @@ public Tag getTag(ObjectNode obj, String location, ParseResult result) { Tag tag = new Tag(); String value = getString("name", obj, true, location, result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { tag.setName(value); } value = getString("description", obj, false, location, result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { tag.setDescription(value); } @@ -475,7 +476,7 @@ public Server getServer(ObjectNode obj, String location, ParseResult result, Str } String value = getString("url", obj, true, location, result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { if (!isValidURL(value) && path != null) { try { final URI absURI = new URI(path.replaceAll("\\\\", "/")); @@ -495,7 +496,7 @@ public Server getServer(ObjectNode obj, String location, ParseResult result, Str } value = getString("description", obj, false, location, result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { server.setDescription(value); } @@ -563,12 +564,12 @@ public ServerVariable getServerVariable(ObjectNode obj, String location, ParseRe } } String value = getString("default", obj, true, String.format("%s.%s", location, "default"), result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { serverVariable.setDefault(value); } value = getString("description", obj, false, String.format("%s.%s", location, "description"), result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { serverVariable.setDescription(value); } @@ -715,12 +716,12 @@ public PathItem getPathItem(ObjectNode obj, String location, ParseResult result) } String value = getString("summary", obj, false, location, result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { pathItem.setSummary(value); } value = getString("description", obj, false, location, result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { pathItem.setDescription(value); } @@ -814,12 +815,12 @@ public ExternalDocumentation getExternalDocs(ObjectNode node, String location, P externalDocs = new ExternalDocumentation(); String value = getString("description", node, false, location, result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { externalDocs.description(value); } value = getString("url", node, true, location, result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { externalDocs.url(value); } @@ -906,17 +907,17 @@ public Info getInfo(ObjectNode node, String location, ParseResult result) { Info info = new Info(); String value = getString("title", node, true, location, result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { info.setTitle(value); } value = getString("description", node, false, location, result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { info.setDescription(value); } value = getString("termsOfService", node, false, location, result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { info.setTermsOfService(value); } @@ -932,7 +933,7 @@ public Info getInfo(ObjectNode node, String location, ParseResult result) { } value = getString("version", node, true, location, result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { info.setVersion(value); } @@ -958,12 +959,12 @@ public License getLicense(ObjectNode node, String location, ParseResult result) License license = new License(); String value = getString("name", node, true, location, result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { license.setName(value); } value = getString("url", node, false, location, result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { try { new URL(value); } catch (Exception e) { @@ -994,12 +995,12 @@ public Contact getContact(ObjectNode node, String location, ParseResult result) Contact contact = new Contact(); String value = getString("name", node, false, location, result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { contact.setName(value); } value = getString("url", node, false, location, result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { try { new URL(value); } catch (Exception e) { @@ -1009,7 +1010,7 @@ public Contact getContact(ObjectNode node, String location, ParseResult result) } value = getString("email", node, false, location, result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { contact.setEmail(value); } @@ -1117,7 +1118,7 @@ public Encoding getEncoding(ObjectNode node, String location, ParseResult result Encoding encoding = new Encoding(); String value = getString("contentType", node, false, location, result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { encoding.setContentType(value); } @@ -1226,12 +1227,12 @@ public Link getLink(ObjectNode linkNode, String location, ParseResult result) { } String value = getString("operationRef", linkNode, false, location, result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { link.setOperationRef(value); } value = getString("operationId", linkNode, false, location, result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { link.setOperationId(value); } @@ -1256,7 +1257,7 @@ public Link getLink(ObjectNode linkNode, String location, ParseResult result) { } value = getString("description", linkNode, false, location, result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { link.setDescription(value); } @@ -1356,17 +1357,17 @@ public XML getXml(ObjectNode node, String location, ParseResult result) { XML xml = new XML(); String value = getString("name", node, false, String.format("%s.%s", location, "name"), result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { xml.setName(value); } value = getString("namespace", node, false, String.format("%s.%s", location, "namespace"), result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { xml.setNamespace(value); } value = getString("prefix", node, false, String.format("%s.%s", location, "prefix"), result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { xml.setPrefix(value); } @@ -1612,12 +1613,12 @@ public Parameter getParameter(ObjectNode obj, String location, ParseResult resul parameter.setIn(value); value = getString("name", obj, true, location, result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { parameter.setName(value); } value = getString("description", obj, false, location, result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { parameter.setDescription(value); } @@ -1758,7 +1759,7 @@ public Header getHeader(ObjectNode headerNode, String location, ParseResult resu String value = getString("description", headerNode, false, location, result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { header.setDescription(value); } @@ -1919,7 +1920,7 @@ public SecurityScheme getSecurityScheme(ObjectNode node, String location, ParseR openIdConnectRequired = false; String value = getString("type", node, true, location, result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { if (SecurityScheme.Type.APIKEY.toString().equals(value)) { securityScheme.setType(SecurityScheme.Type.APIKEY); nameRequired = inRequired = true; @@ -1937,12 +1938,12 @@ public SecurityScheme getSecurityScheme(ObjectNode node, String location, ParseR } } value = getString("description", node, descriptionRequired, location, result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { securityScheme.setDescription(value); } value = getString("name", node, nameRequired, location, result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { securityScheme.setName(value); } @@ -1954,12 +1955,12 @@ public SecurityScheme getSecurityScheme(ObjectNode node, String location, ParseR securityScheme.setIn(matchingIn.orElse(null)); value = getString("scheme", node, schemeRequired, location, result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { securityScheme.setScheme(value); } value = getString("bearerFormat", node, bearerFormatRequired, location, result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { securityScheme.setBearerFormat(value); } @@ -1969,7 +1970,7 @@ public SecurityScheme getSecurityScheme(ObjectNode node, String location, ParseR } value = getString("openIdConnectUrl", node, openIdConnectRequired, location, result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { securityScheme.setOpenIdConnectUrl(value); } @@ -2057,17 +2058,17 @@ public OAuthFlow getOAuthFlow(String oAuthFlowType, ObjectNode node, String loca } String value = getString("authorizationUrl", node, authorizationUrlRequired, location, result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { oAuthFlow.setAuthorizationUrl(value); } value = getString("tokenUrl", node, tokenUrlRequired, location, result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { oAuthFlow.setTokenUrl(value); } value = getString("refreshUrl", node, refreshUrlRequired, location, result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { oAuthFlow.setRefreshUrl(value); } @@ -2133,7 +2134,7 @@ public Discriminator getDiscriminator(ObjectNode node, String location, ParseRes Discriminator discriminator = new Discriminator(); String value = getString("propertyName", node, true, location, result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { discriminator.setPropertyName(value); } @@ -2281,7 +2282,7 @@ public Schema getSchema(ObjectNode node, String location, ParseResult result) { String value = getString("title", node, false, location, result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { schema.setTitle(value); } @@ -2397,7 +2398,7 @@ public Schema getSchema(ObjectNode node, String location, ParseResult result) { value = getString("type", node, false, location, result); if (StringUtils.isBlank(schema.getType())) { - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { schema.setType(value); } else { // may have an enum where type can be inferred @@ -2444,12 +2445,12 @@ public Schema getSchema(ObjectNode node, String location, ParseResult result) { } value = getString("description", node, false, location, result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { schema.setDescription(value); } value = getString("format", node, false, location, result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { schema.setFormat(value); } @@ -2463,7 +2464,7 @@ public Schema getSchema(ObjectNode node, String location, ParseResult result) { } } else if (schema.getType().equals("string")) { value = getString("default", node, false, location, result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { try { schema.setDefault(getDecodedObject(schema, value)); } catch (ParseException e) { @@ -2723,12 +2724,12 @@ public Example getExample(ObjectNode node, String location, ParseResult result) } String value = getString("summary", node, false, location, result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { example.setSummary(value); } value = getString("description", node, false, location, result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { example.setDescription(value); } @@ -2739,7 +2740,7 @@ public Example getExample(ObjectNode node, String location, ParseResult result) value = getString("externalValue", node, false, location, result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { example.setExternalValue(value); } @@ -2848,7 +2849,7 @@ public ApiResponse getResponse(ObjectNode node, String location, ParseResult res } String value = getString("description", node, true, location, result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { apiResponse.description(value); } @@ -2917,12 +2918,12 @@ public Operation getOperation(ObjectNode obj, String location, ParseResult resul operation.setTags(tags); } String value = getString("summary", obj, false, location, result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { operation.setSummary(value); } value = getString("description", obj, false, location, result); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { operation.setDescription(value); } @@ -2933,7 +2934,7 @@ public Operation getOperation(ObjectNode obj, String location, ParseResult resul operation.setExternalDocs(docs); } value = getString("operationId", obj, false, location, result, operationIDs); - if (result.isAllowEmptyStrings() && value != null) { + if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { operation.operationId(value); } diff --git a/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java index d8487c3da1..bb902ea029 100644 --- a/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java +++ b/modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java @@ -94,6 +94,7 @@ public void testEmptyStrings_False() throws Exception{ Assert.assertNotNull(result.getOpenAPI()); OpenAPI openAPI = result.getOpenAPI(); assertNull(openAPI.getInfo().getTitle()); + assertNotNull(openAPI.getInfo().getVersion()); assertNull(openAPI.getInfo().getLicense().getName()); assertNull(openAPI.getPaths().get("/something").getGet().getResponses().get("200").getDescription()); assertNull(openAPI.getPaths().get("/something").getGet().getParameters().get(0).getDescription()); From dd311de675f2f5fd29a9bb3bddf6dd2c0237fad6 Mon Sep 17 00:00:00 2001 From: gracekarina Date: Thu, 14 Oct 2021 16:43:51 -0500 Subject: [PATCH 4/4] improve validation --- .../v3/parser/util/OpenAPIDeserializer.java | 102 +++++++++--------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java index 6a2d4addc4..14f7198339 100644 --- a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java +++ b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java @@ -397,12 +397,12 @@ public Tag getTag(ObjectNode obj, String location, ParseResult result) { Tag tag = new Tag(); String value = getString("name", obj, true, location, result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { tag.setName(value); } value = getString("description", obj, false, location, result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { tag.setDescription(value); } @@ -476,7 +476,7 @@ public Server getServer(ObjectNode obj, String location, ParseResult result, Str } String value = getString("url", obj, true, location, result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { if (!isValidURL(value) && path != null) { try { final URI absURI = new URI(path.replaceAll("\\\\", "/")); @@ -496,7 +496,7 @@ public Server getServer(ObjectNode obj, String location, ParseResult result, Str } value = getString("description", obj, false, location, result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { server.setDescription(value); } @@ -564,12 +564,12 @@ public ServerVariable getServerVariable(ObjectNode obj, String location, ParseRe } } String value = getString("default", obj, true, String.format("%s.%s", location, "default"), result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { serverVariable.setDefault(value); } value = getString("description", obj, false, String.format("%s.%s", location, "description"), result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { serverVariable.setDescription(value); } @@ -716,12 +716,12 @@ public PathItem getPathItem(ObjectNode obj, String location, ParseResult result) } String value = getString("summary", obj, false, location, result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { pathItem.setSummary(value); } value = getString("description", obj, false, location, result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { pathItem.setDescription(value); } @@ -815,12 +815,12 @@ public ExternalDocumentation getExternalDocs(ObjectNode node, String location, P externalDocs = new ExternalDocumentation(); String value = getString("description", node, false, location, result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { externalDocs.description(value); } value = getString("url", node, true, location, result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { externalDocs.url(value); } @@ -907,17 +907,17 @@ public Info getInfo(ObjectNode node, String location, ParseResult result) { Info info = new Info(); String value = getString("title", node, true, location, result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { info.setTitle(value); } value = getString("description", node, false, location, result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { info.setDescription(value); } value = getString("termsOfService", node, false, location, result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { info.setTermsOfService(value); } @@ -933,7 +933,7 @@ public Info getInfo(ObjectNode node, String location, ParseResult result) { } value = getString("version", node, true, location, result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { info.setVersion(value); } @@ -959,12 +959,12 @@ public License getLicense(ObjectNode node, String location, ParseResult result) License license = new License(); String value = getString("name", node, true, location, result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { license.setName(value); } value = getString("url", node, false, location, result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { try { new URL(value); } catch (Exception e) { @@ -995,12 +995,12 @@ public Contact getContact(ObjectNode node, String location, ParseResult result) Contact contact = new Contact(); String value = getString("name", node, false, location, result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { contact.setName(value); } value = getString("url", node, false, location, result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { try { new URL(value); } catch (Exception e) { @@ -1010,7 +1010,7 @@ public Contact getContact(ObjectNode node, String location, ParseResult result) } value = getString("email", node, false, location, result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { contact.setEmail(value); } @@ -1118,7 +1118,7 @@ public Encoding getEncoding(ObjectNode node, String location, ParseResult result Encoding encoding = new Encoding(); String value = getString("contentType", node, false, location, result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { encoding.setContentType(value); } @@ -1227,12 +1227,12 @@ public Link getLink(ObjectNode linkNode, String location, ParseResult result) { } String value = getString("operationRef", linkNode, false, location, result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { link.setOperationRef(value); } value = getString("operationId", linkNode, false, location, result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { link.setOperationId(value); } @@ -1257,7 +1257,7 @@ public Link getLink(ObjectNode linkNode, String location, ParseResult result) { } value = getString("description", linkNode, false, location, result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { link.setDescription(value); } @@ -1357,17 +1357,17 @@ public XML getXml(ObjectNode node, String location, ParseResult result) { XML xml = new XML(); String value = getString("name", node, false, String.format("%s.%s", location, "name"), result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { xml.setName(value); } value = getString("namespace", node, false, String.format("%s.%s", location, "namespace"), result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { xml.setNamespace(value); } value = getString("prefix", node, false, String.format("%s.%s", location, "prefix"), result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { xml.setPrefix(value); } @@ -1613,12 +1613,12 @@ public Parameter getParameter(ObjectNode obj, String location, ParseResult resul parameter.setIn(value); value = getString("name", obj, true, location, result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { parameter.setName(value); } value = getString("description", obj, false, location, result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { parameter.setDescription(value); } @@ -1759,7 +1759,7 @@ public Header getHeader(ObjectNode headerNode, String location, ParseResult resu String value = getString("description", headerNode, false, location, result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { header.setDescription(value); } @@ -1920,7 +1920,7 @@ public SecurityScheme getSecurityScheme(ObjectNode node, String location, ParseR openIdConnectRequired = false; String value = getString("type", node, true, location, result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { if (SecurityScheme.Type.APIKEY.toString().equals(value)) { securityScheme.setType(SecurityScheme.Type.APIKEY); nameRequired = inRequired = true; @@ -1938,12 +1938,12 @@ public SecurityScheme getSecurityScheme(ObjectNode node, String location, ParseR } } value = getString("description", node, descriptionRequired, location, result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { securityScheme.setDescription(value); } value = getString("name", node, nameRequired, location, result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { securityScheme.setName(value); } @@ -1955,12 +1955,12 @@ public SecurityScheme getSecurityScheme(ObjectNode node, String location, ParseR securityScheme.setIn(matchingIn.orElse(null)); value = getString("scheme", node, schemeRequired, location, result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { securityScheme.setScheme(value); } value = getString("bearerFormat", node, bearerFormatRequired, location, result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { securityScheme.setBearerFormat(value); } @@ -1970,7 +1970,7 @@ public SecurityScheme getSecurityScheme(ObjectNode node, String location, ParseR } value = getString("openIdConnectUrl", node, openIdConnectRequired, location, result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { securityScheme.setOpenIdConnectUrl(value); } @@ -2058,17 +2058,17 @@ public OAuthFlow getOAuthFlow(String oAuthFlowType, ObjectNode node, String loca } String value = getString("authorizationUrl", node, authorizationUrlRequired, location, result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { oAuthFlow.setAuthorizationUrl(value); } value = getString("tokenUrl", node, tokenUrlRequired, location, result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { oAuthFlow.setTokenUrl(value); } value = getString("refreshUrl", node, refreshUrlRequired, location, result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { oAuthFlow.setRefreshUrl(value); } @@ -2134,7 +2134,7 @@ public Discriminator getDiscriminator(ObjectNode node, String location, ParseRes Discriminator discriminator = new Discriminator(); String value = getString("propertyName", node, true, location, result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { discriminator.setPropertyName(value); } @@ -2282,7 +2282,7 @@ public Schema getSchema(ObjectNode node, String location, ParseResult result) { String value = getString("title", node, false, location, result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { schema.setTitle(value); } @@ -2398,7 +2398,7 @@ public Schema getSchema(ObjectNode node, String location, ParseResult result) { value = getString("type", node, false, location, result); if (StringUtils.isBlank(schema.getType())) { - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { schema.setType(value); } else { // may have an enum where type can be inferred @@ -2445,12 +2445,12 @@ public Schema getSchema(ObjectNode node, String location, ParseResult result) { } value = getString("description", node, false, location, result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { schema.setDescription(value); } value = getString("format", node, false, location, result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { schema.setFormat(value); } @@ -2464,7 +2464,7 @@ public Schema getSchema(ObjectNode node, String location, ParseResult result) { } } else if (schema.getType().equals("string")) { value = getString("default", node, false, location, result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { try { schema.setDefault(getDecodedObject(schema, value)); } catch (ParseException e) { @@ -2724,12 +2724,12 @@ public Example getExample(ObjectNode node, String location, ParseResult result) } String value = getString("summary", node, false, location, result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { example.setSummary(value); } value = getString("description", node, false, location, result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { example.setDescription(value); } @@ -2740,7 +2740,7 @@ public Example getExample(ObjectNode node, String location, ParseResult result) value = getString("externalValue", node, false, location, result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { example.setExternalValue(value); } @@ -2849,7 +2849,7 @@ public ApiResponse getResponse(ObjectNode node, String location, ParseResult res } String value = getString("description", node, true, location, result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { apiResponse.description(value); } @@ -2918,12 +2918,12 @@ public Operation getOperation(ObjectNode obj, String location, ParseResult resul operation.setTags(tags); } String value = getString("summary", obj, false, location, result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { operation.setSummary(value); } value = getString("description", obj, false, location, result); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { operation.setDescription(value); } @@ -2934,7 +2934,7 @@ public Operation getOperation(ObjectNode obj, String location, ParseResult resul operation.setExternalDocs(docs); } value = getString("operationId", obj, false, location, result, operationIDs); - if (result.isAllowEmptyStrings() && value != null || !result.isAllowEmptyStrings() && !StringUtils.isBlank(value)) { + if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) { operation.operationId(value); }