I'm having trouble with the model names. When an action returns some sort of collection of a certain type, Swagger UI displays the model as Inline Model [ ... ] for the collection, which is fine because the collection doesn't have a name, but instead of the type name of the element, the inner type will be displayed as Inline Model 1.
To reproduce look at the Search action of the CrudActionsController of the _Basic_ sample.
The model in Swagger UI looks like
Inline Model [
Inline Model 1
]
Inline Model 1 {
id (integer, optional): Uniquely identifies the product,
description (string, optional): Describes the product,
status (integer, optional) = ['0', '1', '2']
}
but should probably look like
Inline Model [
Product
]
Product {
id (integer, optional): Uniquely identifies the product,
description (string, optional): Describes the product,
status (integer, optional) = ['0', '1', '2']
}
Additionally the sample when modified to create application/xml will create an example value of
<?xml version="1.0"?>
<Inline Model>
<id>1</id>
<description>string</description>
<status>0</status>
</Inline Model>
instead of
<?xml version="1.0"?>
<Inline Model>
<Product>
<id>1</id>
<description>string</description>
<status>0</status>
</Product>
</Inline Model>
I've tried to add a CollectionDataContract (using AddXmlDataContractSerializerFormatters to set up XML Serialization), but that didn't work.
Not sure where this goes wrong and how it should be rectified?
I think that the issue is related to the fact that the Schema.Title is not set. If I add
schema.Title = GetSchemaIdFor(type);
into SchemaRegistry.CreateInlineSchema after the schema is instantiated I do get
IEnumerable[Product] [
Product
]
Product {
id (integer, optional): Uniquely identifies the product,
description (string, optional): Describes the product,
status (integer, optional) = ['0', '1', '2']
}
for the model and
<?xml version="1.0"?>
<IEnumerable[Product]>
<id>1</id>
<description>string</description>
<status>0</status>
</IEnumerable[Product]>
for the xml example.
Better, I think, but not there yet.
Given that the generated Swagger is correct, I think this is really a swagger-ui issue. In fact, it appears to be a known bug that was introduced in a more recent version:
https://github.com/swagger-api/swagger-ui/issues/2325
I'll keep this issue open to track it so that I update the swagger-ui version that's embedded in SB when a fix is available.
Any update on when this will be fixed? I am also running into the same problem.
Same issue. Just posting here to be notified of a fix
For anyone else out there using Web API 2 and XML documentation file I found a way for this to work :
Instead of decorating your methods in your controller this way (List
[SwaggerResponse(HttpStatusCode.OK, Type = typeof(List
Try (Just the type T itself):
[SwaggerResponse(HttpStatusCode.OK, Type = typeof(T))]
There is really no need to tell Swagger the response is a collection of type "T". It works just fine without knowing the response is a collection of objects.
This fixed the "Inline Model" stuff for me.
This seems to be related to #349, as this issue is fixed in the latest swagger-ui 3.x release.
An update of swagger-ui to 3.x should fix the problem within AspNetCore.SwaggerUI too.
Fixed as of release 2.0.0, which includes swagger-ui 3.x.
Do you solve this problem? and how ? thank you~
I use the version 2.7.0 , ant the same problem
I'm using Swashbuckle.Core 5.6.0 and experience the same problem. It shows "Inline Model 1" for every method that returns an IEnumerable<Foo> instead of IEnumerable[Foo].
(More specifically, I'm using Task<IEnumerable<Foo>> but it also / just as well fails on IEnumerable<Foo>)
@RobThree I am facing the same issue with the same version of Swashbuckle 5.6.0.
Did you or anyone solve this Inline Model [ Inline Model 1 ] problem?
+1
https://stackoverflow.com/questions/39572999/asp-net-swagger-ienumerablet/53405945#53405945
the second answer in the above link solved this problem for me.
GlobalConfiguration.Configuration.EnableSwagger
(c =>{
c.SchemaFilter
}
class AnyClassName: ISchemaFilter{
public void Apply(Schema schema, SchemaRegistry schemaRegistry, Type type)
{
schema.title = type.Name;
}
}
at least it can show the model name.
Most helpful comment
Any update on when this will be fixed? I am also running into the same problem.