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 schema_with custon fn reference #390

Merged
merged 3 commits into from
Dec 6, 2022

Conversation

juhaku
Copy link
Owner

@juhaku juhaku commented Dec 6, 2022

Add support for schema_with custom fn reference that can be used alternatively via builders to alter the compile time schema if schema attributes are not enough nor does not fit to the purpose.

Implement schema_with for ToSchema and IntoParmas named struct fields.

Supported syntax:

fn custom_type() -> Object {
    ObjectBuilder::new()
        .schema_type(utoipa::openapi::SchemaType::String)
        .format(Some(utoipa::openapi::SchemaFormat::Custom(
            "email".to_string(),
        )))
        .description(Some("this is email"))
        .build()
}

#[derive(ToSchema)]
struct Value {
    #[schema(with_schema = custom_type)]
    email: String,
}

#[derive(IntoParams)]
struct Query {
    #[param(with_schema = custom_type)]
    email: String,
}

Resolves #195

Add support for `schema_with` custom fn reference that can be used
alternatively via builders to alter the compile time schema if schema
attributes are not enough nor does not fit to the purpose.

Implement `schema_with` for `ToSchema` and `IntoParams` named struct
fields.

Supported syntax:
```rust
fn custom_type() -> Object {
    ObjectBuilder::new()
        .schema_type(utoipa::openapi::SchemaType::String)
        .format(Some(utoipa::openapi::SchemaFormat::Custom(
            "email".to_string(),
        )))
        .description(Some("this is email"))
        .build()
}

struct Value {
    #[schema(with_schema = custom_type)]
    email: String,
}

struct Value {
    #[param(with_schema = custom_type)]
    email: String,
}
```
@juhaku juhaku marked this pull request as ready for review December 6, 2022 15:42
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.

Component derive attribute manual implementation
1 participant