Skip to content

fix: build Path<Struct> parameters from fields(), not scraped properties - #74

Merged
Kilerd merged 1 commit into
mainfrom
fix/path-struct-params-under-schema-collection
Aug 13, 2026
Merged

fix: build Path<Struct> parameters from fields(), not scraped properties#74
Kilerd merged 1 commit into
mainfrom
fix/path-struct-params-under-schema-collection

Conversation

@Kilerd

@Kilerd Kilerd commented Aug 13, 2026

Copy link
Copy Markdown
Owner

Problem

Since the schema-collection mode landed, every operation is generated inside a registry::collect scope, where a derived struct's generate_schema() returns a bare $ref (registering the real schema under components/schemas). Path<T>::generate detected the struct case by scraping properties out of the generated schema — a $ref carries no properties, so it fell through to the simple-type branch:

  • the first URL parameter got the whole object's $ref as its schema, and
  • every other field of a multi-field path struct was dropped from the documented parameters.

Query<T> was unaffected because it already reads T::fields() first, which is registry-independent.

Fix

Align Path<T> with Query<T>: read T::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-written Schematic impls without fields(), 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 $ref to its string-enum component, which is valid and arguably better.

Tests

Two regression tests in gotcha/tests/test_path_params.rs: a two-field Path<ConnectionPath> must produce two per-field parameters with inline string schemas, 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 and cargo fmt --check.

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().
@Kilerd
Kilerd merged commit 8232061 into main Aug 13, 2026
11 checks passed
@Kilerd Kilerd mentioned this pull request Aug 13, 2026
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.

1 participant