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

[OpenAPI] Support using Default trait when derive Object #369

Closed
duskmoon314 opened this issue Aug 16, 2022 · 3 comments
Closed

[OpenAPI] Support using Default trait when derive Object #369

duskmoon314 opened this issue Aug 16, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@duskmoon314
Copy link

Description of the feature

Currently, only the fields of Object has the default parameter. And it can only be used for some types that already implement Default, or have a function to generate the default value.

It might be more convenient if we could define Default for structs and use it.

Notice: I don't know if this is possible. Have taken a simple look at the macro of Object, it takes fields' attributes one by one and generates codes.

Code example (if possible)

Suppose rust codes like this:

#[derive(Object)]
#[oai(default)]
struct MyObj {
  str: String,
  int: isize
}

impl Default for MyObj {
  fn default() -> Self {
    Self {
      str: "some_string".to_string(),
      int: 32,
    }
  }
}
@duskmoon314 duskmoon314 added the enhancement New feature or request label Aug 16, 2022
@duskmoon314 duskmoon314 changed the title [OpenAPI] Support using Default traid when derive Object [OpenAPI] Support using Default trait when derive Object Aug 16, 2022
@sunli829
Copy link
Collaborator

Absolutely, I'll add it later.

@sunli829
Copy link
Collaborator

Released in v2.0.10

#[oai(default)]

@duskmoon314
Copy link
Author

Amazing! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants