| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using System.Collections.Generic; |
| | | 6 | | using CoreWCF.Web; |
| | | 7 | | using Microsoft.Extensions.Options; |
| | | 8 | | using Microsoft.OpenApi.Models; |
| | | 9 | | using Swashbuckle.AspNetCore.Swagger; |
| | | 10 | | |
| | | 11 | | namespace CoreWCF.OpenApi |
| | | 12 | | { |
| | | 13 | | internal sealed class OpenApiDocumentProvider : ISwaggerProvider |
| | | 14 | | { |
| | | 15 | | private readonly IOptions<OpenApiOptions> _options; |
| | | 16 | | private OpenApiDocument _document; |
| | | 17 | | |
| | 0 | 18 | | public OpenApiDocumentProvider( |
| | 0 | 19 | | IOptions<OpenApiOptions> options) |
| | | 20 | | { |
| | 0 | 21 | | _options = options; |
| | 0 | 22 | | } |
| | | 23 | | |
| | 0 | 24 | | public IList<OpenApiContractInfo> Contracts { get; } = new List<OpenApiContractInfo>(); |
| | | 25 | | |
| | | 26 | | public OpenApiDocument GetSwagger(string documentName, string host = null, string basePath = null) |
| | | 27 | | { |
| | 0 | 28 | | if (_document == null) |
| | | 29 | | { |
| | 0 | 30 | | _document = OpenApiSchemaBuilder.BuildOpenApiSpecificationDocument(_options.Value, Contracts); |
| | | 31 | | } |
| | | 32 | | |
| | 0 | 33 | | return _document; |
| | | 34 | | } |
| | | 35 | | } |
| | | 36 | | } |