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
Most helpful comment
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:
Oddly setting the AdditionalPropertiesAllowed removes the AdditionalProperties
and in the startup:
Also mentioned in:
https://github.com/OAI/OpenAPI-Specification/issues/668#issuecomment-281837896