/// <summary> /// Apply the filter. /// </summary> /// <param name="openApiDoc"><see cref="OpenApiDocument"/>.</param> /// <param name="context"><see cref="DocumentFilterContext"/>.</param> public void Apply(OpenApiDocument openApiDoc, DocumentFilterContext context) { if (!this._applyFiler) { return; } foreach (var schemaDictionaryItem in openApiDoc.Components.Schemas) { var schema = schemaDictionaryItem.Value; var description = schema.AddEnumValuesDescription(this._includeDescriptionFromAttribute); if (description != null) { if (schema.Description == null) { schema.Description = description; } else if (!schema.Description.Contains(description)) { schema.Description += description; } } } if (openApiDoc.Paths.Count <= 0) { return; } // add enum descriptions to input parameters of every operation foreach (var parameter in openApiDoc.Paths.Values.SelectMany(v => v.Operations).SelectMany(op => op.Value.Parameters)) { OpenApiSchema schema = null; if (parameter.Schema.Reference == null) { if (parameter.Schema.AllOf.Count > 0) { schema = context.SchemaRepository.Schemas.FirstOrDefault(s => parameter.Schema.AllOf.FirstOrDefault(a => a.Reference.Id == s.Key) != null).Value; } else { continue; } } else { var componentReference = parameter.Schema.Reference.Id; if (!string.IsNullOrWhiteSpace(componentReference)) { schema = openApiDoc.Components.Schemas[componentReference]; } } if (schema != null) { var description = schema.AddEnumValuesDescription(this._includeDescriptionFromAttribute); if (description != null) { if (parameter.Description == null) { parameter.Description = description; } else if (!parameter.Description.Contains(description)) { parameter.Description += description; } } } } // add enum descriptions to request body foreach (var operation in openApiDoc.Paths.Values.SelectMany(v => v.Operations)) { var requestBodyContents = operation.Value.RequestBody?.Content; if (requestBodyContents != null) { foreach (var requestBodyContent in requestBodyContents) { if (requestBodyContent.Value.Schema?.Reference?.Id != null) { var schema = context.SchemaRepository.Schemas[requestBodyContent.Value.Schema?.Reference?.Id]; if (schema != null) { requestBodyContent.Value.Schema.Description = schema.Description; requestBodyContent.Value.Schema.Extensions = schema.Extensions; } } } } } }