Skip to content

Parse inline endpoint response schemas - #542

Merged
Smaug123 merged 3 commits into
mainfrom
swagger-inline-response-schemas
Jul 9, 2026
Merged

Parse inline endpoint response schemas#542
Smaug123 merged 3 commits into
mainfrom
swagger-inline-response-schemas

Conversation

@Smaug123

@Smaug123 Smaug123 commented Jul 9, 2026

Copy link
Copy Markdown
Owner

Splits out the first of six fixes from #540 (stack: this ← #543#544#545#546; see also the independent capturing-mock fix).

Endpoint responses fed the whole Response Object to Definition.Parse, so an inline {description, schema} response has neither $ref nor a top-level type and degraded to Definition.Unspecified, generating Task<unit> clients that silently discard the body. Responses now go through Response.Parse (moved above SwaggerEndpoint) and use its schema; $ref responses are handled as before.

Making those schemas parse exposed a second gap: inline schemas under paths were never fed through defnToType, so renderType crashed on anonymous inline objects. Endpoint response and parameter schemas are now seeded into type generation (with no handle name); previously, inline parameter types only rendered when they happened to collide with an identically-shaped named definition in the cache.

Gitea's /users/search, /orgs/{org}/teams/search, and the two signing-key.gpg endpoints now return real types (Type9/Type10/string) instead of Task<unit>.

Test was written first and observed failing: the inline 200 response parsed as Unspecified.

🤖 Generated with Claude Code

Endpoint responses fed the whole Response Object to Definition.Parse,
so an inline {description, schema} response has neither $ref nor a
top-level type and degraded to Definition.Unspecified, generating
Task<unit> clients that discard the body. Responses now go through
Response.Parse (moved above SwaggerEndpoint) and use its schema; $ref
responses are handled as before.

Inline endpoint schemas (both responses and parameters) are also now
seeded into type generation, so anonymous inline object schemas get
generated types instead of crashing renderType; previously, inline
parameter types only rendered when they happened to collide with a
named definition in the cache. Gitea's /users/search,
/orgs/{org}/teams/search and the two signing-key.gpg endpoints now
return real types.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Anonymous inline schemas were named Type1, Type2, ... without checking
the names already taken by the spec's definitions and responses, so a
valid spec defining a type called "Type1" alongside an inline object
schema generated two `type Type1` declarations and failed to compile
with FS0037. The anonymous-name counter now starts past any sanitised
definition/response name of the form Type{N}.

Verified at the level the repo's generators are tested at: the new
swagger-anonymous-types.json in ConsumePlugin defines "Type1" plus an
inline object response, so a regression here fails the build. (An
in-process generate test isn't currently possible: WoofWare.Expect
forces Fantomas.FCS 7.0.3 in the test project, which is binary-
incompatible with the Fantomas.FCS 6.1.1 that WoofWare.Whippet.Fantomas
0.7.3 was compiled against, so calling the generator's AST construction
from the test host throws MissingMethodException.)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@Smaug123

Smaug123 commented Jul 9, 2026

Copy link
Copy Markdown
Owner Author

Fixed in 57a533c. The anonymous-name counter now starts past any sanitised definition/response name of the form Type{N}, so the spec's own Type1 is preserved and the inline schema becomes Type2.

Verified at the level this repo tests generators: swagger-anonymous-types.json in ConsumePlugin defines Type1 alongside an inline object response, so a regression fails the build with FS0037 (observed before the fix). An in-process generate test isn't currently possible: WoofWare.Expect forces Fantomas.FCS 7.0.3 in the test project, which is binary-incompatible with the Fantomas.FCS 6.1.1 that WoofWare.Whippet.Fantomas 0.7.3 was compiled against, so calling the generator's AST construction from the test host throws MissingMethodException.

The fix has been merged forward through the rest of the stack (#543#546); each branch rebuilt and passed its full suite.

Seeding the anonymous-name counter to the largest spec-defined Type{N}
overflows on a valid schema named Type2147483647: the next
Interlocked.Increment wraps to Int32.MinValue and produces a type
declared (sanitised) as Type2147483648 but referenced as
Type-2147483648, failing with FS0010. Instead of seeding, the allocator
now skips over a set of taken (sanitised) definition/response names, so
no name can push the counter anywhere near overflow.

The ConsumePlugin regression spec now also defines Type2147483647
(structurally distinct from Type1, since identical shapes are collapsed
into one generated type), so both the collision and the overflow fail
the build if reintroduced.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@Smaug123

Smaug123 commented Jul 9, 2026

Copy link
Copy Markdown
Owner Author

Fixed in a196b18. Confirmed the overflow: a definition named Type2147483647 seeded the counter to Int32.MaxValue, the next increment wrapped, and the generated file declared Type2147483648 (sanitised) while referencing Type-2147483648 — FS0010, as you predicted.

As suggested, the seeding scheme is gone: defnToType now takes a nextAnonymousTypeName : unit -> string allocator, built in generate over a set of taken (sanitised) definition/response names, which skips occupied Type{N} names one at a time. No spec-supplied name can move the counter, so wraparound would require actually generating 2^31 anonymous types.

swagger-anonymous-types.json now also defines Type2147483647 (structurally distinct from Type1, since identical shapes are deduplicated into one generated type), so both the collision and the overflow break the build if reintroduced. Propagated through #543#546; all branches green.

@Smaug123
Smaug123 merged commit d7440bb into main Jul 9, 2026
20 checks passed
@Smaug123
Smaug123 deleted the swagger-inline-response-schemas branch July 9, 2026 23:05
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