Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for unit structs #392

Merged
merged 1 commit into from
Dec 6, 2022
Merged

Conversation

juhaku
Copy link
Owner

@juhaku juhaku commented Dec 6, 2022

This PR will add support for unit type structs to be declared with #[derive(ToSchema)]. Previously only struct either with named fiels or unnamed fields and enums where supported.

According serde serialization unit type struct will be serialized as null but the support for utoipa ToSchema was lacking in this aspect.

Add suport for the definition:

#[derive(ToSchema)]
struct UnitValue;

// .... results following specification:

utoipa::openapi::schema::ObjectBuilder::new()
    .nullable(true)
    .default(Some(serde_json::Value::Null))
    .example(Some(serde_json::Value::Null))

Above definition will get serialized as null.

Resolves #332

@juhaku juhaku marked this pull request as ready for review December 6, 2022 18:59
@juhaku juhaku changed the title Add support for unit sructs Add support for unit structs Dec 6, 2022
This PR will add support for unit type structs to be declared with
`#[derive(ToSchema)]`. Previously only struct either with named fiels or
unnamed fields and enums where supported.

According serde serialization unit type struct will be serialized as
`null` but the support for utoipa `ToSchema` was lacking in this aspect.

Add suport for the definition:
```rust
struct UnitValue;

// .... results following specification:

utoipa::openapi::schema::ObjectBuilder::new()
    .nullable(true)
    .default(Some(serde_json::json!(null)))
    .example(Some(serde_json::json!(null)))
```
Above definition will get serialized as `null`.
@juhaku juhaku force-pushed the feature-support-unit-structs branch from 017a31c to 3d2613d Compare December 6, 2022 19:09
@juhaku juhaku merged commit a4b1af0 into master Dec 6, 2022
@juhaku juhaku deleted the feature-support-unit-structs branch December 6, 2022 19:15
@biwecka biwecka mentioned this pull request Jan 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Released
Development

Successfully merging this pull request may close these issues.

Derive ToSchema on Unit Structs
1 participant