RicoSuter / NSwag

The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
http://NSwag.org
MIT License
6.78k stars 1.29k forks source link

No way to extend OpenApiSchemaGenerator in v14 #4644

Closed SamuelBerger closed 10 months ago

SamuelBerger commented 10 months ago

I could not find a way in v14 to configure a custom OpenApiSchemaGenerator like it was possible in v13:

    services.AddOpenApiDocument(document => {
        document.SchemaGenerator = new MyOpenApiSchemaGenerator(document);

In v14 the OpenApiSchemaGenerator gets created inside the constructor of OpenApiDocumentGenerator:

    /// <summary>Provides services to for Swagger generators like the creation of parameters and handling of schemas.</summary>
    public class OpenApiDocumentGenerator
    {
        private readonly JsonSchemaResolver _schemaResolver;
        private readonly OpenApiDocumentGeneratorSettings _settings;

        /// <summary>Initializes a new instance of the <see cref="OpenApiDocumentGenerator"/> class.</summary>
        /// <param name="settings">The settings.</param>
        /// <param name="schemaResolver">The schema resolver.</param>
        public OpenApiDocumentGenerator(OpenApiDocumentGeneratorSettings settings, JsonSchemaResolver schemaResolver)
        {
            SchemaGenerator = new OpenApiSchemaGenerator(settings);
            ...

Would you consider bringing that capability back in? Or would a PR be welcome?