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

fix: Move all parameters from query to JSON body #105

Merged
merged 1 commit into from
Jun 6, 2024

Conversation

provokateurin
Copy link
Member

@provokateurin provokateurin commented Mar 15, 2024

Closes #88

This fixes a lot of cases where the query parameters was just typed as string because it was not possible to correctly set the type.

Copy link

@come-nc come-nc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on security_guard and looks promising.

Copy link
Member

@nickvergessen nickvergessen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs at least more documentation

generate-spec Outdated Show resolved Hide resolved
@nickvergessen nickvergessen force-pushed the refactor/array-merge-associative-arrays branch from cd537bc to 6b02989 Compare March 25, 2024 16:02
@delete-merged-branch delete-merged-branch bot deleted the branch main March 25, 2024 16:13
@provokateurin provokateurin changed the base branch from refactor/array-merge-associative-arrays to main April 9, 2024 12:09
@provokateurin provokateurin force-pushed the refactor/non-atomic-parameters-body branch from 71cfaff to 826eaf2 Compare June 4, 2024 08:07
@provokateurin provokateurin changed the title refactor: Put non-atomic parameters into body fix: Move all parameters from query to JSON body Jun 4, 2024
@provokateurin
Copy link
Member Author

I will still have to do some testing to ensure the updated specs are correct.

@provokateurin
Copy link
Member Author

My API unit test suite from https://github.com/nextcloud/neon/tree/main/packages/nextcloud/test confirms that these specs work exactly as intended. From my side this is ready to be merged.

Copy link

@come-nc come-nc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work fine with ocs_api_viewer app?

@provokateurin
Copy link
Member Author

It should, but let me give it a try

@provokateurin
Copy link
Member Author

Oof, it seems like ocs_api_viewer is broken in that regard because it doesn't send the body at all. This has to be a bug in the library as the body is also not added to the code examples, but I couldn't find an issue about it 🤔

@provokateurin
Copy link
Member Author

After another quick check it makes somewhat sense: GET requests are "not allowed" to have request bodies, so this is likely why it is omitted. This is not really true though, as the spec does not forbid and it is just considered undefined behavior while most web servers just handle it right (See the note at the top of https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET). All other endpoints are fine, I was just unlucky to select a GET endpoint when I quickly tested it (or rather lucky because this way I found the problem).
So we could change this to only move the parameters in case it is not a GET or DELETE operation, but that won't solve the serialization problems that are the driving force behind this PR. I would vote for ignoring this as the changes are required to send valid requests in quite a few cases and the "forbidden" part is not our problem but rather a different interpretation of the spec which is not correct IMO. I would also go and change this in the stoplight/elements library we use in ocs_api_viewer to make this work for us.

@come-nc @nickvergessen what do you think?

@nickvergessen
Copy link
Member

Sounds okay.

@come-nc
Copy link

come-nc commented Jun 6, 2024

So we could change this to only move the parameters in case it is not a GET or DELETE operation, but that won't solve the serialization problems that are the driving force behind this PR. I would vote for ignoring this as the changes are required to send valid requests in quite a few cases and the "forbidden" part is not our problem but rather a different interpretation of the spec which is not correct IMO. I would also go and change this in the stoplight/elements library we use in ocs_api_viewer to make this work for us.

I’m fine with both solutions, either putting parameters into body only for non-GET requests, or for all of them.
It’s more common to have complex parameters for POST/PUT I suppose, but a GET on a search endpoint might have complex objects for the filter for instance.

@provokateurin
Copy link
Member Author

@nickvergessen do you want to do a final review or can I go ahead and merge?

@nickvergessen
Copy link
Member

Go ahead, still having more than 700 unread emails and this is not a prio for me atm.

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

Successfully merging this pull request may close these issues.

Support body parameters
4 participants