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

Annotation for example values #31

Closed
ralpha opened this issue May 18, 2020 · 1 comment
Closed

Annotation for example values #31

ralpha opened this issue May 18, 2020 · 1 comment

Comments

@ralpha
Copy link
Contributor

ralpha commented May 18, 2020

Adding support for examples.

Currently strings will have an example of:

[
  {
    "list_of_int": [
      0
    ],
    "id": 0,
    "name": "string",
    "full_name": "string"
  }
],

Where strings are always "string" and int is always 0
If we add examples we can give some more info.

Maybe with a syntax like:

#[schemars(example = "This is the example string")]

Used like this:

#[derive(Serialize, Deserialize, JsonSchema)]
pub struct Version {
    #[schemars(example = "1.0.0")]
    pub code: String,
    #[schemars(example = "First release of our crate/application.")]
    pub description: String,
}

This will result in something like:

{
  "code": "1.0.0",
  "description": "First release of our crate/application."
}

I don't know how this can also be done for int, but I think that is less of an issue.
For enums the first value is converted to string and that is used. So that does not have to change I think.

This issue is a repost of: GREsau/okapi#11

@GREsau
Copy link
Owner

GREsau commented Jun 11, 2020

Duplicate of #23 which was implemented in schemars v0.7.6

@GREsau GREsau closed this as completed Jun 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants