kynos-openapi 0.1.0

OpenAPI 3.1 and 3.2 document model, serialization and validation.
Documentation
use crate::model::{
    body::{RequestBody, media_type::MediaType, mime_names},
    schema::{Schema, types::SchemaType},
};

#[test]
fn a_json_body_is_required_by_default() {
    let body = RequestBody::json(Schema::of_type(SchemaType::Object));
    assert_eq!(body.required, Some(true));
    assert!(body.content.contains_key(mime_names::APPLICATION_JSON));
}

#[test]
fn a_body_can_offer_several_representations() {
    let body = RequestBody::json(Schema::of_type(SchemaType::Object)).with_media_type(
        mime_names::APPLICATION_FORM_URLENCODED,
        MediaType::new(Schema::of_type(SchemaType::Object)),
    );
    assert_eq!(body.content.len(), 2);
}

#[test]
fn optional_bodies_say_so() {
    let body = RequestBody::json(Schema::any()).optional();
    assert_eq!(body.required, Some(false));
}

#[test]
fn an_encoding_declaring_a_style_no_query_parameter_could_take_is_refused() {
    use crate::model::body::encoding::Encoding;

    // An encoded property is serialized the way a query parameter is, so the
    // path, header and cookie styles are not a combination to report but words
    // `EncodingStyle` cannot read.
    for style in ["matrix", "label", "simple", "cookie"] {
        let json = format!(r#"{{"style":"{style}"}}"#);
        serde_json::from_str::<Encoding>(&json)
            .expect_err("an encoding takes only the query styles");
    }
}