-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Add failing test case for schema generation #7080
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
Add failing test case for schema generation #7080
Conversation
@tomchristie I would like to fix this issue. My idea: There is no constraint on the datatypes of choices. While debugging schema generation logic, I found a comment with 2 questions at
I would like to answer these questions. Question: Is 'type' required? Question: can we determine the TYPE of a choicefield? I know it is not a 100% proper solution but "something is better than nothing" |
Any Update on this? |
HI @dhaval-mehta. Sorry I missed this one. I've seen it now. I'll take a look. Will just need a cycle. Sorry for the delay. |
@dhaval-mehta Where does the OpenAPI spec say that it requires https://spec.openapis.org/oas/v3.0.2#properties states that https://tools.ietf.org/html/draft-wright-json-schema-validation-00#section-5.20 states that " Elements in the array MAY be of any type, including null." https://json-schema.org/understanding-json-schema/reference/generic.html#enumerated-values also supports the usage of 'any' type in enums. I do agree that we should try to add the type property to the OpenAPI output where it can be inferred, or add some way to explicitly state which type the enum should be mapped to, but I couldn't find anywhere in the spec that says it has to be. In my current codebase I am outputting typescript interfaces from DRF, and for the time being I have something akin to this code to do the mapping:
|
Thanks for pointing out. As per https://tools.ietf.org/html/draft-wright-json-schema-validation-00#section-5.20, String values MUST be one of the seven primitive types defined by the core specification. Here, the DRF schema generator is set Also, I have already suggested that we can generate a type for the choice-field in specific cases. for the rest of the cases, we should not set type at all. Anyway, PR to fix this issue is already open. Let's wait for the release. :) |
This was automatically closed because the PR fixing the root issue (a null
I'm open to reviewing a PR which adds this functionality in a clean way. |
Let's reopen. (Good catch @kevin-brown!) |
Thanks for the great support. I am actively working to provide |
As #7161 is merged into master, I am closing this issue. |
Notes:
As per OpenAPI specs, type is required. While generating schema, type is not provided for choice field. This leads to wrong schema in swagger and javascript error in redoc.
Someone has already reported this issue. See #7023