reinhardt-rest 0.1.2

REST API framework aggregator for Reinhardt
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
//! OpenAPI 3.0 types with Reinhardt extensions
//!
//! This module re-exports utoipa's OpenAPI types and provides
//! convenient helper functions and extension traits for easier usage.

// Re-export core utoipa types as Reinhardt's OpenAPI types
pub use utoipa::openapi::{
	Components, Contact, Header, Info, License, OpenApi as OpenApiSchema, PathItem, Paths, RefOr,
	Required, Schema, Server, Tag,
};

// Re-export request/response types
pub use utoipa::openapi::request_body::RequestBody;
pub use utoipa::openapi::response::{Response, Responses};

// Re-export path operation types
pub use utoipa::openapi::path::{Operation, Parameter, ParameterIn};

// Re-export content-related types (MediaType)
pub use utoipa::openapi::Content as MediaType;

// Re-export path-related types
pub use utoipa::openapi::path::ParameterIn as ParameterLocation;

// Re-export security-related types
pub use utoipa::openapi::security::{ApiKey, ApiKeyValue, Http, HttpAuthScheme, SecurityScheme};

/// Convenient type alias for API key location configuration.
pub type ApiKeyLocation = utoipa::openapi::security::ApiKeyValue;

/// Convenient type alias for HTTP authentication scheme.
pub type HttpScheme = HttpAuthScheme;

// Re-export builders
pub use utoipa::openapi::path::{OperationBuilder, ParameterBuilder, PathItemBuilder};
pub use utoipa::openapi::request_body::RequestBodyBuilder;
pub use utoipa::openapi::response::{ResponseBuilder, ResponsesBuilder};
pub use utoipa::openapi::schema::{ArrayBuilder, ObjectBuilder, SchemaType};
pub use utoipa::openapi::tag::TagBuilder;
pub use utoipa::openapi::{
	ComponentsBuilder, ContactBuilder, InfoBuilder, OpenApiBuilder, PathsBuilder, ServerBuilder,
};

/// Extension trait for Schema to provide convenient constructor methods
pub trait SchemaExt {
	/// Create a string schema
	fn string() -> Schema;

	/// Create an integer schema
	fn integer() -> Schema;

	/// Create a number (float) schema
	fn number() -> Schema;

	/// Create a boolean schema
	fn boolean() -> Schema;

	/// Create an empty object schema
	fn object() -> Schema;

	/// Create a date schema (string with format: "date")
	fn date() -> Schema;

	/// Create a datetime schema (string with format: "date-time")
	fn datetime() -> Schema;

	/// Create an array schema with the given item schema
	fn array(items: Schema) -> Schema;

	/// Create an object schema with properties and required fields
	fn object_with_properties(
		properties: Vec<(impl Into<String>, Schema)>,
		required: Vec<impl Into<String>>,
	) -> Schema;

	/// Create an object schema with properties, required fields, and description
	fn object_with_description(
		properties: Vec<(impl Into<String>, Schema)>,
		required: Vec<impl Into<String>>,
		description: impl Into<String>,
	) -> Schema;
}

impl SchemaExt for Schema {
	fn string() -> Schema {
		Schema::Object(
			ObjectBuilder::new()
				.schema_type(SchemaType::Type(utoipa::openapi::Type::String))
				.build(),
		)
	}

	fn integer() -> Schema {
		Schema::Object(
			ObjectBuilder::new()
				.schema_type(SchemaType::Type(utoipa::openapi::Type::Integer))
				.build(),
		)
	}

	fn number() -> Schema {
		Schema::Object(
			ObjectBuilder::new()
				.schema_type(SchemaType::Type(utoipa::openapi::Type::Number))
				.build(),
		)
	}

	fn boolean() -> Schema {
		Schema::Object(
			ObjectBuilder::new()
				.schema_type(SchemaType::Type(utoipa::openapi::Type::Boolean))
				.build(),
		)
	}

	fn object() -> Schema {
		Schema::Object(
			ObjectBuilder::new()
				.schema_type(SchemaType::Type(utoipa::openapi::Type::Object))
				.build(),
		)
	}

	fn date() -> Schema {
		Schema::Object(
			ObjectBuilder::new()
				.schema_type(SchemaType::Type(utoipa::openapi::Type::String))
				.format(Some(utoipa::openapi::SchemaFormat::KnownFormat(
					utoipa::openapi::KnownFormat::Date,
				)))
				.build(),
		)
	}

	fn datetime() -> Schema {
		Schema::Object(
			ObjectBuilder::new()
				.schema_type(SchemaType::Type(utoipa::openapi::Type::String))
				.format(Some(utoipa::openapi::SchemaFormat::KnownFormat(
					utoipa::openapi::KnownFormat::DateTime,
				)))
				.build(),
		)
	}

	fn array(items: Schema) -> Schema {
		Schema::Array(ArrayBuilder::new().items(RefOr::T(items)).build())
	}

	fn object_with_properties(
		properties: Vec<(impl Into<String>, Schema)>,
		required: Vec<impl Into<String>>,
	) -> Schema {
		let mut builder =
			ObjectBuilder::new().schema_type(SchemaType::Type(utoipa::openapi::Type::Object));

		for (name, schema) in properties {
			builder = builder.property(name, schema);
		}

		for req in required {
			builder = builder.required(req);
		}

		Schema::Object(builder.build())
	}

	fn object_with_description(
		properties: Vec<(impl Into<String>, Schema)>,
		required: Vec<impl Into<String>>,
		description: impl Into<String>,
	) -> Schema {
		let mut builder = ObjectBuilder::new()
			.schema_type(SchemaType::Type(utoipa::openapi::Type::Object))
			.description(Some(description.into()));

		for (name, schema) in properties {
			builder = builder.property(name, schema);
		}

		for req in required {
			builder = builder.required(req);
		}

		Schema::Object(builder.build())
	}
}

/// Extension trait for OpenApiSchema to provide convenient methods
pub trait OpenApiSchemaExt {
	/// Create a new OpenApiSchema with title and version
	fn create(title: impl Into<String>, version: impl Into<String>) -> OpenApiSchema;

	/// Add a path to the schema
	fn add_path(&mut self, path: String, item: PathItem);

	/// Add a tag to the schema
	fn add_tag(&mut self, name: String, description: Option<String>);
}

impl OpenApiSchemaExt for OpenApiSchema {
	fn create(title: impl Into<String>, version: impl Into<String>) -> OpenApiSchema {
		OpenApiBuilder::new()
			.info(InfoBuilder::new().title(title).version(version).build())
			.build()
	}

	fn add_path(&mut self, path: String, item: PathItem) {
		self.paths.paths.insert(path, item);
	}

	fn add_tag(&mut self, name: String, description: Option<String>) {
		let mut builder = TagBuilder::new().name(name);
		if let Some(desc) = description {
			builder = builder.description(Some(desc));
		}
		let tag = builder.build();

		if self.tags.is_none() {
			self.tags = Some(Vec::new());
		}
		if let Some(tags) = &mut self.tags {
			tags.push(tag);
		}
	}
}

/// Extension trait for Operation to provide convenient methods
pub trait OperationExt {
	/// Create a new Operation with default values
	fn create() -> Operation;

	/// Add a parameter to the operation
	fn add_parameter(&mut self, parameter: Parameter);

	/// Add a response to the operation
	fn add_response(&mut self, status: impl Into<String>, response: Response);
}

impl OperationExt for Operation {
	fn create() -> Operation {
		// Operation is non-exhaustive, so we must use Default
		Default::default()
	}

	fn add_parameter(&mut self, parameter: Parameter) {
		if self.parameters.is_none() {
			self.parameters = Some(Vec::new());
		}
		if let Some(params) = &mut self.parameters {
			params.push(parameter);
		}
	}

