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

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

sebastien-rosset
Copy link
Contributor

@sebastien-rosset sebastien-rosset commented May 15, 2020

This is a PR to add a unit test for #1369.

When the 'additionalProperties' keyword is specified in a '2.0' document as a boolean value, the value is not converted to the 3.0 document. In the converted 3.0 schema, the additionalProperties() function returns null instead of the boolean value.

I'm not sure if this should be targeted for the master branch or the 2.0-before-branch-switch branch.

At this point this PR is only the unit test that shows the conversion issue.

Code that needs to change:

  1. Process JsonNode "additionalProperties" https://github.com/swagger-api/swagger-parser/blob/v1/modules/swagger-parser/src/main/java/io/swagger/parser/util/SwaggerDeserializer.java#L820
  2. Change type of additionalProperties field to Object. Should allow both Boolean value and Property: https://github.com/swagger-api/swagger-core/blob/1.5/modules/swagger-models/src/main/java/io/swagger/models/ModelImpl.java#L25

@JonathanParrilla
Copy link
Contributor

please build

@sebastien-rosset
Copy link
Contributor Author

sebastien-rosset commented Aug 3, 2020

please build

I have now pulled the latest from master. As it stands, this PR has a unit test to show the problem. It does not have the actual fix. I initially spent some time looking at how to fix the problem, but in doing so it occurred to me the v2 code seems to have been the basis for v3 code, with some code being copied from v2 into a v3 folder, then modified to handle additional properties (but not retrofitted back to the v2 code). Code maintainers probably have opinions on how this problem should be fixed.

@spacether
Copy link
Contributor

spacether commented Aug 3, 2020

Heads up, I just submitted this PR: #1414
Which adds unit tests and a fix for additionalProperties in the v1 branch which is responsible for parsing v2 specs

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants