Skip to content

Strip null from query parameter schemas#275

Merged
jplatte merged 2 commits intotamasfe:mainfrom
hniksic:main
Mar 30, 2026
Merged

Strip null from query parameter schemas#275
jplatte merged 2 commits intotamasfe:mainfrom
hniksic:main

Conversation

@hniksic
Copy link
Copy Markdown
Contributor

@hniksic hniksic commented Jan 14, 2026

Fixes #274.

Query strings cannot express null values - a parameter is either present with a value or absent - so null types in the schema don't make sense and cause issues for SDK generators.

The transformation handles two cases:

  • type: ["string", "null"], changed to type: "string"
  • anyOf: [{$ref: ...}, {type: "null"}], changed to {$ref: ...}

This is enabled by default and can be disabled if needed:

aide::generate::strip_query_null_types(false);

A manual method TransformOpenApi::strip_null_from_query_params() is also available if you need to apply it at a specific point in your transform chain.

Schemars generates null types for Option<T> fields (either
`type: ["string", "null"]` or `anyOf: [{...}, {type: "null"}]`),
but query strings cannot express null values - a parameter is
either present with a value or absent.

This change automatically strips null types from query parameter
schemas during finalization. The behavior is enabled by default
and can be disabled with `strip_query_null_types(false)`.
@jplatte
Copy link
Copy Markdown
Collaborator

jplatte commented Mar 17, 2026

Hey! Sorry for the very long wait time. Could you add a test for this new functionality?

@hniksic
Copy link
Copy Markdown
Contributor Author

hniksic commented Mar 18, 2026

Hey, thanks for looking into it. I've added a test - please let me know if the location is good. (Another option was adding it to existing end-to-end tests in axum/mod.rs, but the functionality is not axum-specific.)

@jplatte jplatte merged commit bae4704 into tamasfe:main Mar 30, 2026
2 checks passed
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.

Query parameter schemas include null types inappropriate for query strings

2 participants