	fn add_response(&mut self, status: impl Into<String>, response: Response) {
		self.responses
			.responses
			.insert(status.into(), response.into());
	}
}

/// Extension trait for Responses to provide collection methods
pub trait ResponsesExt {
	/// Get the number of responses
	fn len(&self) -> usize;

	/// Check if responses collection is empty
	fn is_empty(&self) -> bool;

	/// Check if a specific status code exists
	fn contains_key(&self, status: &str) -> bool;
}

impl ResponsesExt for Responses {
	fn len(&self) -> usize {
		self.responses.len()
	}

	fn is_empty(&self) -> bool {
		self.responses.is_empty()
	}

	fn contains_key(&self, status: &str) -> bool {
		self.responses.contains_key(status)
	}
}

/// Extension trait for Components to provide convenient methods
pub trait ComponentsExt {
	/// Add a schema to the components
	fn add_schema(&mut self, name: String, schema: Schema);
}

impl ComponentsExt for Components {
	fn add_schema(&mut self, name: String, schema: Schema) {
		self.schemas.insert(name, schema.into());
	}
}

/// Extension trait for PathItem to provide constructor
pub trait PathItemExt {
	/// Create a new PathItem
	fn create() -> PathItem;
}

impl PathItemExt for PathItem {
	fn create() -> PathItem {
		PathItem::default()
	}
}

/// Extension trait for Parameter to provide convenient constructors
pub trait ParameterExt {
	/// Create a new Parameter with ParameterBuilder
	fn new_simple(
		name: impl Into<String>,
		location: ParameterIn,
		schema: Schema,
		required: bool,
	) -> Parameter;

	/// Create a new Parameter with description
	fn new_with_description(
		name: impl Into<String>,
		location: ParameterIn,
		schema: Schema,
		required: bool,
		description: impl Into<String>,
	) -> Parameter;
}

impl ParameterExt for Parameter {
	fn new_simple(
		name: impl Into<String>,
		location: ParameterIn,
		schema: Schema,
		required: bool,
	) -> Parameter {
		ParameterBuilder::new()
			.name(name)
			.parameter_in(location)
			.schema(Some(schema))
			.required(if required {
				utoipa::openapi::Required::True
			} else {
				utoipa::openapi::Required::False
			})
			.build()
	}

	fn new_with_description(
		name: impl Into<String>,
		location: ParameterIn,
		schema: Schema,
		required: bool,
		description: impl Into<String>,
	) -> Parameter {
		ParameterBuilder::new()
			.name(name)
			.parameter_in(location)
			.schema(Some(schema))
			.required(if required {
				utoipa::openapi::Required::True
			} else {
				utoipa::openapi::Required::False
			})
			.description(Some(description.into()))
			.build()
	}
}

#[cfg(test)]
mod tests {
	use super::*;

