Skip to content

[1369] Unit test for AdditionalProperties keyword when converting from v2 to v3 #1370

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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 @@ -963,7 +963,7 @@ private Schema convert(Property schema) {
FileSchema fileSchema = Json.mapper().convertValue(schema, FileSchema.class);
result = fileSchema;

}else {
} else {

result = Json.mapper().convertValue(schema, Schema.class);
result.setExample(schema.getExample());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public class V2ConverterTest {
private static final String ISSUE_1113_YAML = "issue-1113.yaml";
private static final String ISSUE_1164_YAML = "issue-1164.yaml";
private static final String ISSUE_1261_YAML = "issue-1261.yaml";
private static final String ISSUE_1369_YAML = "issue-1369.yaml";

private static final String API_BATCH_PATH = "/api/batch/";
private static final String PETS_PATH = "/pets";
Expand Down Expand Up @@ -852,6 +853,29 @@ public void testissue1261() throws Exception {

}

@Test(description = "OpenAPI v2 converter - verifies the additionalProperties")
public void testissue1369() throws Exception {
OpenAPI oas = getConvertedOpenAPIFromJsonFile(ISSUE_1369_YAML);
assertNotNull(oas);
Schema schema = (Schema) oas.getComponents().getSchemas().get("Foo1");
assertNotNull(schema);
assertNull(schema.getAdditionalProperties());

schema = (Schema) oas.getComponents().getSchemas().get("Foo2");
assertNotNull(schema);
assertNotNull(schema.getAdditionalProperties());
assertEquals(schema.getAdditionalProperties(), Boolean.TRUE);
Copy link
Contributor

@spacether spacether Aug 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getAdditionalProperties() value should be a schema at this step in processing for a true spec input

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My mistake, this should be Boolean.TRUE per checking results when parsing a v3 spec.
This is good


schema = (Schema) oas.getComponents().getSchemas().get("Foo3");
assertNotNull(schema);
assertNotNull(schema.getAdditionalProperties());
assertEquals(schema.getAdditionalProperties(), Boolean.FALSE);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getAdditionalProperties() value should be null at this step in processing for a false spec input

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My mistake, this should be Boolean.FALSE per checking results when parsing a v3 spec.
This is good


schema = (Schema) oas.getComponents().getSchemas().get("Foo4");
assertNotNull(schema);
assertNotNull(schema.getAdditionalProperties());
}

@Test()
public void testInlineDefinitionProperty() throws Exception {
SwaggerConverter converter = new SwaggerConverter();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
swagger: '2.0'
info:
title: additionalProperties test
version: '1.0.0'
paths: {}

definitions:
Foo1:
type: object
properties:
bar:
type: string
Foo2:
type: object
properties:
foo:
type: string
additionalProperties: false
Foo3:
type: object
properties:
foo:
type: string
additionalProperties: true
Foo4:
type: object
properties:
bar:
type: string
additionalProperties:
type: string