|
1 | | -use openapi_to_rust::config::ServerSection; |
| 1 | +use openapi_to_rust::config::{ServerSection, ServerValidationSection}; |
2 | 2 | use openapi_to_rust::streaming::{StreamingConfig, StreamingEndpoint}; |
3 | | -use openapi_to_rust::type_mapping::{DurationStrategy, TypeMappingConfig}; |
| 3 | +use openapi_to_rust::type_mapping::{BinaryStrategy, DurationStrategy, TypeMappingConfig}; |
4 | 4 | use openapi_to_rust::{CodeGenerator, GeneratorConfig, RetryConfig, SchemaAnalyzer, TypeMapper}; |
5 | 5 | use serde_json::json; |
6 | 6 | use std::collections::BTreeSet; |
@@ -49,9 +49,15 @@ fn requirements_spec() -> serde_json::Value { |
49 | 49 | "responses": { "204": { "description": "ok" } } |
50 | 50 | } |
51 | 51 | }, |
52 | | - "/upload": { |
| 52 | + "/upload/{id}.json": { |
53 | 53 | "post": { |
54 | 54 | "operationId": "uploadPayload", |
| 55 | + "parameters": [{ |
| 56 | + "name": "id", |
| 57 | + "in": "path", |
| 58 | + "required": true, |
| 59 | + "schema": { "type": "string" } |
| 60 | + }], |
55 | 61 | "requestBody": { |
56 | 62 | "required": true, |
57 | 63 | "content": { |
@@ -266,6 +272,62 @@ fn disabled_sse_feature_does_not_emit_streaming_code_or_dependencies() { |
266 | 272 | assert!(!dependency_names(&result).contains("futures-util")); |
267 | 273 | } |
268 | 274 |
|
| 275 | +#[test] |
| 276 | +fn multipart_server_enables_axum_multipart_feature() { |
| 277 | + let result = compile_case( |
| 278 | + "multipart-server", |
| 279 | + GeneratorConfig { |
| 280 | + enable_async_client: false, |
| 281 | + enable_sse_client: false, |
| 282 | + tracing_enabled: false, |
| 283 | + server: Some(ServerSection { |
| 284 | + framework: "axum".into(), |
| 285 | + operations: vec!["uploadPayload".into()], |
| 286 | + prune_models: false, |
| 287 | + validation: Default::default(), |
| 288 | + }), |
| 289 | + ..Default::default() |
| 290 | + }, |
| 291 | + ); |
| 292 | + let axum = result |
| 293 | + .required_deps |
| 294 | + .iter() |
| 295 | + .find(|dependency| dependency.crate_name == "axum") |
| 296 | + .expect("axum dependency"); |
| 297 | + assert_eq!(axum.features, vec!["json", "multipart"]); |
| 298 | +} |
| 299 | + |
| 300 | +#[test] |
| 301 | +fn multipart_client_and_server_compile_for_every_binary_strategy() { |
| 302 | + for (name, binary) in [ |
| 303 | + ("multipart-binary-bytes", BinaryStrategy::Bytes), |
| 304 | + ("multipart-binary-vec", BinaryStrategy::VecU8), |
| 305 | + ("multipart-binary-string", BinaryStrategy::String), |
| 306 | + ] { |
| 307 | + compile_case( |
| 308 | + name, |
| 309 | + GeneratorConfig { |
| 310 | + enable_sse_client: false, |
| 311 | + tracing_enabled: false, |
| 312 | + types: TypeMappingConfig { |
| 313 | + binary, |
| 314 | + ..Default::default() |
| 315 | + }, |
| 316 | + server: Some(ServerSection { |
| 317 | + framework: "axum".into(), |
| 318 | + operations: vec!["uploadPayload".into()], |
| 319 | + prune_models: false, |
| 320 | + validation: ServerValidationSection { |
| 321 | + enabled: false, |
| 322 | + ..Default::default() |
| 323 | + }, |
| 324 | + }), |
| 325 | + ..Default::default() |
| 326 | + }, |
| 327 | + ); |
| 328 | + } |
| 329 | +} |
| 330 | + |
269 | 331 | #[test] |
270 | 332 | fn every_generation_mode_compiles_from_its_exact_dependency_fragment() { |
271 | 333 | let types = compile_case( |
|
0 commit comments