	#[test]
	fn test_schema_helpers() {
		// Test string schema
		let string_schema = Schema::string();
		let json =
			serde_json::to_string(&string_schema).expect("Failed to serialize string schema");
		let parsed: serde_json::Value =
			serde_json::from_str(&json).expect("Failed to parse string schema JSON");
		assert_eq!(
			parsed["type"].as_str(),
			Some("string"),
			"String schema type should be 'string'"
		);

		// Test integer schema
		let integer_schema = Schema::integer();
		let json =
			serde_json::to_string(&integer_schema).expect("Failed to serialize integer schema");
		let parsed: serde_json::Value =
			serde_json::from_str(&json).expect("Failed to parse integer schema JSON");
		assert_eq!(
			parsed["type"].as_str(),
			Some("integer"),
			"Integer schema type should be 'integer'"
		);

		// Test boolean schema
		let boolean_schema = Schema::boolean();
		let json =
			serde_json::to_string(&boolean_schema).expect("Failed to serialize boolean schema");
		let parsed: serde_json::Value =
			serde_json::from_str(&json).expect("Failed to parse boolean schema JSON");
		assert_eq!(
			parsed["type"].as_str(),
			Some("boolean"),
			"Boolean schema type should be 'boolean'"
		);

		// Test number schema
		let number_schema = Schema::number();
		let json =
			serde_json::to_string(&number_schema).expect("Failed to serialize number schema");
		let parsed: serde_json::Value =
			serde_json::from_str(&json).expect("Failed to parse number schema JSON");
		assert_eq!(
			parsed["type"].as_str(),
			Some("number"),
			"Number schema type should be 'number'"
		);

		// Test object schema
		let object_schema = Schema::object();
		let json =
			serde_json::to_string(&object_schema).expect("Failed to serialize object schema");
		let parsed: serde_json::Value =
			serde_json::from_str(&json).expect("Failed to parse object schema JSON");
		assert_eq!(
			parsed["type"].as_str(),
			Some("object"),
			"Object schema type should be 'object'"
		);

		// Test date schema
		let date_schema = Schema::date();
		let json = serde_json::to_string(&date_schema).expect("Failed to serialize date schema");
		let parsed: serde_json::Value =
			serde_json::from_str(&json).expect("Failed to parse date schema JSON");
		assert_eq!(
			parsed["type"].as_str(),
			Some("string"),
			"Date schema type should be 'string'"
		);
		assert_eq!(
			parsed["format"].as_str(),
			Some("date"),
			"Date schema format should be 'date'"
		);

		// Test datetime schema
		let datetime_schema = Schema::datetime();
		let json =
			serde_json::to_string(&datetime_schema).expect("Failed to serialize datetime schema");
		let parsed: serde_json::Value =
			serde_json::from_str(&json).expect("Failed to parse datetime schema JSON");
		assert_eq!(
			parsed["type"].as_str(),
			Some("string"),
			"Datetime schema type should be 'string'"
		);
		assert_eq!(
			parsed["format"].as_str(),
			Some("date-time"),
			"Datetime schema format should be 'date-time'"
		);
	}

	#[test]
	fn test_openapi_schema_new() {
		let schema = <OpenApiSchema as OpenApiSchemaExt>::create("Test API", "1.0.0");

		assert_eq!(
			schema.info.title, "Test API",
			"OpenAPI schema title should match"
		);
		assert_eq!(
			schema.info.version, "1.0.0",
			"OpenAPI schema version should match"
		);

		// Validate JSON structure
		let json = serde_json::to_string(&schema).expect("Failed to serialize OpenAPI schema");
		let parsed: serde_json::Value =
			serde_json::from_str(&json).expect("Failed to parse OpenAPI schema JSON");

		assert_eq!(
			parsed["openapi"].as_str(),
			Some("3.1.0"),
			"OpenAPI version should be 3.1.0"
		);
		assert!(parsed["info"].is_object(), "Info should be an object");
		assert_eq!(
			parsed["info"]["title"].as_str(),
			Some("Test API"),
			"Info title should match"
		);
		assert_eq!(
			parsed["info"]["version"].as_str(),
			Some("1.0.0"),
			"Info version should match"
		);
	}

	#[test]
	fn test_operation_ext() {
		let mut operation = <Operation as OperationExt>::create();
		let param = ParameterBuilder::new()
			.name("id")
			.parameter_in(ParameterIn::Path)
			.required(Required::True)
			.build();

		operation.add_parameter(param);

		assert!(
			operation.parameters.is_some(),
			"Operation should have parameters"
		);
		assert_eq!(
			operation.parameters.as_ref().unwrap().len(),
			1,
			"Operation should have exactly 1 parameter"
		);

		// Validate JSON structure
		let json = serde_json::to_string(&operation).expect("Failed to serialize Operation");
		let parsed: serde_json::Value =
			serde_json::from_str(&json).expect("Failed to parse Operation JSON");

		assert!(
			parsed["parameters"].is_array(),
			"Parameters should be an array"
		);
		let params = parsed["parameters"]
			.as_array()
			.expect("Parameters should be an array");
		assert_eq!(params.len(), 1, "Should have exactly 1 parameter");
		assert_eq!(
			params[0]["name"].as_str(),
			Some("id"),
			"Parameter name should be 'id'"
		);
		assert_eq!(
			params[0]["in"].as_str(),
			Some("path"),
			"Parameter location should be 'path'"
		);
		assert_eq!(
			params[0]["required"],
			serde_json::Value::Bool(true),
			"Parameter should be required"
		);
	}

	#[test]
	fn test_responses_ext() {
		let response = ResponseBuilder::new().description("Success").build();

		let mut responses = ResponsesBuilder::new().build();
		responses
			.responses
			.insert("200".to_string(), response.into());

		assert_eq!(responses.len(), 1, "Responses should have exactly 1 entry");
		assert!(!responses.is_empty(), "Responses should not be empty");
		assert!(
			responses.contains_key("200"),
			"Responses should contain key '200'"
		);

		// Validate JSON structure
		let json = serde_json::to_string(&responses).expect("Failed to serialize Responses");
		let parsed: serde_json::Value =
			serde_json::from_str(&json).expect("Failed to parse Responses JSON");

		assert!(parsed.is_object(), "Responses should be an object");
		assert!(
			parsed["200"].is_object(),
			"Response '200' should be an object"
		);
		assert_eq!(
			parsed["200"]["description"].as_str(),
			Some("Success"),
			"Response description should be 'Success'"
		);
	}

	#[test]
	fn test_openapi_schema_json_structure() {
		let mut schema = <OpenApiSchema as OpenApiSchemaExt>::create("Test API", "1.0.0");

		// Add a path
		let path_item = PathItemBuilder::new().build();
		schema.add_path("/users".to_string(), path_item);

		// Add a tag
		schema.add_tag("users".to_string(), Some("User operations".to_string()));

		// Serialize to JSON
		let json =
			serde_json::to_string_pretty(&schema).expect("Failed to serialize OpenAPI schema");
		let parsed: serde_json::Value =
			serde_json::from_str(&json).expect("Failed to parse OpenAPI schema JSON");

		// Verify OpenAPI version
		assert_eq!(
			parsed["openapi"].as_str(),
			Some("3.1.0"),
			"OpenAPI version should be 3.1.0"
		);

		// Verify info structure
		assert!(parsed["info"].is_object(), "Info should be an object");
		assert_eq!(
			parsed["info"]["title"].as_str(),
			Some("Test API"),
			"Info title should be 'Test API'"
		);
		assert_eq!(
			parsed["info"]["version"].as_str(),
			Some("1.0.0"),
			"Info version should be '1.0.0'"
		);

		// Verify paths structure
		assert!(parsed["paths"].is_object(), "Paths should be an object");
		assert!(
			parsed["paths"]["/users"].is_object(),
			"Path '/users' should be an object"
		);

		// Verify tags structure
		assert!(parsed["tags"].is_array(), "Tags should be an array");
		let tags = parsed["tags"].as_array().expect("Tags should be an array");
		assert_eq!(tags.len(), 1, "Should have exactly 1 tag");
		assert_eq!(
			tags[0]["name"].as_str(),
			Some("users"),
			"Tag name should be 'users'"
		);
		assert_eq!(
			tags[0]["description"].as_str(),
			Some("User operations"),
			"Tag description should be 'User operations'"
		);
	}

