Skip to content

[codegen] Improve java code comments and argument documentation; Fix issue with ComposedSchema that has undeclared properties - #5316

Merged
jimschubert merged 6 commits into
OpenAPITools:masterfrom
CiscoM31:alias-documentation
Feb 17, 2020
Merged

[codegen] Improve java code comments and argument documentation; Fix issue with ComposedSchema that has undeclared properties#5316
jimschubert merged 6 commits into
OpenAPITools:masterfrom
CiscoM31:alias-documentation

Conversation

@sebastien-rosset

@sebastien-rosset sebastien-rosset commented Feb 14, 2020

Copy link
Copy Markdown
Contributor

Add code comments in ModelUtils and documentation for the --generate-alias-as-model argument.

PR checklist

  • Read the contribution guidelines.
  • If contributing template-only or documentation-only changes which will change sample output, build the project before.
  • Run the shell script(s) under ./bin/ (or Windows batch scripts under.\bin\windows) to update Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit, and these must match the expectations made by your contribution. You only need to run ./bin/{LANG}-petstore.sh, ./bin/openapi3/{LANG}-petstore.sh if updating the code or mustache templates for a language ({LANG}) (e.g. php, ruby, python, etc).
  • File the PR against the correct branch: master, 4.3.x, 5.0.x. Default: master.
  • Copy the technical committee to review the pull request if your PR is targeting a particular programming language.

@sebastien-rosset

sebastien-rosset commented Feb 14, 2020

Copy link
Copy Markdown
Contributor Author

This PR is also a fix for #5317

@sebastien-rosset sebastien-rosset changed the title [codegen] Improve java code comments and argument documentation [codegen] Improve java code comments and argument documentation; Fix issue with ComposedSchema that has undeclared properties Feb 14, 2020

@sebastien-rosset sebastien-rosset left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@wing328 IMHO the title should never be used for code generation, but I'm not sure how to replace with another (better) logic. I am tracking this issue in #5248. One potential issue is that some OAS documents may have been written specifically for OpenAPITools, hence removing the title logic would end up breaking these specs. This could be addressed with a --use-title-attribute-to-flatten-inline-models-but-really-don-t-do-this command-line argument.
On the other hand, I argue it's just wrong to use the "title" and we should move away from it.

// The 'title' attribute is supposed to be for human consumption, not for code generation.
// OAS authors should not be expected to set a 'title' value that will control the
// code generation logic.
String innerModelName = resolveModelName(op.getTitle(), key);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

IMO, the "title" attribute in a OAS document should not have any impact whatsover on the code generation (codegen currently uses title to flatten inline schemas). Using 'title' can lead to completely unexpected outcomes for the generated code.

The OAS spec clearly states the 'title' attribute is for human consumption, so codegen should not use it.

I was working with a draft OAS document that has a composed allOf schema. The "title" of the inner schema happens to be the name of the outer (composed) object, but it could also have been any value, including names of totally unrelated schema.

That had the weird side effect to nullify the inheritance hierarchy. Then you have to debug the code to finally understand why the "parent" attribute ends up being nullified as a side effect of the "title" attribute

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I agree with this, and always thought it was odd.

Maybe we should consider it a bug and replace it's support with a vendor extension in 4.3.0. We don't have any metrics about who is actually using the feature, but I doubt anyone is because:

  1. it's not really documented
  2. it's confusing
  3. it may block users with well-defined specs from using the tooling

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have opened #5248 for this issue.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Based on the discussion in #5248 I'll file a PR to revise the wording here.

@jimschubert jimschubert left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for increasing the standards in our code for quality comments!

@jimschubert jimschubert added this to the 4.3.0 milestone Feb 17, 2020
@jimschubert
jimschubert merged commit 527c118 into OpenAPITools:master Feb 17, 2020
@sebastien-rosset

Copy link
Copy Markdown
Contributor Author

Thank you @jimschubert !

MikailBag pushed a commit to MikailBag/openapi-generator that referenced this pull request Mar 23, 2020
…issue with ComposedSchema that has undeclared properties (OpenAPITools#5316)

* improve documentation

* Add use case of composed schema with additional properties
@sebastien-rosset
sebastien-rosset deleted the alias-documentation branch May 23, 2020 19:26
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.

3 participants