Skip to content

[Schema Inaccuracy] Clarify use of default values defined in the schema #2411

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

Open
netomi opened this issue Apr 3, 2023 · 0 comments
Open

Comments

@netomi
Copy link

netomi commented Apr 3, 2023

Schema Inaccuracy

Certain operations, e.g. Update organization define default values for some of their optional body parameters.

According to the openapi specification, a default value is the one that the server uses if the client does not supply the parameter value in the request . In my tests I can not confirm that the server conforms to that.

Expected

I would expect that the rest endpoint honors the default value as specified in the api documentation. In my tests the behavior is quite inconsistent. Usually the default values are not taken into account when an optional values is not specified. I noticed a few corner cases where the server seems to take a default into account when it actually should not (seems like a bug):

have web_commit_signoff_required = true and members_can_create_private_repositories = false
setting web_commit_signoff_required to false will automatically trigger setting members_can_create_private_repositories to true

Reproduction Steps

Making a rest call to update an organization setting a value with a default, e.g.

set members_can_create_public_pages to false which according to the rest spec should have a default of true

curl -X PATCH -H "Accept: application/vnd.github+json" -H "Authorization: Bearer " -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/orgs/OtterdogTest -d "{"members_can_create_public_pages": false}"

set members_can_create_pages to false, which should trigger members_can_create_public_pages to be enabled again

curl -X PATCH -H "Accept: application/vnd.github+json" -H "Authorization: Bearer " -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/orgs/OtterdogTest -d "{"members_can_create_pages": false}"

the result is that both settings are false, no default value seems to be taken into account.

Discussion

In general I find default values for updates to be dangerous, as it forces you to specify all values all the time when updating a specific field. There are some tools (like https://github.com/yanyongyu/githubkit) out there that parse the published schema and honor the api spec, i.e. set default values where specified in the spec. I find this behavior quite surprising and unexpected, sos I would like to have clarification on the purpose of the default value in the rest spec if it matches the intention of the openapi baseline or serves another purpose.

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

No branches or pull requests

2 participants