MCPcopy Create free account
hub / github.com/baerwang/openapi-rs / parse_field_of_example

Function parse_field_of_example

tests/tests.rs:409–487  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

407
408 #[test]
409 fn parse_field_of_example() -> Result<(), Box<dyn std::error::Error>> {
410 let content = r#"
411openapi: 3.1.0
412info:
413 title: Example API
414 description: API definitions for example
415 version: '0.0.1'
416
417components:
418 schemas:
419 ExampleResponse:
420 type: object
421 properties:
422 uuid:
423 type: string
424 description: The UUID for this example.
425 format: uuid
426 example: 00000000-0000-0000-0000-000000000000
427 multi_uuid:
428 type: array
429 description: The Multi UUID for this example.
430 format: uuid
431 example:
432 - 00000000-0000-0000-0000-000000000000
433 - 00000000-0000-0000-0000-000000000001
434 - 00000000-0000-0000-0000-000000000002
435paths:
436 "#;
437
438 let openapi: OpenAPI = OpenAPI::yaml(content)?;
439
440 // Validate general properties
441 assert_eq!(openapi.openapi, "3.1.0");
442 assert_eq!(openapi.info.title, "Example API");
443 assert_eq!(
444 openapi.info.description.as_deref(),
445 Some("API definitions for example")
446 );
447 assert_eq!(openapi.info.version, "0.0.1");
448
449 // Validate components and schemas
450 let components = openapi.components.as_ref().unwrap();
451 let example_response = components.schemas.get("ExampleResponse").unwrap();
452 let properties = example_response.properties.as_ref().unwrap();
453
454 // Validate uuid property
455 let uuid = properties.get("uuid").unwrap();
456 assert_eq!(uuid.r#type, Some(TypeOrUnion::Single(Type::String)));
457 assert_eq!(
458 uuid.description.as_deref(),
459 Some("The UUID for this example.")
460 );
461 assert_eq!(uuid.format, Some(Format::UUID));
462 assert_eq!(
463 uuid.example.clone().unwrap(),
464 "00000000-0000-0000-0000-000000000000"
465 );
466

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected