You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello here 👋😊! First: thank you very much for the awesome work done in this repo 🙏 😍 !
I try to fill the generated documentation with "examples", especially for a QueryParam.
Here are the changes I made in examples/example-axum/src/todos/routes.rs in order to do some tests, focusing on the /todo/{id}/complete use case (I also imported Query from axum::extract):
Image:
Code:
#[derive(Debug,Serialize,Deserialize,JsonSchema)]pubstructInt32DefaultedTo20(pubu32);implDefaultforInt32DefaultedTo20{fndefault() -> Self{Int32DefaultedTo20(20)}}implCloneforInt32DefaultedTo20{fnclone(&self) -> Self{Int32DefaultedTo20(self.0.clone())}}fnindex_serde_defaulted_with_value_fn() -> u32{22}#[derive(Debug,Serialize,Deserialize,JsonSchema)]pubstructStringDefaultedToHello(pubString);implDefaultforStringDefaultedToHello{fndefault() -> Self{StringDefaultedToHello("hello".to_string())}}implCloneforStringDefaultedToHello{fnclone(&self) -> Self{StringDefaultedToHello(self.0.clone())}}fntext_serde_defaulted_with_value_fn() -> String{"text_serde_default_value".to_string()}#[derive(Deserialize,Debug,JsonSchema)]pubstructCompleteTodoQuery{/// The index#[validate(range(min = 18, max = 20))]pubindex:u32,/// The index_as_u32_20#[validate(range(min = 19, max = 21))]pubindex_as_u32_20:Int32DefaultedTo20,/// The index_serde_defaulted#[validate(range(min = 20, max = 22))]#[serde(default)]pubindex_serde_defaulted:u32,/// The index_serde_defaulted_with_value#[validate(length(min = 21, max = 23))]#[serde(default = "index_serde_defaulted_with_value_fn")]pubindex_serde_defaulted_with_value:u32,/// The text#[validate(length(min = 1))]pubtext:String,/// The text_as_string_hello#[validate(length(min = 2))]pubtext_as_string_hello:StringDefaultedToHello,/// The text_serde_defaulted#[validate(length(min = 3))]#[serde(default)]pubtext_serde_defaulted:String,/// The text_serde_defaulted_with_value#[validate(length(min = 4))]#[serde(default = "text_serde_defaulted_with_value_fn")]pubtext_serde_defaulted_with_value:String,}asyncfncomplete_todo(State(app):State<AppState>,Path(todo):Path<SelectTodo>,Query(query):Query<CompleteTodoQuery>,) -> implIntoApiResponse{println!("query: {:?}", query);ifletSome(todo) = app.todos.lock().unwrap().get_mut(&todo.id){
todo.complete = true;StatusCode::NO_CONTENT}else{StatusCode::NOT_FOUND}}
Here are the results at http://127.0.0.1:3000/docs:
View:
Send Request:
I noticed the following:
text_serde_defaulted is missing
index_serde_defaulted has 0 as value and is not visible in the curl example, whereas without serde_default it was 1 and it was visible in the curl example
What I would like is to have a way to set an example value for a query param:
This value requires to be independent from the "required" state of the query param (they are not really "defaults" but "examples")
This value requires be visible:
In the curl example of the main view (curl request ready to copy/paste with example values)
In the Send Request view, as the value in the cell in the "value" column related to the query param
Does anyone have some keys or tricks to achieve this need? 🍀 😬
The text was updated successfully, but these errors were encountered:
hadrien-toma
changed the title
QueryParams usage
QueryParam generated documentation usage
Aug 12, 2024
Hello here 👋😊! First: thank you very much for the awesome work done in this repo 🙏 😍 !
I try to fill the generated documentation with "examples", especially for a QueryParam.
Here are the changes I made in
examples/example-axum/src/todos/routes.rs
in order to do some tests, focusing on the/todo/{id}/complete
use case (I also importedQuery
fromaxum::extract
):Here are the results at
http://127.0.0.1:3000/docs
:I noticed the following:
text_serde_defaulted
is missingindex_serde_defaulted
has0
as value and is not visible in thecurl
example, whereas without serde_default it was1
and it was visible in thecurl
exampleWhat I would like is to have a way to set an example value for a query param:
curl
example of the main view (curl request ready to copy/paste with example values)Does anyone have some keys or tricks to achieve this need? 🍀 😬
The text was updated successfully, but these errors were encountered: