CarterCommunity / Carter

Carter is framework that is a thin layer of extension methods and functionality over ASP.NET Core allowing code to be more explicit and most importantly more enjoyable.
MIT License
2.08k stars 175 forks source link

Adds support for user-supplied openapi examples #169

Closed rcknight closed 4 years ago

rcknight commented 5 years ago

(As discussed in slack)

Users can supply an example instance on RouteMetaData and RouteMetaDataResponse. If supplied, the values on these objects will be used to populate examples in the OpenApi schemas. If no example objects are supplied, then this PR still improves example output, displaying correctly typed values rather than deciding everything is a string, and correctly handling nested object structures rather than only including top-level properties in examples.

rcknight commented 5 years ago

The build will be failing because I didn't yet update the expected test output. Even in this default case where no example instance is supplied, the example object has improved to use the correct types:

new:

"example": {
    "name": "Example",
    "id": 0,
    "age": 0
}

old:

"example": {
    "name": "",
    "id": "",
    "age": ""
}
jchannon commented 4 years ago

Recent OpenAPI changes from @williamhbell don't create the "Example" json objects as swagerui does it for you