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

Consider callbacks in unused schemas #1232

Merged
merged 1 commit into from
Oct 18, 2018

Conversation

jmini
Copy link
Member

@jmini jmini commented Oct 13, 2018

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh and ./bin/security/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in .\bin\windows\.
  • Filed the PR against the correct branch: master, 3.4.x, 4.0.x. Default: master.
  • Copied the technical committee: @OpenAPITools/generator-core-team (change to the core)

Description of the PR

Callbacks can reference Schemas. The ModelUtils methods that compute used and unused schemas should visit the callbacks.

Callbacks effort in general is tracked as #372.

Copy link
Member

@jimschubert jimschubert left a comment

Choose a reason for hiding this comment

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

Code looks good. I'm not that familiar with callbacks, so I don't know how I'd go about testing this. I'll leave the evaluation from that perspective to someone else with experience in callback usages.

if (allOperations != null) {
for (Operation operation : allOperations) {
//Params:
if (operation.getParameters() != null) {
Copy link
Member

Choose a reason for hiding this comment

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

I know most of the code here was just reorganized, but I just had a question. I'm wondering why we follow visitor pattern only for a few elements (visitSchema) but not others which are commented here like "Params", "RequestBody", "Responses", and "Callbacks"? It seems like this would make for smaller surface area for unit testing edge cases.

Copy link
Member Author

@jmini jmini May 19, 2020

Choose a reason for hiding this comment

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

@jimschubert: I never forgot your comment about having a true visitor Pattern for an OpenAPI spec.

I have implemented it in OpenAPITools/empoa#14

See: https://openapitools.github.io/empoa/#visitor-pattern

@jmini jmini merged commit 16f1fc0 into OpenAPITools:master Oct 18, 2018
@jmini
Copy link
Member Author

jmini commented Oct 18, 2018

Thank you for the review.

This PR is mainly about taking into account the Schema that can be referenced in PathItems of Callbacks. I did not change anything else.

Of course a proper/complete visitor pattern would be better. This might also be an overkill for this use case. In the ModelUtils the visitor approach is internal (private) in order to be able to share core between following methods:

List<String> getAllUsedSchemas(OpenAPI openAPI)
List<String> getUnusedSchemas(OpenAPI openAPI)
List<String> getSchemasUsedOnlyInFormParam(OpenAPI openAPI)

@wing328 wing328 added this to the 3.3.2 milestone Oct 31, 2018
jmini added a commit to jmini/openapi-generator that referenced this pull request Dec 10, 2018
jmini added a commit that referenced this pull request Dec 10, 2018
A-Joshi pushed a commit to ihsmarkitoss/openapi-generator that referenced this pull request Feb 27, 2019
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