Forum Discussion
ok, one of my problems solved at least! Not many examples out there and documentation is a bit vague, but if I add all of my schemas to the OpenApiDocument.Components.Schema and then reference them as follows when actually using them it seems to work.
The missing piece was that I needed to make a "new JsonSchema().Reference = XXXXX", which is my reference to the previously added type!
var returnType = Type.GetType(item.ReturnType);
var temp = new NSwag.OpenApiResponse();
var schema = ObjectTools.GetSchemaFromType(returnType);
if (resolver.Schemas.FirstOrDefault(x => x.Title == schema.Title) == null)
{
resolver.AddSchema(returnType, false, schema);
}
temp.Content.Add(
"application/json",
new NSwag.OpenApiMediaType
{
Schema = new NJsonSchema.JsonSchema()
{
Reference = resolver.GetSchema(returnType, false)
},
Example = new NSwag.OpenApiExample()
{
Value = Activator.CreateInstance(returnType)
}
});
newOp.Responses.Add("200", temp);
However how my problem is that when I add my original object to the OpenApiDocument.Components.Schema, I cannot figure out how to make it remove the "definitions" section(which the tool complains about) and how to force the reference to be "#components/schemas/<SOMEOBJECT> instead of it being nested
Related Content
- 2 years ago
Recent Discussions
- 2 days ago
- 3 days ago
- 20 days ago