public void Apply(OpenApiOperation operation, OperationFilterContext context) { var errorSchema = context.EnsureSchemaPresentAndGetRef <ApiError>(); var response = new OpenApiResponse { Description = "Error response describing why the operation failed", Content = new Dictionary <string, OpenApiMediaType>() { { "application/json", new OpenApiMediaType() { Schema = errorSchema } } } }; operation.Responses.Add("default", response); }
public void Apply(OpenApiOperation operation, OperationFilterContext context) { var queryAttribute = context.MethodInfo.GetCustomAttribute <EnableQueryAttribute>(); var responseType = context.MethodInfo.GetCustomAttribute <SwaggerResponseAttribute>(); if (queryAttribute == null || responseType == null) { return; } var referenceType = responseType.Type; if (responseType.Type.IsClosedTypeOf(typeof(ODataValue <>))) { // get inner list type for odata reference referenceType = referenceType.GetGenericArguments().First().GetGenericArguments().First(); } var reference = context.EnsureSchemaPresentAndGetRef(referenceType); operation.Extensions.Add(new KeyValuePair <string, IOpenApiExtension>("x-ms-odata", new OpenApiString(reference.Reference.ReferenceV2))); }
/// <summary> /// Makes sure that schema repository contains model for <typeparamref name="TModel"/>. /// Returns OpenAPI schema as a reference to the schema in repository. /// </summary> /// <typeparam name="TModel">Model type to be represented in schema repository</typeparam> /// <param name="self">The operation filter</param> /// <returns>The OpenAPI schema for <typeparamref name="TModel"/></returns> public static OpenApiSchema EnsureSchemaPresentAndGetRef <TModel>( this OperationFilterContext self) => self.EnsureSchemaPresentAndGetRef(typeof(TModel));