kurtbuilds/oasgen

Possible to support required properties?

Closed this issue · 2 comments

Hey thanks for creating this. Is it possible to support required properties?

I'm using the schema to generate TypesScript types (https://github.com/fabien0102/openapi-codegen) and it's much nicer if the fields are marked as required.

Thanks for this. It's a bug, but technically a breaking change, so it's released as 0.8.0.

Let me know if you encounter issues with it.

// oasgen/tests/test-none/02-required.rs
use oasgen::{OaSchema};
use serde::{Deserialize, Serialize};

#[derive(OaSchema, Serialize, Deserialize)]
pub struct Foo {
    is_required: String,
    is_nullable: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    is_not_required: Option<String>,
    #[serde(skip)]
    is_not_on_schema: String,
    #[openapi(skip)]
    is_also_not_on_schema: String,
}

fn main() {
    use pretty_assertions::assert_eq;
    let schema = Foo::schema().unwrap();
    let spec = serde_yaml::to_string(&schema).unwrap();
    assert_eq!(spec.trim(), include_str!("02-required.yaml"));
}

Works great, thanks for the quick response!