Swagger-codegen: [openapi-generators]: oneOfs are broken

Created on 16 Sep 2019  路  9Comments  路  Source: swagger-api/swagger-codegen

Description

Similar to issue https://github.com/swagger-api/swagger-codegen/issues/4081 I do not get any schema outputs in the genreted html2 doc. The schema definitions work in html though, only in html2 ALL are empty.
image
in html:
image

I was not able to track the issue down, there is also nothing in the log output that I can refer to...

Swagger-codegen version

$ java -jar swagger-codegen-cli.jar version
21:12:58.590 [main] DEBUG io.swagger.codegen.v3.cli.SwaggerCodegen - there are not options for command 'langs'
21:12:58.592 [main] DEBUG io.swagger.codegen.v3.cli.SwaggerCodegen - there are not options for command 'version'
3.0.11

Swagger declaration file content or url

https://test.hokify.com/ats-api/openapi.yaml

Command line used for generation

java -jar swagger-codegen-cli.jar generate -i services/ats-api/dist/swagger/swagger.yaml -l html2 -o doc-test
also happening in the online version.

Steps to reproduce

just generate the documentation with the command above and see that there is no schema response in the documentation.

Related issues/PRs

A very old one: https://github.com/swagger-api/swagger-codegen/issues/4081

Suggest a fix/enhancement

I guess something is "wrong" with the swagger file, I have generated this one with "tsoa". Maybe someone can give me a hint what is going one here.
UPDATE: I also opened an issue at tsoa's github page, and we checked that the issue is definitly not related to tsoa itself. The swagger file is valid, the generator seems to produce broken output here. See also my last comment.

Thanks a lot!

Simon

All 9 comments

And sometimes you just need to open an issue to get some more ideas what it could be ;) I just stumpled upon some javascript errors.
It looks like the generator produces "broken" javascript in the documentation.
e.g..

defs.LikeUser = {
  "type" : "string",
  "enum" : [ "true", "false", "saved", "pending", "needreview" ]
};
            defs.OneOfIAPIUserExtraType = ;
            defs.OneOfICustomApplicationOptionsReplyTo = ;
            defs.TypeObjectIdIAPIAbstractJob = {
  "type" : "object",
  "properties" : { },
  "additionalProperties" : false
};

the value assigments do not assign anything, which causes a javascvript parsing error.

index.html:2678 Uncaught SyntaxError: Unexpected token ;

So again, I guess the root cuase is still the swagger definition file, but besides that maybe an additional check if there is any value would help to overcome "broken" javascript.

regards
Simon

And one more finding:
It's definetliy related to the "oneOf" syntax.
But super weird, e.g. in ICustomApplicationOptions I have:

properties:
                to:
                    additionalProperties: true
                    type: object
                    nullable: true
                from:
                    oneOf:
                        -
                            type: string
                        -
                            properties:
                                name:
                                    type: string
                                address:
                                    type: string
                            required:
                                - address
                                - name
                            type: object
                    nullable: true
                replyTo:
                    oneOf:
                        -
                            type: string
                        -
                            properties:
                                name:
                                    type: string
                                address:
                                    type: string
                            required:
                                - address
                                - name
                            type: object
                    nullable: true

the "from" and "replyTo" are actually identically, but from does not cause any troubles, replyTo does though?

Regards
Simon

If I remove the occurences of "oneOf" and replace them by "type: string" it starts working.

1.

                from:
                    oneOf:
                        -
                            type: string
                        -
                            properties:
                                name:
                                    type: string
                                address:
                                    type: string
                            required:
                                - address
                                - name
                            type: object
                    nullable: true
    2.
replyTo:
                    oneOf:
                        -
                            type: string
                        -
                            properties:
                                name:
                                    type: string
                                address:
                                    type: string
                            required:
                                - address
                                - name
                            type: object
                    nullable: true

3.

 type:
                    oneOf:
                        -
                            $ref: '#/components/schemas/UserExtraType'
                        -
                            type: string

what could be wrong with this?

Regards
Simon

And one more comment, sorry for all the updates, but hopefully it helps to track this down :)

I couldn't find any grammer mistakes, therefore I assume this must be an underlying bug of the generator(s) (html2 is broken, html works, php generaor is also broken)

Thanks
Simon

thanks @simllll, going to assign this to myself and take a time to address it.

I have the same issue.
Will be fixed in v3.0.12 ? I am trying the swagger-codegen-cli-3.0.12-20191007.173642-40.jar but still not works.
Do you have any news?

Thanks G.

Any updates reagrding this issue?

@simllll please see this PR https://github.com/swagger-api/swagger-codegen/pull/9849 which adds a test to this case, I tested your spec locally and it generates the properties of the OneOf ComposedSchema, please let us know if that fixes the issue.

closed by #9849

Was this page helpful?
0 / 5 - 0 ratings