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 various ref handling (fixes : #2086) #2087

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

Conversation

anthochristen
Copy link

This PR is to address the $ref handling issues in callbacks and discriminator mapping objects as detailed in #2086.
It does it with the following changes

  • Extends discriminator mapping handling for anyOf like its done for OneOf in SchemaProcessor class.
  • Add ref path resolution for examples of Parameters
  • Handles ref path resolution for array items with ComplexSchemas
  • Refactors the processRefToExternalPathItem in ExternalRefProcessor so that it can be used for $ref path resolution in PathItems used within callbacks.

Each done in dedicated commits, although there might be some spill over.

@anthochristen anthochristen force-pushed the bug/fix-cb-and-discriminator-refs branch from d04e41c to 18400a0 Compare May 1, 2024 19:39
@anthochristen anthochristen changed the title Fix various ref handling Fix various ref handling (fixes : #2086) May 1, 2024
@anthochristen
Copy link
Author

@gracekarina I see that you have worked on the files in which most of this changes are done for this issue (#2086). Would be great if you can take a look at these changes.

@anthochristen
Copy link
Author

Have a blanket IT type test for now, can add more in depth UTs once I get some comments on these changes.

@frantuma frantuma self-assigned this May 2, 2024
@anthochristen
Copy link
Author

Thanks @frantuma for assigning this to yourself!

@anthochristen
Copy link
Author

P.S: These issues are not present in the npm swagger-parser lib.

Copy link
Member

@frantuma frantuma left a comment

Choose a reason for hiding this comment

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

@anthochristen thanks a lot for your PR

added a couple of comments

} else {
processSchema(s, file);
}
});
Copy link
Member

Choose a reason for hiding this comment

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

We would need to add processProperties(arraySchema.getItems().getProperties(), file); also here as a composed schema can also have properties

Copy link
Author

Choose a reason for hiding this comment

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

Looks like this scenarios was handled in the latest snapshot version of reverted this change for arrays.

@@ -246,9 +264,29 @@ private void processSchema(Schema property, String file) {
}
if (property instanceof ComposedSchema) {
ComposedSchema composed = (ComposedSchema) property;
final Map<String, String> refMap = Optional.ofNullable(property.getDiscriminator())
Copy link
Member

Choose a reason for hiding this comment

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

IIANM the changes here, alongside the ones in SchemaProcessor and PathsProcessor, consider oneOf and anyOf as mutually exclusive, while they can coexist even if not so common. I would suggest to consider them both in the processing

Copy link
Author

Choose a reason for hiding this comment

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

Updated as per suggestion, thanks!

}if (composedSchema.getAnyOf() != null) {
for(Schema innerModel : composedSchema.getAnyOf()) {
}
if (composedSchema.getAnyOf() != null || composedSchema.getOneOf() != null) {
Copy link
Member

Choose a reason for hiding this comment

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

AS mentioned above:

IIANM the changes here consider oneOf and anyOf as mutually exclusive, while they can coexist even if not so common. I would suggest to consider them both in the processing

Copy link
Author

Choose a reason for hiding this comment

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

Made the processing to be mutually inclusive.
Intuitively though, the definitions feel that they are mutually exclusive.

@@ -157,8 +157,10 @@ public void processComposedSchema(ComposedSchema composedSchema) {
}
}
}
}if(composedSchema.getOneOf() != null){
final List<Schema> schemas = composedSchema.getOneOf();
}
Copy link
Member

Choose a reason for hiding this comment

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

AS mentioned above:

IIANM the changes here consider oneOf and anyOf as mutually exclusive, while they can coexist even if not so common. I would suggest to consider them both in the processing

Copy link
Author

Choose a reason for hiding this comment

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

Updated as suggested.

@anthochristen anthochristen force-pushed the bug/fix-cb-and-discriminator-refs branch from 076540b to 0f34603 Compare May 20, 2024 11:41
@anthochristen anthochristen force-pushed the bug/fix-cb-and-discriminator-refs branch from 0f34603 to a19e9e0 Compare May 29, 2024 06:55
@anthochristen
Copy link
Author

@frantuma I've changed the oneOf and anyOf to be inclusive, kindly help take a look when possible, thanks!

@anthochristen anthochristen force-pushed the bug/fix-cb-and-discriminator-refs branch from a19e9e0 to 04d7ef2 Compare May 29, 2024 10:22
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

2 participants