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

Proposal for Required Fields #54

Closed
tfranzel opened this issue May 15, 2020 · 10 comments
Closed

Proposal for Required Fields #54

tfranzel opened this issue May 15, 2020 · 10 comments

Comments

@tfranzel
Copy link
Owner

spectacular apparently is used by a few people now. i'd like to get some feedback on an idea before doing potentially invasive schema changes.

Theoretically we could make all read-only fields required. Which is imho a better representation of what DRF is actually doing. afaik DRF will always render a field even if it is null. so it is indeed required and not optional. note that this would only apply to responses and not requests.

It is an easy change, but i would like to get feedback beforehand. i don't want to break your schemas/clients. For our purposes it looks very good and the generated clients also honor it well.

i will create a pull request for you to check this out.

@tfranzel
Copy link
Owner Author

@MissiaL @tsouvarev @jayvdb you guys certainly exposed spectacular to a few code bases. what do you think?

@tsouvarev
Copy link
Contributor

Sounds good to me

@MissiaL
Copy link
Contributor

MissiaL commented May 16, 2020

For me too. I will test you changes

@tfranzel
Copy link
Owner Author

awesome! i merged it. lets see where it takes us. thanks for checking it out.

@MissiaL
Copy link
Contributor

MissiaL commented May 18, 2020

I checked changes
So I see that changes are broken my scheme
image
This creates problems.
The drf_yasg does not do this and maybe it will also break the scheme for future users

We use the request validator https://github.com/p1c2u/openapi-core and now it swears at these required fields

@tfranzel
Copy link
Owner Author

@MissiaL i just remembered why this is problematic. for us it is primarily a code generator issue. do you use the schema for code generation or only for display?

https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#fixed-fields-20

If the property is marked as readOnly being true and is in the required list, the required will take effect on the response only.

so strictly speaking validation should not complain about that afais. the spec also states that the written word overrules the json schema specification.

for us it is mainly a typescript generation issue which i encoutered just now.

@tfranzel
Copy link
Owner Author

@MissiaL i'm on the fence on reverting this.

  • could you elaborate on your openapi-core validation issue?
  • do you use the schema in any code generators?

i would like to make a more informed decision on how to proceed.

@MissiaL
Copy link
Contributor

MissiaL commented May 19, 2020

The problem was in our versioning
Some fields should be absent in the schema, but this does not work in the schema generator
#56

@tfranzel
Copy link
Owner Author

@MissiaL with the fix i proposed in #56, is this issue resolved?

@MissiaL
Copy link
Contributor

MissiaL commented May 19, 2020

I have not tested this implementation yet. I will study and inform here soon

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

No branches or pull requests

3 participants