I am getting Structural error "should NOT have additional properties" error due to $ref
element present in type: array
.
In https://editor.swagger.io when replace $ref: '#/definitions/EnumExample1'
with type: array
. I do not see the error. But I am not sure how to fix this in swagger-gen code.
If more information is required to understand this issue, please post in comments!
Swagger snippet
parameters:
- in: query
name: parameterNameX
description: parameterNameX
type: string
- in: query
name: name
type: string
- in: query
name: include
description: Comma-separated list of properties to include in the response
type: array
items:
$ref: '#/definitions/EnumExample1'
Errors
Structural error at paths./v1/workflows.get.parameters.2.items
should NOT have additional properties
additionalProperty: $ref
Jump to line 30
Startup.cs
services
.AddMvc(options =>
{
options.EnableEndpointRouting = false;
options.Conventions.Add(new CsvQueryStringConvention());
})
.AddNewtonsoftJson(options =>
{
options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
options.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
//ensure enums passed to client are strings
options.SerializerSettings.Converters.Add(new StringEnumConverter { NamingStrategy = new CamelCaseNamingStrategy()});
})
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("",
new OpenApiInfo()
{
Title = "Service",
Version = "v1"
});
app.UseSwagger(c =>
{
c.RouteTemplate = "app/swagger/{documentName}/swagger.json";
c.PreSerializeFilters.Add((openApiDocument, httpReq) =>
{
openApiDocument.Servers = new List<OpenApiServer>
{
new OpenApiServer { Url = $"https://{httpReq.Host.Value}" }
#if DEBUG
, new OpenApiServer { Url = $"http://{httpReq.Host.Value}" }
#endif
};
});
c.SerializeAsV2 = true;
});
Model
public EnumExample1[] Example { get; set; }
From Swagger Example will be passed as comma-separated string. Since c.SerializeAsV2 = true; I am not sure why generated Swagger.json have $ref element which is OpenApi3 standard.
items
. You need to define that enum inline. – HelenEnumExample1
model and theinclude
parameter, and also your Swashbuckle/Swagger-Net configuration. – Helen