services.AddSwaggerGen(c =>
{
c.SchemaFilter<RequireNonNullablePropertiesSchemaFilter>();
c.SupportNonNullableReferenceTypes();
c.CustomOperationIds(e => $"{e.ActionDescriptor.RouteValues["action"]}");
// // Set the comments path for the Swagger JSON and UI.
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
c.IncludeXmlComments(xmlPath);
});
Schema Filter:
public class RequireNonNullablePropertiesSchemaFilter : ISchemaFilter
{
/// <summary>
/// Add to model.Required all properties where Nullable is false.
/// </summary>
public void Apply(OpenApiSchema model, SchemaFilterContext context)
{
IEnumerable<string> additionalRequiredProps = model.Properties
.Where(x => !x.Value.Nullable && !model.Required.Contains(x.Key))
.Select(x => x.Key);
foreach (string propKey in additionalRequiredProps)
{
model.Required.Add(propKey);
}
}
}
When I run npm run api, which cleans and runs codegen, it's shortening the service names and populating the view models with "_" in the names.
Example of the issue:
My Current fix for this is running it back to 0.13.3 which seems to fix the issue. Seen here:
Please let me know if there is anything else I can do to help!
Package.json:
Codegen.ts:
Startup Swagger Generation:
Schema Filter:
Swashbuckle.AspNetCore.Swagger Version: 6.4.0 Swashbuckle.AspNetCore.SwaggerGen Version: 6.4.0 Swashbuckle.AspNetCore.SwaggerUI Version: 6.4.0