Skip to content

Conversation

spacether
Copy link
Contributor

@spacether spacether commented Sep 9, 2020

We have a bug in master branch where this schema:

    A:
      type: object
      additionalProperties:
        $ref: '#/components/schemas/B'

Is incorrectly interpreted as FreeFormObject when it should be a MapSchema
Per our java documentation a schema is FreeForm if:

A free form object is an object (i.e. 'type: object' in a OAS document) that:
1) Does not define properties, and
2) Is not a composed schema (no anyOf, oneOf, allOf), and
3) additionalproperties is not defined, or additionalproperties: true, or additionalproperties: {}.

Schema A does not satisfy requirement 3. Requirement 3 only allows additionalproperties values of null, true, and empty object {}. We have {$ref: '#/components/schemas/B'} which is different.

This PR fixes that bug by making sure that when we are in isFreeFormObject we check to see that a ref does not exist in additionalProperties.

  • A test has been added demonstrating that the above model is generated with our updated code

  • If merged, this PR will fix [BUG] python-experimental broken on master (java.lang.NullPointerException) #7372 (comment)

  • Read the contribution guidelines.

  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.

  • If contributing template-only or documentation-only changes which will change sample output, build the project beforehand.

  • Run the shell script ./bin/generate-samples.shto update all Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master. These must match the expectations made by your contribution. You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*. For Windows users, please run the script in Git BASH.

  • File the PR against the correct branch: master

  • Copy the technical committee to review the pull request if your PR is targeting a particular programming language.

@mks-m
Copy link
Contributor

mks-m commented Sep 11, 2020

if i understand correctly, if the error is in modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java then it should be affecting all languages. why did i only get the exception in python-experimental?

@mks-m
Copy link
Contributor

mks-m commented Sep 11, 2020

otherwise the fix looks good, thanks for addressing this so quickly!

@spacether
Copy link
Contributor Author

spacether commented Sep 11, 2020

if i understand correctly, if the error is in modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java then it should be affecting all languages. why did i only get the exception in python-experimental?

So there are two issues at play with why the error is seen in python-experimental and not other generators.

  1. Is schema A seen as a FreeFormObject? In master branch yes it is incorrectly classified as FreeFormObject rather than MapSchema. That means that it will not be generated.
  • [all generators impacted]
  1. python-experimental post processes all models to make sure that their imports are formatted correctly for python. Because schema A was not generated, this line throws a null pointer exception. This only happens in python-experimental because we are post processing all models (whether or not they are generated), and we hit some data where a value that we are trying to grab is null. If other generators were trying to get the "models" value in the schema A model they will also hit this exception. They don't do this same iteration, or they handle the null condition.
  • [only python-experimental impacted]

That's why it is only seen in python-experimental.

Copy link
Member

@wing328 wing328 left a comment

Choose a reason for hiding this comment

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

LGTM

@wing328 wing328 merged commit 8556cb8 into OpenAPITools:master Sep 14, 2020
@spacether spacether deleted the issue_7372_fix branch September 14, 2020 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] python-experimental broken on master (java.lang.NullPointerException)

3 participants