fix: build Path<Struct> parameters from fields(), not scraped properties - #74
Merged
Merged
Conversation
During spec assembly a schema-collection scope is active, so a derived struct's generate_schema() returns a bare $ref with no properties. The properties-scraping branch in Path<T>::generate then found nothing and fell through to the simple-type branch, which emitted the whole object's $ref as the schema of the first URL parameter and dropped every other field of a multi-field path struct. Read T::fields() first instead, as Query<T> already does: it is registry-independent, so each field becomes one path parameter with its own schema, requiredness and description in both inline and collection modes. The properties branch stays as a fallback for hand-written Schematic impls without fields().
Merged
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.
Problem
Since the schema-collection mode landed, every operation is generated inside a
registry::collectscope, where a derived struct'sgenerate_schema()returns a bare$ref(registering the real schema undercomponents/schemas).Path<T>::generatedetected the struct case by scrapingpropertiesout of the generated schema — a$refcarries no properties, so it fell through to the simple-type branch:$refas its schema, andQuery<T>was unaffected because it already readsT::fields()first, which is registry-independent.Fix
Align
Path<T>withQuery<T>: readT::fields()first, emitting one path parameter per field with its own schema, requiredness and description — identical output inside and outside a collection scope. The properties-scraping branch stays as a fallback for hand-writtenSchematicimpls withoutfields(), and the simple-type branch is unchanged.Adjacent cases checked: newtype derives don't go through
schema_or_ref, so they stay inline; a simple enum as a path segment now documents as a$refto its string-enum component, which is valid and arguably better.Tests
Two regression tests in
gotcha/tests/test_path_params.rs: a two-fieldPath<ConnectionPath>must produce two per-field parameters with inlinestringschemas, both outside and inside a collection scope (the latter failed before this fix with one parameter holding the object$ref).Verified with
cargo test -p gotcha_core --features axum,cargo test -p gotcha --all-features, clippy andcargo fmt --check.