Possible to support required properties?
Closed this issue · 2 comments
twe4ked commented
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.
kurtbuilds commented
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"));
}
twe4ked commented
Works great, thanks for the quick response!