Open GeoJim1218 opened 4 years ago
I have made changes based on the sample project https://github.com/RicoSuter/NSwag/tree/master/samples/NSwag.Sample.NetOwinMiddleware the package versions are:
<package id="NJsonSchema" version="10.1.12" targetFramework="net472" /> <package id="NSwag.AspNet.Owin" version="13.4.2" targetFramework="net472" /> <package id="NSwag.Core" version="13.4.2" targetFramework="net472" /> <package id="NSwag.Generation" version="13.4.2" targetFramework="net472" /> <package id="NSwag.Generation.WebApi" version="13.4.2" targetFramework="net472" /> <package id="NSwag.SwaggerGeneration" version="12.3.0" targetFramework="net472" /> <package id="NSwag.SwaggerGeneration.WebApi" version="12.3.0" targetFramework="net472" /> <package id="Owin" version="1.0" targetFramework="net472" /> <package id="System.Buffers" version="4.4.0" targetFramework="net472" /> <package id="System.Xml.XPath" version="4.3.0" targetFramework="net472" />
I try to add example to model Product like https://github.com/RicoSuter/NJsonSchema/wiki/XML-Documentation#define-examples does. here is the codes.
/// <summary> /// product /// </summary> /// <example> ///{ /// "id":5, /// "name":"abc", /// "category":"food", /// "price":10.0 ///} /// </example> public class Product { public int Id { get; set; } public string Name { get; set; } public string Category { get; set; } public decimal Price { get; set; } }
app.UseSwaggerUi3(typeof(Startup).Assembly, settings => { // configure settings here // settings.GeneratorSettings.*: Generator settings and extension points // settings.*: Routing and UI settings settings.GeneratorSettings.DefaultUrlTemplate = "api/{controller}/{id?}"; settings.GeneratorSettings.GenerateExamples = true; settings.GeneratorSettings.AllowNullableBodyParameters = false; });
However, I could not see the example in the swagger.json.
"Product": { "type": "object", "required": [ "Id", "Price" ], "properties": { "Id": { "type": "integer", "format": "int32" }, "Name": { "type": "string" }, "Category": { "type": "string" }, "Price": { "type": "number", "format": "decimal" } } }
I have no idea what I'm missing. I have searched a lot of discussion about the missing examples. But it seems I have everything to make it work but it doesn't. Please help to look at this question, I appreciate it.
The xml file is outputted alongside the .dll?
I have made changes based on the sample project https://github.com/RicoSuter/NSwag/tree/master/samples/NSwag.Sample.NetOwinMiddleware the package versions are:
I try to add example to model Product like https://github.com/RicoSuter/NJsonSchema/wiki/XML-Documentation#define-examples does. here is the codes.
However, I could not see the example in the swagger.json.
I have no idea what I'm missing. I have searched a lot of discussion about the missing examples. But it seems I have everything to make it work but it doesn't. Please help to look at this question, I appreciate it.