Swashbuckle.AspNetCore
Swashbuckle.AspNetCore copied to clipboard
AdditionalProperties has AdditionalPropertiesAllowed=false
When JsonDictionaryHandler sets the OpenApiSchema.AdditionalProperties, that OpenApiSchema will have AdditionalPropertiesAllowed == false. This in turns will add "additionalProperties": false to every AdditionalProperties-entry in the generated swagger.
Probably not a big issue, but I think it is unnecessary.
Actually it is a big issue. (for me at least)
Microsofts autorest tool does not accept a boolean value for additionalProperties and crashes. Of course it should just accept these values because the spec dictates that it can be either a boolean or a schema, but if there are no additional properties the field should just be omitted.
As a workaround i implemented a DocumentFilter:
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
namespace XXX.Middleware {
public class AdditionalParametersDocumentFilter : IDocumentFilter {
public void Apply(OpenApiDocument openApiDoc, DocumentFilterContext context) {
foreach(var schema in context.SchemaRepository.Schemas) {
if(schema.Value.AdditionalProperties == null) {
schema.Value.AdditionalPropertiesAllowed = true;
}
}
}
}
}
Oddly setting the AdditionalPropertiesAllowed removes the AdditionalProperties
and in the startup:
services.AddSwaggerGen(options => {
...
options.DocumentFilter<AdditionalParametersDocumentFilter>();
...
});
Also mentioned in: https://github.com/OAI/OpenAPI-Specification/issues/668#issuecomment-281837896
This happens to me as well. I can't use Swashbuckle until it is fixed.
More context: https://github.com/Azure/autorest/issues/3497
@richardscholten73 your workaround didn't work for me unfortunately. I still get those properties. I don't get how it's different from your setup somehow. Could there be something else involved?
@richardscholten73 your workaround didn't work for me unfortunately. I still get those properties. I don't get how it's different from your setup somehow. Could there be something else involved?
Not that i know of. It's been awhile since i worked on that project. Maybe the workaround does not work anymore on newer versions? My project is on 5.5.1
@ffMathy the workaround works for me in latest Swashbuckle version 6.1.4. Make sure you register AdditionalParametersDocumentFilter
after all other filters, so it can update all schemas properly 😉
Worked like a charm, thank you! As the additionalProperties
are set to true by default (at least in Azure API Management), the generated Swagger document just omits the whole property using your filter.
This issue is stale because it has been open for 60 days with no activity. It will be automatically closed in 14 days if no further updates are made.
This issue was closed because it has been inactive for 14 days since being marked as stale.