Skip to content

Commit 0ce7dbb

Browse files
committed
Add complex
1 parent b659e7a commit 0ce7dbb

3 files changed

Lines changed: 215 additions & 2 deletions

File tree

examples/axum-example/openapi.json

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,33 @@
2727
}
2828
}
2929
},
30+
"/complex-struct-body": {
31+
"post": {
32+
"operationId": "mod_file_with_complex_struct_body",
33+
"requestBody": {
34+
"required": true,
35+
"content": {
36+
"application/json": {
37+
"schema": {
38+
"$ref": "#/components/schemas/ComplexStructBody"
39+
}
40+
}
41+
}
42+
},
43+
"responses": {
44+
"200": {
45+
"description": "Successful response",
46+
"content": {
47+
"application/json": {
48+
"schema": {
49+
"type": "string"
50+
}
51+
}
52+
}
53+
}
54+
}
55+
}
56+
},
3057
"/health": {
3158
"get": {
3259
"operationId": "health",
@@ -268,6 +295,69 @@
268295
},
269296
"components": {
270297
"schemas": {
298+
"ComplexStructBody": {
299+
"type": "object",
300+
"properties": {
301+
"age": {
302+
"type": "integer"
303+
},
304+
"array": {
305+
"type": "array",
306+
"items": {
307+
"type": "string"
308+
}
309+
},
310+
"map": {
311+
"type": "object"
312+
},
313+
"name": {
314+
"type": "string"
315+
},
316+
"nested_array": {
317+
"type": "array",
318+
"items": {
319+
"$ref": "#/components/schemas/StructBodyWithOptional"
320+
}
321+
},
322+
"nested_map": {
323+
"type": "object"
324+
},
325+
"nested_struct": {
326+
"$ref": "#/components/schemas/StructBodyWithOptional"
327+
},
328+
"nested_struct_array": {
329+
"type": "array",
330+
"items": {
331+
"$ref": "#/components/schemas/StructBodyWithOptional"
332+
}
333+
},
334+
"nested_struct_array_map": {
335+
"type": "array",
336+
"items": {
337+
"type": "object"
338+
}
339+
},
340+
"nested_struct_map": {
341+
"type": "object"
342+
},
343+
"nested_struct_map_array": {
344+
"type": "object"
345+
}
346+
},
347+
"required": [
348+
"name",
349+
"age",
350+
"nested_struct",
351+
"array",
352+
"map",
353+
"nested_array",
354+
"nested_map",
355+
"nested_struct_array",
356+
"nested_struct_map",
357+
"nested_struct_array_map",
358+
"nested_struct_map_array"
359+
]
360+
},
271361
"StructBody": {
272362
"type": "object",
273363
"properties": {

examples/axum-example/src/routes/mod.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub async fn mod_file_with_struct_body(Json(body): Json<StructBody>) -> String {
5050
format!("name: {}, age: {}", body.name, body.age)
5151
}
5252

53-
#[derive(Deserialize, Schema)]
53+
#[derive(Deserialize, Schema, Debug)]
5454
pub struct StructBodyWithOptional {
5555
pub name: Option<String>,
5656
pub age: Option<u32>,
@@ -62,3 +62,37 @@ pub async fn mod_file_with_struct_body_with_optional(
6262
) -> String {
6363
format!("name: {:?}, age: {:?}", body.name, body.age)
6464
}
65+
66+
#[derive(Deserialize, Schema)]
67+
#[serde(rename_all = "camelCase")]
68+
pub struct ComplexStructBody {
69+
pub name: String,
70+
pub age: u32,
71+
pub nested_struct: StructBodyWithOptional,
72+
pub array: Vec<String>,
73+
pub map: HashMap<String, String>,
74+
pub nested_array: Vec<StructBodyWithOptional>,
75+
pub nested_map: HashMap<String, StructBodyWithOptional>,
76+
pub nested_struct_array: Vec<StructBodyWithOptional>,
77+
pub nested_struct_map: HashMap<String, StructBodyWithOptional>,
78+
pub nested_struct_array_map: Vec<HashMap<String, StructBodyWithOptional>>,
79+
pub nested_struct_map_array: HashMap<String, Vec<StructBodyWithOptional>>,
80+
}
81+
82+
#[vespera::route(post, path = "/complex-struct-body")]
83+
pub async fn mod_file_with_complex_struct_body(Json(body): Json<ComplexStructBody>) -> String {
84+
format!(
85+
"name: {}, age: {}, nested_struct: {:?}, array: {:?}, map: {:?}, nested_array: {:?}, nested_map: {:?}, nested_struct_array: {:?}, nested_struct_map: {:?}, nested_struct_array_map: {:?}, nested_struct_map_array: {:?}",
86+
body.name,
87+
body.age,
88+
body.nested_struct,
89+
body.array,
90+
body.map,
91+
body.nested_array,
92+
body.nested_map,
93+
body.nested_struct_array,
94+
body.nested_struct_map,
95+
body.nested_struct_array_map,
96+
body.nested_struct_map_array
97+
)
98+
}

examples/axum-example/tests/snapshots/integration_test__openapi.snap

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
---
22
source: examples/axum-example/tests/integration_test.rs
3-
assertion_line: 128
43
expression: openapi
54
---
65
{
@@ -32,6 +31,33 @@ expression: openapi
3231
}
3332
}
3433
},
34+
"/complex-struct-body": {
35+
"post": {
36+
"operationId": "mod_file_with_complex_struct_body",
37+
"requestBody": {
38+
"required": true,
39+
"content": {
40+
"application/json": {
41+
"schema": {
42+
"$ref": "#/components/schemas/ComplexStructBody"
43+
}
44+
}
45+
}
46+
},
47+
"responses": {
48+
"200": {
49+
"description": "Successful response",
50+
"content": {
51+
"application/json": {
52+
"schema": {
53+
"type": "string"
54+
}
55+
}
56+
}
57+
}
58+
}
59+
}
60+
},
3561
"/health": {
3662
"get": {
3763
"operationId": "health",
@@ -273,6 +299,69 @@ expression: openapi
273299
},
274300
"components": {
275301
"schemas": {
302+
"ComplexStructBody": {
303+
"type": "object",
304+
"properties": {
305+
"age": {
306+
"type": "integer"
307+
},
308+
"array": {
309+
"type": "array",
310+
"items": {
311+
"type": "string"
312+
}
313+
},
314+
"map": {
315+
"type": "object"
316+
},
317+
"name": {
318+
"type": "string"
319+
},
320+
"nested_array": {
321+
"type": "array",
322+
"items": {
323+
"$ref": "#/components/schemas/StructBodyWithOptional"
324+
}
325+
},
326+
"nested_map": {
327+
"type": "object"
328+
},
329+
"nested_struct": {
330+
"$ref": "#/components/schemas/StructBodyWithOptional"
331+
},
332+
"nested_struct_array": {
333+
"type": "array",
334+
"items": {
335+
"$ref": "#/components/schemas/StructBodyWithOptional"
336+
}
337+
},
338+
"nested_struct_array_map": {
339+
"type": "array",
340+
"items": {
341+
"type": "object"
342+
}
343+
},
344+
"nested_struct_map": {
345+
"type": "object"
346+
},
347+
"nested_struct_map_array": {
348+
"type": "object"
349+
}
350+
},
351+
"required": [
352+
"name",
353+
"age",
354+
"nested_struct",
355+
"array",
356+
"map",
357+
"nested_array",
358+
"nested_map",
359+
"nested_struct_array",
360+
"nested_struct_map",
361+
"nested_struct_array_map",
362+
"nested_struct_map_array"
363+
]
364+
},
276365
"StructBody": {
277366
"type": "object",
278367
"properties": {

0 commit comments

Comments
 (0)