Exemplo n.º 1
0
        public OpenApiDocument Generate(HttpContext httpContext, IAppEntity app, IEnumerable <ISchemaEntity> schemas)
        {
            document = NSwagHelper.CreateApiDocument(httpContext, urlOptions, app.Name);

            schemaGenerator = new OpenApiSchemaGenerator(settings);
            schemaResolver  = new OpenApiSchemaResolver(document, settings);

            statusSchema = GenerateStatusSchema();

            GenerateSchemasOperations(schemas, app);

            var context =
                new DocumentProcessorContext(document,
                                             Enumerable.Empty <Type>(),
                                             Enumerable.Empty <Type>(),
                                             schemaResolver,
                                             schemaGenerator,
                                             settings);

            foreach (var processor in settings.DocumentProcessors)
            {
                processor.Process(context);
            }

            return(document);
        }
Exemplo n.º 2
0
        private static void SetupDescription(OpenApiSecurityScheme securityScheme, string tokenUrl)
        {
            var securityDocs = NSwagHelper.LoadDocs("security");
            var securityText = securityDocs.Replace("<TOKEN_URL>", tokenUrl);

            securityScheme.Description = securityText;
        }
Exemplo n.º 3
0
        public async Task <SwaggerDocument> Generate(HttpContext httpContext, IAppEntity app, IEnumerable <ISchemaEntity> schemas)
        {
            document = NSwagHelper.CreateApiDocument(httpContext, urlOptions, app.Name);

            schemaGenerator = new SwaggerJsonSchemaGenerator(settings);
            schemaResolver  = new SwaggerSchemaResolver(document, settings);

            GenerateSchemasOperations(schemas, app);

            await GenerateDefaultErrorsAsync();

            var context =
                new DocumentProcessorContext(document,
                                             Enumerable.Empty <Type>(),
                                             Enumerable.Empty <Type>(),
                                             schemaResolver,
                                             schemaGenerator,
                                             settings);

            foreach (var processor in settings.DocumentProcessors)
            {
                await processor.ProcessAsync(context);
            }

            return(document);
        }
Exemplo n.º 4
0
        private static SwaggerSecurityScheme CreateOAuthSchema(UrlsOptions urlOptions)
        {
            var securityScheme = new SwaggerSecurityScheme();

            var tokenUrl = urlOptions.BuildUrl($"{Constants.IdentityServerPrefix}/connect/token", false);

            securityScheme.TokenUrl = tokenUrl;

            var securityDocs = NSwagHelper.LoadDocs("security");
            var securityText = securityDocs.Replace("<TOKEN_URL>", tokenUrl);

            securityScheme.Description = securityText;

            securityScheme.Type = SwaggerSecuritySchemeType.OAuth2;
            securityScheme.Flow = SwaggerOAuth2Flow.Application;

            securityScheme.Scopes = new Dictionary <string, string>
            {
                [Constants.ApiScope] = "Read and write access to the API"
            };

            return(securityScheme);
        }
Exemplo n.º 5
0
 static SchemaSwaggerGenerator()
 {
     SchemaBodyDescription  = NSwagHelper.LoadDocs("schemabody");
     SchemaQueryDescription = NSwagHelper.LoadDocs("schemaquery");
 }