title: .NET 5 - SWAGGER.json
body: <p>I've generated a swagger.json file for my public apis. It works really nice with the following code:</p>
  <p><strong>In Startup - Configure Services</strong></p>
  <pre><code>            //Register Swagger Options as Dependency Injection
          services.AddTransient&lt;IConfigureOptions&lt;SwaggerGenOptions&gt;, ConfigureSwaggerOptions&gt;();
          
          services.AddSwaggerGen(options =&gt;
          {
              // add a custom operation filter which sets default values
              //options.OperationFilter&lt;SwaggerDefaultValues&gt;();
  
              var xmlFile = $&quot;{Assembly.GetExecutingAssembly().GetName().Name}.xml&quot;;
              var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
              options.IncludeXmlComments(xmlPath);
  
          });
  </code></pre>
  <p><strong>In Startup - Configure</strong></p>
  <pre><code>app.UseSwagger();
          app.UseSwaggerUI(c =&gt;
          {
              c.InjectStylesheet(&quot;../css/customize-swagger-ui.css&quot;);
              c.InjectJavascript(&quot;../js/customize-swagger-ui.js&quot;);
              // build a swagger endpoint for each discovered API version
              foreach (var description in provider.ApiVersionDescriptions)
              {
                  c.SwaggerEndpoint($&quot;/swagger/{description.GroupName}/swagger.json&quot;, description.GroupName.ToUpperInvariant());
  
              }
  
          });
  </code></pre>
  <p>My problem is, that i would like to add the name of the method behind the API-Request. Otherwise a tool like NSWAG for Client-Code-Generation creates a lot of different methods which are called APIRoute1, APIRoute2, APIRoute3, ...</p>
  <p>Here is a json-snippet of the swagger generated file:</p>
  <pre><code>&quot;paths&quot;: {
  &quot;/api/v1/Order&quot;: {
    &quot;post&quot;: {
      &quot;tags&quot;: [
        &quot;Order&quot;
      ],
      &quot;summary&quot;: &quot;Creates a new Order if no order currently exists&quot;,
      &quot;requestBody&quot;: {
        &quot;description&quot;: &quot;&quot;,
        &quot;content&quot;: {
          &quot;application/json&quot;: {
            &quot;schema&quot;: {
              &quot;$ref&quot;: &quot;#/components/schemas/CreateOrderModel&quot;
            }
          },
          &quot;text/json&quot;: {
            &quot;schema&quot;: {
              &quot;$ref&quot;: &quot;#/components/schemas/CreateOrderModel&quot;
            }
          },
          &quot;application/*+json&quot;: {
            &quot;schema&quot;: {
              &quot;$ref&quot;: &quot;#/components/schemas/CreateOrderModel&quot;
            }
          }
        }
      },
      &quot;responses&quot;: {
        &quot;200&quot;: {
          &quot;description&quot;: &quot;Success&quot;
        }
      }
    }
  },
  &quot;/api/v1/Order/{orderNumber}&quot;: {
    &quot;get&quot;: {
      &quot;tags&quot;: [
        &quot;Order&quot;
      ],
      &quot;summary&quot;: &quot;Reads a given Order if exists&quot;,
      &quot;parameters&quot;: [
        {
          &quot;name&quot;: &quot;orderNumber&quot;,
          &quot;in&quot;: &quot;path&quot;,
          &quot;description&quot;: &quot;Order Number&quot;,
          &quot;required&quot;: true,
          &quot;schema&quot;: {
            &quot;type&quot;: &quot;integer&quot;,
            &quot;format&quot;: &quot;int32&quot;
          }
        }
      ],
      &quot;responses&quot;: {
        &quot;200&quot;: {
          &quot;description&quot;: &quot;Success&quot;,
          &quot;content&quot;: {
            &quot;application/json&quot;: {
              &quot;schema&quot;: {
                &quot;$ref&quot;: &quot;#/components/schemas/OrderDTO&quot;
              }
            }
          }
        },
        &quot;400&quot;: {
          &quot;description&quot;: &quot;Bad Request&quot;,
          &quot;content&quot;: {
            &quot;application/json&quot;: {
              &quot;schema&quot;: {
                &quot;type&quot;: &quot;string&quot;
              }
            }
          }
        },
        &quot;404&quot;: {
          &quot;description&quot;: &quot;Not Found&quot;,
          &quot;content&quot;: {
            &quot;application/json&quot;: {
              &quot;schema&quot;: {
                &quot;type&quot;: &quot;string&quot;
              }
            }
          }
        }
      }
    }
  }
  </code></pre>
  <p>APIRoute is only a placeholder as an example. The methods behinde APIRouteX are implemented with the same route but the http variable is different like (POST, DELETE, PUT). So its really hard to read the client-code generated code.</p>
  <p>Is it possible to add the &quot;Method-Name&quot; behind the route to the swagger.json file?</p>
  <p><strong>SWAGGER Configure Options</strong></p>
  <pre><code>    /// &lt;summary&gt;
  /// Configures the Swagger Options like Titel, Contact Informations etc
  /// &lt;/summary&gt;
  public class ConfigureSwaggerOptions : IConfigureOptions&lt;SwaggerGenOptions&gt;
  {
      readonly IApiVersionDescriptionProvider provider;
  
      /// &lt;summary&gt;
      /// Constructor which adds ApiVersionDescription by Dependency Injection
      /// &lt;/summary&gt;
      /// &lt;param name=&quot;provider&quot;&gt;API Version Description Provider&lt;/param&gt;
      public ConfigureSwaggerOptions(IApiVersionDescriptionProvider provider) =&gt; this.provider = provider;
  
      /// &lt;summary&gt;
      /// Adds a seperate Swagger Document for each API Version
      /// &lt;/summary&gt;
      /// &lt;param name=&quot;options&quot;&gt;Swagger Generic Options&lt;/param&gt;
      public void Configure(SwaggerGenOptions options)
      {
          foreach (var description in provider.ApiVersionDescriptions)
          {
              options.SwaggerDoc(description.GroupName, CreateInfoForApiVersion(description.ApiVersion.ToString(), description.IsDeprecated));
          }
      }
  
      /// &lt;summary&gt;
      /// Creates Header Informations for API
      /// &lt;/summary&gt;
      /// &lt;param name=&quot;description&quot;&gt;ApiVersionDescription&lt;/param&gt;
      /// &lt;returns&gt;Api Info&lt;/returns&gt;
      static OpenApiInfo CreateInfoForApiVersion(string version, bool isDeprecated)
      {
          var info = new OpenApiInfo()
          {
              Title = &quot;Rüstkontrolle API&quot;,
              Version = version,
              Description = &quot;Service Dokumentation für das AddOn Rüstkontrolle im SICK Werkerportal&quot;,
              Contact = new OpenApiContact() { Name = &quot;Lukas Adler&quot;, Email = &quot;lukas.adler@sick.de&quot; },
              License = new OpenApiLicense() { Name = &quot;&quot;,}
          };
  
          if (isDeprecated)
          {
              info.Description += &quot;API version is deprecated.&quot;;
          }
          return info;
      }
  }
  </code></pre>
  <p><strong>Swagger Default Values</strong></p>
  <pre><code>    /// &lt;summary&gt;
  /// Swagger Operation Filter
  /// &lt;/summary&gt;
  public class SwaggerDefaultValues : IOperationFilter
  {
      /// &lt;summary&gt;
      /// Applies Operations and OperationsFilterContext on API Descriptions
      /// &lt;/summary&gt;
      /// &lt;param name=&quot;operation&quot;&gt;Operation&lt;/param&gt;
      /// &lt;param name=&quot;context&quot;&gt;OperationFilterContext&lt;/param&gt;
      public void Apply(OpenApiOperation operation, OperationFilterContext context)
      {
  
          var apiDescription = context.ApiDescription;
  
          if (operation.Parameters == null)
          {
              return;
          }
  
          foreach (var parameter in operation.Parameters)
          {
              var description = apiDescription.ParameterDescriptions.First(p =&gt; p.Name == parameter.Name);
  
              if (parameter.Description == null)
              {
                  parameter.Description = description.ModelMetadata?.Description;
              }
  
              parameter.Required |= description.IsRequired;
          }
      }
  }
  </code></pre>
  <p><strong>NSWAG Konfiguration</strong></p>
  <pre><code>    {
    &quot;runtime&quot;: &quot;NetCore21&quot;,
    &quot;defaultVariables&quot;: null,
    &quot;documentGenerator&quot;: {
      &quot;fromDocument&quot;: &quot;HERE IS NORMALLY MY API DESCRIPTION&quot;,
        &quot;url&quot;: &quot;https://localhost:44314/swagger/v1/swagger.json&quot;,
        &quot;output&quot;: null,
        &quot;newLineBehavior&quot;: &quot;Auto&quot;
      }
    },
    &quot;codeGenerators&quot;: {
      &quot;openApiToCSharpClient&quot;: {
        &quot;clientBaseClass&quot;: null,
        &quot;configurationClass&quot;: null,
        &quot;generateClientClasses&quot;: true,
        &quot;generateClientInterfaces&quot;: false,
        &quot;clientBaseInterface&quot;: null,
        &quot;injectHttpClient&quot;: true,
        &quot;disposeHttpClient&quot;: true,
        &quot;protectedMethods&quot;: [],
        &quot;generateExceptionClasses&quot;: true,
        &quot;exceptionClass&quot;: &quot;ApiException&quot;,
        &quot;wrapDtoExceptions&quot;: true,
        &quot;useHttpClientCreationMethod&quot;: false,
        &quot;httpClientType&quot;: &quot;System.Net.Http.HttpClient&quot;,
        &quot;useHttpRequestMessageCreationMethod&quot;: false,
        &quot;useBaseUrl&quot;: true,
        &quot;generateBaseUrlProperty&quot;: true,
        &quot;generateSyncMethods&quot;: false,
        &quot;generatePrepareRequestAndProcessResponseAsAsyncMethods&quot;: false,
        &quot;exposeJsonSerializerSettings&quot;: false,
        &quot;clientClassAccessModifier&quot;: &quot;public&quot;,
        &quot;typeAccessModifier&quot;: &quot;public&quot;,
        &quot;generateContractsOutput&quot;: false,
        &quot;contractsNamespace&quot;: null,
        &quot;contractsOutputFilePath&quot;: null,
        &quot;parameterDateTimeFormat&quot;: &quot;s&quot;,
        &quot;parameterDateFormat&quot;: &quot;yyyy-MM-dd&quot;,
        &quot;generateUpdateJsonSerializerSettingsMethod&quot;: true,
        &quot;useRequestAndResponseSerializationSettings&quot;: false,
        &quot;serializeTypeInformation&quot;: false,
        &quot;queryNullValue&quot;: &quot;&quot;,
        &quot;className&quot;: &quot;{controller}Client&quot;,
        &quot;operationGenerationMode&quot;: &quot;MultipleClientsFromOperationId&quot;,
        &quot;additionalNamespaceUsages&quot;: [],
        &quot;additionalContractNamespaceUsages&quot;: [],
        &quot;generateOptionalParameters&quot;: false,
        &quot;generateJsonMethods&quot;: false,
        &quot;enforceFlagEnums&quot;: false,
        &quot;parameterArrayType&quot;: &quot;System.Collections.Generic.IEnumerable&quot;,
        &quot;parameterDictionaryType&quot;: &quot;System.Collections.Generic.IDictionary&quot;,
        &quot;responseArrayType&quot;: &quot;System.Collections.Generic.ICollection&quot;,
        &quot;responseDictionaryType&quot;: &quot;System.Collections.Generic.IDictionary&quot;,
        &quot;wrapResponses&quot;: false,
        &quot;wrapResponseMethods&quot;: [],
        &quot;generateResponseClasses&quot;: true,
        &quot;responseClass&quot;: &quot;SwaggerResponse&quot;,
        &quot;namespace&quot;: &quot;MyNamespace&quot;,
        &quot;requiredPropertiesMustBeDefined&quot;: true,
        &quot;dateType&quot;: &quot;System.DateTimeOffset&quot;,
        &quot;jsonConverters&quot;: null,
        &quot;anyType&quot;: &quot;object&quot;,
        &quot;dateTimeType&quot;: &quot;System.DateTimeOffset&quot;,
        &quot;timeType&quot;: &quot;System.TimeSpan&quot;,
        &quot;timeSpanType&quot;: &quot;System.TimeSpan&quot;,
        &quot;arrayType&quot;: &quot;System.Collections.Generic.ICollection&quot;,
        &quot;arrayInstanceType&quot;: &quot;System.Collections.ObjectModel.Collection&quot;,
        &quot;dictionaryType&quot;: &quot;System.Collections.Generic.IDictionary&quot;,
        &quot;dictionaryInstanceType&quot;: &quot;System.Collections.Generic.Dictionary&quot;,
        &quot;arrayBaseType&quot;: &quot;System.Collections.ObjectModel.Collection&quot;,
        &quot;dictionaryBaseType&quot;: &quot;System.Collections.Generic.Dictionary&quot;,
        &quot;classStyle&quot;: &quot;Poco&quot;,
        &quot;jsonLibrary&quot;: &quot;NewtonsoftJson&quot;,
        &quot;generateDefaultValues&quot;: true,
        &quot;generateDataAnnotations&quot;: true,
        &quot;excludedTypeNames&quot;: [],
        &quot;excludedParameterNames&quot;: [],
        &quot;handleReferences&quot;: false,
        &quot;generateImmutableArrayProperties&quot;: false,
        &quot;generateImmutableDictionaryProperties&quot;: false,
        &quot;jsonSerializerSettingsTransformationMethod&quot;: null,
        &quot;inlineNamedArrays&quot;: false,
        &quot;inlineNamedDictionaries&quot;: false,
        &quot;inlineNamedTuples&quot;: true,
        &quot;inlineNamedAny&quot;: false,
        &quot;generateDtoTypes&quot;: true,
        &quot;generateOptionalPropertiesAsNullable&quot;: false,
        &quot;generateNullableReferenceTypes&quot;: false,
        &quot;templateDirectory&quot;: null,
        &quot;typeNameGeneratorType&quot;: null,
        &quot;propertyNameGeneratorType&quot;: null,
        &quot;enumNameGeneratorType&quot;: null,
        &quot;serviceHost&quot;: null,
        &quot;serviceSchemes&quot;: null,
        &quot;output&quot;: null,
        &quot;newLineBehavior&quot;: &quot;Auto&quot;
      }
    }
  }
  </code></pre>