예제 #1
0
        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);
        }
예제 #2
0
        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
            });
        }
예제 #3
0
 private static Dictionary <OperationType, OpenApiOperation> CreateOperations(
     SwaggerAggregateRoute aggregateRoute,
     IEnumerable <RouteDocs> routes,
     Response response)
 => new Dictionary <OperationType, OpenApiOperation>()
 {
     {
         OperationType.Get,
         CreateOperation(aggregateRoute, routes, response)
     }
 };
예제 #4
0
 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)
 };
예제 #5
0
        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
            });
        }
예제 #6
0
 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);
 }