yahehe / Nancy.Swagger

Nancy plugin for generated API documentation in Swagger format.
MIT License
133 stars 60 forks source link

ModelData Examples #173

Closed MacroPower closed 3 years ago

MacroPower commented 5 years ago

Hello,

I had the same question as this stackoverflow user.

This seems to be supported by swagger: https://swagger.io/docs/specification/2-0/adding-examples/

I would expect then to be able to write something like this:

return SwaggerModelData.ForType<Type>(with =>
{
    with.Property(x => x.Name)
        .Description("Name of the user")
        .Example("James Johnson")
});

Thus clicking "Try it out" for a MetaDataModule with a BodyParameter that has .Schema<Type> would give me the example json:

{
  "name": "James Johnson"
}

Rather than

{
  "name": "string"
}

A fairly trivial example, but it would be nice for large bodies with a lot of information (some of which may need to conform to some standards).

MacroPower commented 3 years ago

Believe I've found a way to do this, at least partially. See my answer here: https://stackoverflow.com/a/58634621