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

openapi spec improperly uses allOf when not needed #3563

Closed
jlsherrill opened this issue Feb 10, 2023 · 6 comments
Closed

openapi spec improperly uses allOf when not needed #3563

jlsherrill opened this issue Feb 10, 2023 · 6 comments

Comments

@jlsherrill
Copy link
Contributor

Version
3.22.2

Describe the bug
The openapi spec is written in such a way that is valid, but makes generating bindings problematic for some languages.

properties such as:

                    "policy": {
                        "allOf": [
                            {
                                "$ref": "#/components/schemas/PolicyDb6Enum"
                            }
                        ],
                        "default": "immediate",
                        "description": "The policy to use when downloading content."
                    },

could be re-written to be:

                    "policy": {
                       "$ref": "#/components/schemas/PolicyDb6Enum"
                        "default": "immediate",
                        "description": "The policy to use when downloading content."
                    },

and thus the property would only have a single type, and can be more easily handled by the openapi-generator, since the type is known and singular

To Reproduce
see this bug: OpenAPITools/openapi-generator#14665

Expected behavior
allOf should not be used in the spec when there is only a single type

Additional context
this prevents go bindings from being generated properly without patching

@jlsherrill
Copy link
Contributor Author

this is also an issue for the exporter part:

                    "method": { 
                        "allOf": [
                            {
                                "$ref": "#/components/schemas/MethodEnum"
                            }
                        ],
                        "default": "write",
                        "description": "Method of exporting"
                    }

@mdellweg
Copy link
Member

I do believe that the generated schema is correct, and that it cannot be simplified using $ref directly.

$ref and Sibling Elements

Any sibling elements of a $ref are ignored. This is because $ref works by replacing itself and everything on its level with the definition it is pointing at.

from: https://swagger.io/docs/specification/using-ref/

@jlsherrill
Copy link
Contributor Author

In the second schema, the description and default properties are ignored, so this schema ends up exactly the same as the referenced Date schema.
I see. I'm guessing you need the description & default value to be set on a per property basis too

@mdellweg
Copy link
Member

mdellweg commented Feb 13, 2023

Well maybe, first off all, this is what drf-spectacular generates for us. It may be redundant, yes. But we cannot have "$ref" and "description" without composing it with the help of "allOf".

@dkliban
Copy link
Member

dkliban commented Feb 20, 2023

@jlsherrill can we close this now that your openapi-generator PR has been merged?

@jlsherrill
Copy link
Contributor Author

yes sir!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

3 participants