Preserve optional Swagger parameters as option types - #546
Closed
Smaug123 wants to merge 1 commit into
Closed
Conversation
This was referenced Jul 9, 2026
Smaug123
force-pushed
the
swagger-consumes-produces
branch
from
July 10, 2026 12:57
056acd9 to
2677778
Compare
SwaggerParameter.Required was parsed but discarded, so every generated parameter was unconditionally mandatory even though Swagger 2 defaults non-path parameters to optional. Query parameters without required: true are now option-typed (path parameters stay required per the spec; optional bodies are not modelled), e.g. AdminCronList(page : int option, limit : int option). To support that, the HTTP client generator now understands option-typed [<Query>] parameters: the query string is computed at runtime as a List.choose/String.concat over per-parameter string option components and appended (with separator) only when nonempty, so None is omitted from the URL and an all-None query leaves the URL bare. Required-only query strings are byte-identical to before. The joining lambda is deliberately not `id`, which Gitea methods shadow with a parameter of that name. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Smaug123
force-pushed
the
optional-query-params
branch
from
July 10, 2026 17:24
cd8a3bc to
abd3925
Compare
Owner
Author
|
At the very least this should probably come with a major version bump |
Owner
Author
|
Hmm. I really don't like this change and I think it probably shouldn't go in. People are presumably not diligently annotating all their parameters as "required", so this will cause so much noise. |
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.
Fifth fix split out of #540; stacked on #545.
SwaggerParameter.Requiredwas parsed but discarded, so every generated parameter was unconditionally mandatory, even though Swagger 2 defaults non-path parameters to optional. 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).To support that, the HTTP client generator now understands option-typed
[<Query>]parameters: the query string is computed at runtime as aList.choose/String.concatover per-parameterstring optioncomponents, and appended (with separator) only when nonempty — soNoneis omitted from the URL and an all-Nonequery leaves the URL 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.)Tests were written first and observed failing (
page=Some%283%29in the URL):TestOptionalQueryParam.fscovers mixed present/missing/escaped/bare cases through a hand-written interface, andTestGiteaClient.fsgains end-to-endAdminCronListcoverage for bothNoneandSome.Note: #541 rewrites this same query-string block off
mainto fix list-typed parameters; whichever merges second conflicts there. Reconciliation: unify onstring listcomponents, mapping optional scalars viaOption.toList.🤖 Generated with Claude Code