Infer path parameters from scalar and tuple Path extractors#299
Open
hniksic wants to merge 1 commit into
Open
Conversation
`Path<Uuid>`, `Path<(Uuid, u64)>` and other non-struct `Path<T>` extractors no longer produce operations with missing path parameters. Each placeholder in the URL template now appears as a `Parameter::Path` with a schema derived from the extractor type.
c59cf43 to
7246c20
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #113.
If a handler uses
Path<(Uuid, u64)>orPath<Uuid>on a route with placeholders, aide currently emits an operation with noparametersat all. This caused issues with scalar and is rejected by strict validators. The workaround is to use a one-field struct, but that is noisy and duplicates information that's already in the route template (the name) and the extractor (type).This makes aide infer parameters from the extractor type. E.g.:
Path<Uuid>on/users/{id}is interpreted as oneidparameter, uuid-formatted string.Path<(Uuid, u64)>on/users/{u}/posts/{p}-> two parameters in order, with the right types.Path<SomeStruct>- unchanged.Note that the
x-aide-pending-path-paramsextension field is used only for internal book-keeping (to propagate path schemas from the extractor hook to route registration, where placeholder names become available) and doesn't end up in the emitted document.This takes a different approach from #298, as this PR preserves type information (e.g.
format: uuidon uuids).