-
How do I specify a default value for a parameter when using the Path attribute macro? TIA |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The Parameter OpenAPI Type does not itself have What could be done, is something like this seen below. We create a custom schema type with custom default value and then inline it as parameter type. #[derive(ToSchema)]
#[schema(default = "default value")]
struct MyParmater(String)
#[utoipa::path(
params(
("my_parameter = inline(MyParameter))
)
)] |
Beta Was this translation helpful? Give feedback.
The Parameter OpenAPI Type does not itself have
default
attribute. Instead one should either give anexample
which is used as default value by Swagger UI or maybe by giving default value to the schema used for Parameter. Now it might get tricky if the schema used for the Parameter is a String or any other literal type because there is no direct way to give a default value for them.What could be done, is something like this seen below. We create a custom schema type with custom default value and then inline it as parameter type.