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 ref handling in CB, AnyOf & examples (fixes : #2086) #2087

Merged

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
@anthochristen anthochristen changed the title Fix various ref handling (fixes : #2086) Fix ref handling in CB, AnyOf & examples (fixes : #2086) Aug 29, 2024
@anthochristen
Copy link
Author

anthochristen commented Oct 4, 2024

@frantuma @gracekarina @walaniam Any help on this would be much appreciated :)

@emead1
Copy link

emead1 commented Oct 21, 2024

Hi @frantuma @gracekarina @walaniam - I am the Product Manager for Java Frameworks at PayPal. This PR is currently blocking an enterprise-level initiative to upgrade to OAS 3.0. Below is the business case and impact if this PR is not merged in the coming weeks. Please let me know if there is a better channel to escalate this in to get better visibility. Thank you in advance - appreciate the partnership!

The code generation tool is crucial for developers to accurately validate specification and implement REST APIs at PayPal. This PR fixes critical bug that impact virtually all OAS3 REST API specifications using examples, parameter, discriminator and callback features, making the codegen tool incompatible in its current state. Without this fix, developers are forced with cumbersome workarounds to choose between restructure their API specifications that hinder reusability or generate java model classes on the resolved specification resulting significant disruption to existing API implementation. This issue not only impacts individual teams but also prevents the API Platform team from effectively testing and ensuring the platform meets customer needs. Ultimately, Failing to merge this PR to address this critical issue could delay API deployments and hinder the overall adoption of the new platform.

APIReferenceTemplate Repo: https://github.paypal.com/ApiSpecifications-R/APIReferenceSpecification/tree/develop/v1/schema/components

@frantuma frantuma force-pushed the bug/fix-cb-and-discriminator-refs branch from 04d7ef2 to e6b702a Compare October 23, 2024 08:33
@frantuma frantuma merged commit c84b494 into swagger-api:master Oct 23, 2024
6 checks passed
@frantuma
Copy link
Member

@anthochristen eventually merged, thanks!

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.

3 participants