Fix six correctness defects in Swagger 2 generation and capturing mocks - #540
Closed
Smaug123 wants to merge 1 commit into
Closed
Fix six correctness defects in Swagger 2 generation and capturing mocks#540Smaug123 wants to merge 1 commit into
Smaug123 wants to merge 1 commit into
Conversation
Swagger 2 parsing (SwaggerV2.fs):
- Endpoint responses were fed whole Response Objects to Definition.Parse,
so inline {description, schema} responses degraded to Unspecified and
generated Task<unit> clients. Responses now go through Response.Parse
and use its schema; $refs are handled as before. Inline endpoint
schemas (responses and parameters) are also now seeded into type
generation, so anonymous inline object schemas get generated types.
- Response keys were unconditionally Int32.Parsed, so any spec with a
"default" response aborted generation. Responses are now keyed by a
ResponseKey DU (Code of int | Default), and the generator explicitly
ignores Default when selecting the success response.
Swagger 2 client generation (SwaggerClientGenerator.fs):
- Integer formats were ignored; "format": "int64" now renders as int64
instead of narrowing 64-bit IDs to int.
- The request Content-Type header was derived from Produces, and
Consumes was dropped entirely. Content-Type now comes from Consumes
and Produces is sent as the Accept header, both as full MIME strings
(endpoint-level lists override the spec-global ones). This made the
StartsWith active pattern dead, so Text.fs is deleted.
- SwaggerParameter.Required was parsed and discarded, making every
parameter mandatory. Query parameters without required: true are now
option-typed, and None is omitted from the URL.
HTTP client generation (HttpClientGenerator.fs):
- Option-typed [<Query>] parameters are supported: the query string is
now computed at runtime and appended (with separator) only when
nonempty, so a URL with all-None query parameters stays bare.
Capturing mock generation (CapturingInterfaceMockGenerator.fs):
- Property getters logged nothing; they now record into Calls under a
lock, like methods do.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This was referenced Jul 9, 2026
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.
Fixes six review findings, each with a failing test written and observed before the fix. The suite grows from 769 to 788 tests, all passing.
Swagger 2 parsing (
SwaggerV2.fs)Definition.Parse, so inline{description, schema}responses degraded toUnspecifiedand generatedTask<unit>clients that discard the body. Responses now go throughResponse.Parse(moved aboveSwaggerEndpoint) and use its schema;$refresponses 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 crashingrenderType— Gitea's/users/search,/orgs/{org}/teams/searchand the twosigning-key.gpgendpoints now return real types.Int32.Parsed, so any valid spec with adefaultresponse aborted generation. Responses are now keyed by aResponseKeyDU (Code of int | Default), and the client generator explicitly ignoresDefaultwhen selecting the success response.Swagger 2 client generation (
SwaggerClientGenerator.fs)"format": "int64"now renders asint64in bothdefnToTypeandrenderTypeinstead of narrowing 64-bit IDs toint(e.g.IssueGetCommentsnow takesindex : int64).ProducesandConsumeswas dropped: Gitea'srenderMarkdownRaw(consumestext/plain, producestext/html) sentStringContenttaggedtext/html. Content-Type now comes fromConsumesandProducesis translated to anAcceptheader, both as full MIME strings; endpoint-level lists override the spec-global ones, and an ambiguous multi-entry global list prefersapplication/jsonor fails loudly. This made theStartsWithactive pattern dead, soText.fsis deleted.SwaggerParameter.Requiredwas parsed and discarded, so every generated parameter was mandatory. Query parameters withoutrequired: trueare now option-typed (path parameters stay required per the spec; optional bodies are not modelled), e.g.AdminCronList(page : int option, limit : int option).HTTP client generation (
HttpClientGenerator.fs)[<Query>]parameters are supported: the query string is computed at runtime as aList.choose/String.concatover per-parameterstring optioncomponents and appended (with separator) only when nonempty, soNoneis omitted and an all-NoneURL stays bare. Required-only query strings are byte-identical to before. (The joining lambda is deliberately notid, which Gitea methods shadow with a parameter of that name.)Capturing mock generation (
CapturingInterfaceMockGenerator.fs)Calls.Prop1/Calls.Prop2stayed empty forever. They now record intoCallsunder a lock, mirroring method implementations.Not addressed (pre-existing, noted during review)
List-typed query parameters (e.g.
NotifyGetList'sstatus_types : string list) are stringified with.ToString(), producing F# list syntax in the URL; that fix is coming separately.🤖 Generated with Claude Code