public OpenApiPathItem GenerateDocs(SwaggerAggregateRoute aggregateRoute, OpenApiDocument openApiDocument) { IEnumerable <RouteDocs> routes = _routesDocumentationProvider.GetRouteDocs(aggregateRoute.RouteKeys, _routes.Value); OpenApiPathItem docs = GenerateDocs(aggregateRoute, routes, openApiDocument); _postProcess(aggregateRoute, routes, docs, openApiDocument); return(docs); }
private Response CreateResponseSchema( IEnumerable <RouteDocs> routes, SwaggerAggregateRoute aggregateRoute, OpenApiDocument openApiDocument) { AggregateResponseAttribute attribute = GetAggregatorAttribute(aggregateRoute); if (attribute != null) { OpenApiSchema reference = _schemaGenerator.GenerateSchema(attribute.ResponseType, _schemaRepository); var response = new Response() { Description = attribute.Description, MediaType = attribute.MediaType, StatusCode = attribute.StatusCode }; foreach (KeyValuePair <string, OpenApiSchema> item in _schemaRepository.Schemas) { openApiDocument.Components.Schemas.Add(item.Key, item.Value); } if (reference.Reference != null) { response.Schema = _schemaRepository.Schemas[reference.Reference.Id]; } else { response.Schema = reference; } return(response); } var schema = new OpenApiSchema { Type = "object", Properties = new Dictionary <string, OpenApiSchema>(), Required = new SortedSet <string>(), AdditionalPropertiesAllowed = false }; foreach (RouteDocs docs in routes) { OpenApiResponse response = docs.GetResponse(); if (response.Content.ContainsKey(MediaTypeNames.Application.Json)) { OpenApiMediaType content = response.Content[MediaTypeNames.Application.Json]; schema.Properties.Add(docs.Key, content.Schema); } } return(new Response() { Schema = schema }); }
private static Dictionary <OperationType, OpenApiOperation> CreateOperations( SwaggerAggregateRoute aggregateRoute, IEnumerable <RouteDocs> routes, Response response) => new Dictionary <OperationType, OpenApiOperation>() { { OperationType.Get, CreateOperation(aggregateRoute, routes, response) } };
private static OpenApiOperation CreateOperation( SwaggerAggregateRoute aggregateRoute, IEnumerable <RouteDocs> routesDocs, Response response) => new OpenApiOperation() { Tags = GetTags(routesDocs), Summary = GetSummary(routesDocs), Description = GetDescription(aggregateRoute, routesDocs), Responses = OpenApiHelper.Responses(response), Parameters = GetParameters(routesDocs) };
private OpenApiPathItem GenerateDocs( SwaggerAggregateRoute aggregateRoute, IEnumerable <RouteDocs> routes, OpenApiDocument openApiDocument) { Response response = CreateResponseSchema(routes, aggregateRoute, openApiDocument); Dictionary <OperationType, OpenApiOperation> operations = CreateOperations(aggregateRoute, routes, response); return(new OpenApiPathItem() { Operations = operations }); }
private AggregateResponseAttribute GetAggregatorAttribute(SwaggerAggregateRoute aggregateRoute) { if (!aggregateRoute.Aggregator.IsNullOrEmpty()) { Response <IDefinedAggregator> aggregator = _definedAggregatorProvider .Get(new RouteBuilder().WithAggregator(aggregateRoute.Aggregator).Build()); if (!aggregator.IsError) { return(aggregator.Data.GetType().GetCustomAttribute <AggregateResponseAttribute>()); } } return(null); }