Skip to content
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 @@ -1305,9 +1305,17 @@ public License getLicense(ObjectNode node, String location, ParseResult result)
}

if (result.isOpenapi31()) {
value = getString("identifier", node, true, location, result);
// either the url must be set or the identifier but not both
boolean needsIdentifier = license.getUrl() == null;
value = getString("identifier", node, needsIdentifier, location, result);

if (StringUtils.isNotBlank(value)) {
license.setIdentifier(value);
if (!needsIdentifier) {
result.extra(location, "identifier", node);
result.invalid();
} else {
license.setIdentifier(value);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,127 @@ public void testEmptyDefinitions() throws Exception {

}

@Test
public void testIdentifierAndUrlInvalid() throws Exception {
String yaml = "openapi: 3.1.0\n" +
"servers:\n" +
" - url: 'http://abc:5555/mypath'\n" +
"info:\n" +
" version: '1.0'\n" +
" title: dd\n" +
" license:\n" +
" name: test\n" +
" url: http://example.com\n" +
" identifier: test\n" +
"paths:\n" +
" /resource1/Id:\n" +
" post:\n" +
" description: ''\n" +
" operationId: postOp\n" +
" responses:\n" +
" '200':\n" +
" description: Successful\n" +
" '401':\n" +
" description: Access Denied\n" +
" requestBody:\n" +
" content:\n" +
" application/json:\n" +
" schema:\n" +
" $ref: '#/components/schemas/mydefinition'\n" +
" required: true\n" +
"components:\n" +
" schemas:\n" +
" mydefinition: {}";

OpenAPIV3Parser parser = new OpenAPIV3Parser();

SwaggerParseResult result = parser.readContents(yaml,null,null);
OpenAPI openAPI = result.getOpenAPI();
assertNotNull(openAPI);

assertEquals(result.getMessages().size(), 1);
assertTrue(result.getMessages().get(0).contains("identifier"));
}

@Test
public void testUrlValid() {
String yaml = "openapi: 3.1.0\n" +
"servers:\n" +
" - url: 'http://abc:5555/mypath'\n" +
"info:\n" +
" version: '1.0'\n" +
" title: dd\n" +
" license:\n" +
" name: test\n" +
" url: http://example.com\n" +
"paths:\n" +
" /resource1/Id:\n" +
" post:\n" +
" description: ''\n" +
" operationId: postOp\n" +
" responses:\n" +
" '200':\n" +
" description: Successful\n" +
" '401':\n" +
" description: Access Denied\n" +
" requestBody:\n" +
" content:\n" +
" application/json:\n" +
" schema:\n" +
" $ref: '#/components/schemas/mydefinition'\n" +
" required: true\n" +
"components:\n" +
" schemas:\n" +
" mydefinition: {}";

OpenAPIV3Parser parser = new OpenAPIV3Parser();

SwaggerParseResult result = parser.readContents(yaml,null,null);
OpenAPI openAPI = result.getOpenAPI();
assertNotNull(openAPI);

assertEquals(result.getMessages().size(), 0);
}

@Test
public void testIdentifierValid() {
String yaml = "openapi: 3.1.0\n" +
"servers:\n" +
" - url: 'http://abc:5555/mypath'\n" +
"info:\n" +
" version: '1.0'\n" +
" title: dd\n" +
" license:\n" +
" name: test\n" +
" identifier: abc\n" +
"paths:\n" +
" /resource1/Id:\n" +
" post:\n" +
" description: ''\n" +
" operationId: postOp\n" +
" responses:\n" +
" '200':\n" +
" description: Successful\n" +
" '401':\n" +
" description: Access Denied\n" +
" requestBody:\n" +
" content:\n" +
" application/json:\n" +
" schema:\n" +
" $ref: '#/components/schemas/mydefinition'\n" +
" required: true\n" +
"components:\n" +
" schemas:\n" +
" mydefinition: {}";

OpenAPIV3Parser parser = new OpenAPIV3Parser();

SwaggerParseResult result = parser.readContents(yaml,null,null);
OpenAPI openAPI = result.getOpenAPI();
assertNotNull(openAPI);

assertEquals(result.getMessages().size(), 0);
}

@Test
public void testSecurityDeserialization() throws Exception {
Expand Down