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

Set the json model to null in the OneOf and AnyOf interfaces #380

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

oleastre
Copy link
Contributor

@oleastre oleastre commented May 9, 2019

The OneOf and AnyOf interfaces added as part of PR #367 broke the html doc generation.
The interfaces are added as models in the javascript generation with:

defs.{{name}} = {{{modelJson}}};

Since modelJson was not set for those interfaces, the generated javascript is invalid.
This commit quickly fixes the problem by setting modelJson to the json null value.
This is sufficient to make the html2 template happy and it's the only use of the modelJson field, so probably no effect on other templates.

@HugoMario
Copy link
Contributor

hi @oleastre, thanks for catching the issue and create this PR, it seems this fix the problem on HTML generators but it will break the feature for others generators as Java. is it possible you manage these changes that only affects the HTML generators?

i would recommend calling the SchemaHandler class in html generators and make changes there. you could add new method, new extended class overriding the methods or something similar that affect only to HTML generators.

please , let me know if you have any doubt about it

@oleastre
Copy link
Contributor Author

I used that way because the modelJson fields of the CodegenModel does not seems to be used in other templates. I don't see how it could break the java templates.
When I search for modelJson, I only find the following 3 references (without my changes):

src/main/resources/mustache/htmlDocs2/index.mustache:            defs.{{name}} = {{{modelJson}}};
src/main/resources/handlebars/htmlDocs2/index.mustache:            defs.{{name}} = {{{modelJson}}};
src/main/java/io/swagger/codegen/v3/generators/DefaultCodegenConfig.java:        codegenModel.modelJson = Json.pretty(schema)

But it's maybe used in another way I haven't found. My goal is to do the correct thing without breaking other templates, not only for the html2 generator (in fact I also generate python client code for my current project).
If you have better ideas, I would be happy to implement it.
Also, how can I test it my changes do not break the java generator ?

The OneOf and AnyOf interfaces added as part of PR swagger-api#367 broke the html
doc generation.
The interfaces are added as models in the javascript generation with:
```
defs.{{name}} = {{{modelJson}}};
```
Since `modelJson` was not set for those interfaces, the generated
javascript is invalid.
This commit quickly fixes the problem by setting `modelJson` to the json
`null` value. This is sufficient to make the html2 template happy and
it's the only use for the `modelJson` field.
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.

2 participants