	#[test]
	fn test_schema_with_components() {
		// Create components with schemas
		let mut components = ComponentsBuilder::new();
		components = components.schema("User", Schema::object());
		components = components.schema("Post", Schema::object());

		let mut api_schema = OpenApiBuilder::new()
			.info(InfoBuilder::new().title("API").version("1.0.0").build())
			.components(Some(components.build()))
			.build();

		api_schema.add_path("/users".to_string(), PathItemBuilder::new().build());

		// Serialize and validate JSON structure
		let json = serde_json::to_string_pretty(&api_schema)
			.expect("Failed to serialize API schema with components");
		let parsed: serde_json::Value =
			serde_json::from_str(&json).expect("Failed to parse API schema JSON");

		// Verify components/schemas structure
		assert!(
			parsed["components"].is_object(),
			"Components should be an object"
		);
		assert!(
			parsed["components"]["schemas"].is_object(),
			"Components.schemas should be an object"
		);

		let schemas = &parsed["components"]["schemas"];
		assert!(
			schemas["User"].is_object(),
			"User schema should be an object"
		);
		assert_eq!(
			schemas["User"]["type"].as_str(),
			Some("object"),
			"User schema type should be 'object'"
		);
		assert!(
			schemas["Post"].is_object(),
			"Post schema should be an object"
		);
		assert_eq!(
			schemas["Post"]["type"].as_str(),
			Some("object"),
			"Post schema type should be 'object'"
		);

		// Verify paths exist
		assert!(parsed["paths"].is_object(), "Paths should be an object");
		assert!(
			parsed["paths"]["/users"].is_object(),
			"Path '/users' should be an object"
		);
	}

	#[test]
	fn test_parameter_json_structure() {
		let param = Parameter::new_simple("id", ParameterIn::Path, Schema::integer(), true);

		let json = serde_json::to_string_pretty(&param).expect("Failed to serialize Parameter");
		let parsed: serde_json::Value =
			serde_json::from_str(&json).expect("Failed to parse Parameter JSON");

		// Verify parameter structure
		assert_eq!(
			parsed["name"].as_str(),
			Some("id"),
			"Parameter name should be 'id'"
		);
		assert_eq!(
			parsed["in"].as_str(),
			Some("path"),
			"Parameter location should be 'path'"
		);
		assert_eq!(
			parsed["required"],
			serde_json::Value::Bool(true),
			"Parameter should be required"
		);

		// Verify schema
		assert!(
			parsed["schema"].is_object(),
			"Parameter schema should be an object"
		);
		assert_eq!(
			parsed["schema"]["type"].as_str(),
			Some("integer"),
			"Parameter schema type should be 'integer'"
		);
	}

	#[test]
	fn test_operation_json_structure() {
		let mut operation = <Operation as OperationExt>::create();

		// Add parameter
		let param = Parameter::new_simple("id", ParameterIn::Path, Schema::integer(), true);
		operation.add_parameter(param);

		// Add response
		let response = ResponseBuilder::new().description("Success").build();
		operation.add_response("200", response);

		let json = serde_json::to_string_pretty(&operation).expect("Failed to serialize Operation");
		let parsed: serde_json::Value =
			serde_json::from_str(&json).expect("Failed to parse Operation JSON");

		// Verify parameters
		assert!(
			parsed["parameters"].is_array(),
			"Operation parameters should be an array"
		);
		let params = parsed["parameters"]
			.as_array()
			.expect("Parameters should be an array");
		assert_eq!(params.len(), 1, "Should have exactly 1 parameter");
		assert_eq!(
			params[0]["name"].as_str(),
			Some("id"),
			"Parameter name should be 'id'"
		);
		assert_eq!(
			params[0]["in"].as_str(),
			Some("path"),
			"Parameter location should be 'path'"
		);
		assert_eq!(
			params[0]["required"],
			serde_json::Value::Bool(true),
			"Parameter should be required"
		);
		assert!(
			params[0]["schema"].is_object(),
			"Parameter schema should be an object"
		);
		assert_eq!(
			params[0]["schema"]["type"].as_str(),
			Some("integer"),
			"Parameter schema type should be 'integer'"
		);

		// Verify responses
		assert!(
			parsed["responses"].is_object(),
			"Operation responses should be an object"
		);
		assert!(
			parsed["responses"]["200"].is_object(),
			"Response '200' should be an object"
		);
		assert_eq!(
			parsed["responses"]["200"]["description"].as_str(),
			Some("Success"),
			"Response description should be 'Success'"
		);
	}
}