Merge branch 'master' into readme-update
This commit is contained in:
Коммит
427b57bf6b
|
@ -0,0 +1,21 @@
|
|||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
MIT License
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
|
@ -7,13 +7,17 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{AE51B152-3EE
|
|||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{D792CF54-C0D5-4B16-ACD2-6C8932CACA54}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.OpenApi.CSharpComment.Reader", "src\Microsoft.OpenApi.CSharpComment.Reader\Microsoft.OpenApi.CSharpComment.Reader.csproj", "{14D2C330-AAA0-4813-960F-BD3D46D6CE1D}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration", "src\Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration\Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.csproj", "{14D2C330-AAA0-4813-960F-BD3D46D6CE1D}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.OpenApi.CSharpComment.Reader.Tests", "test\Microsoft.OpenApi.CSharpComment.Reader.Tests\Microsoft.OpenApi.CSharpComment.Reader.Tests.csproj", "{4FC8150B-8A9B-4FF9-9213-53AF986CDB30}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests", "test\Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests\Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.csproj", "{4FC8150B-8A9B-4FF9-9213-53AF986CDB30}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.OpenApi.CSharpComment.Reader.Tests.SampleApis", "test\Microsoft.OpenApi.CSharpComment.Reader.Tests.SampleApis\Microsoft.OpenApi.CSharpComment.Reader.Tests.SampleApis.csproj", "{2257ED33-96B6-4D37-B023-337F1E073FE4}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.SampleApis", "test\Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.SampleApis\Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.SampleApis.csproj", "{2257ED33-96B6-4D37-B023-337F1E073FE4}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts", "test\Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts\Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts.csproj", "{62A36B02-A531-48ED-B4CF-3696A5C28B65}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.Contracts", "test\Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.Contracts\Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.Contracts.csproj", "{62A36B02-A531-48ED-B4CF-3696A5C28B65}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.OpenApi.CSharpAnnotations.NewtonsoftJsonExtensions", "src\Microsoft.OpenApi.CSharpAnnotations.NewtonsoftJsonExtensions\Microsoft.OpenApi.CSharpAnnotations.NewtonsoftJsonExtensions.csproj", "{EFD530F4-6D30-4346-BD65-50BD1FBFD67F}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.OpenApi.CSharpAnnotations.NewtonsoftJsonExtensions.Tests", "test\Microsoft.OpenApi.CSharpAnnotations.NewtonsoftJsonExtensions.Tests\Microsoft.OpenApi.CSharpAnnotations.NewtonsoftJsonExtensions.Tests.csproj", "{D1348AA1-F9C9-45E3-A8BF-50B7754340FC}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
@ -37,6 +41,14 @@ Global
|
|||
{62A36B02-A531-48ED-B4CF-3696A5C28B65}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{62A36B02-A531-48ED-B4CF-3696A5C28B65}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{62A36B02-A531-48ED-B4CF-3696A5C28B65}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{EFD530F4-6D30-4346-BD65-50BD1FBFD67F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{EFD530F4-6D30-4346-BD65-50BD1FBFD67F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{EFD530F4-6D30-4346-BD65-50BD1FBFD67F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{EFD530F4-6D30-4346-BD65-50BD1FBFD67F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{D1348AA1-F9C9-45E3-A8BF-50B7754340FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{D1348AA1-F9C9-45E3-A8BF-50B7754340FC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D1348AA1-F9C9-45E3-A8BF-50B7754340FC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D1348AA1-F9C9-45E3-A8BF-50B7754340FC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -46,6 +58,8 @@ Global
|
|||
{4FC8150B-8A9B-4FF9-9213-53AF986CDB30} = {D792CF54-C0D5-4B16-ACD2-6C8932CACA54}
|
||||
{2257ED33-96B6-4D37-B023-337F1E073FE4} = {D792CF54-C0D5-4B16-ACD2-6C8932CACA54}
|
||||
{62A36B02-A531-48ED-B4CF-3696A5C28B65} = {D792CF54-C0D5-4B16-ACD2-6C8932CACA54}
|
||||
{EFD530F4-6D30-4346-BD65-50BD1FBFD67F} = {AE51B152-3EEE-4EA3-AB00-97FD96A89C6A}
|
||||
{D1348AA1-F9C9-45E3-A8BF-50B7754340FC} = {D792CF54-C0D5-4B16-ACD2-6C8932CACA54}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {7D72D95C-9B27-4041-805D-2911C573830C}
|
|
@ -3,7 +3,7 @@
|
|||
// Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
|
||||
// ------------------------------------------------------------
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.DocumentConfigFilters
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.DocumentConfigFilters
|
||||
{
|
||||
/// <summary>
|
||||
/// Settings for <see cref="IDocumentConfigFilter"/>.
|
|
@ -6,12 +6,12 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Exceptions;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Models;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Models.KnownStrings;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Exceptions;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models.KnownStrings;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.DocumentConfigFilters
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.DocumentConfigFilters
|
||||
{
|
||||
/// <summary>
|
||||
/// Populate the <see cref="DocumentVariantInfo.Attributes"/>.
|
|
@ -5,13 +5,18 @@
|
|||
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Models;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.DocumentFilters;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.DocumentConfigFilters
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.DocumentConfigFilters
|
||||
{
|
||||
/// <summary>
|
||||
/// The class representing the contract of a document config filter.
|
||||
/// The class representing the contract of a filter to process the <see cref="Dictionary{TKey,TValue}"/>
|
||||
/// where TKey is <see cref="DocumentVariantInfo"/> and TValue is <see cref="OpenApiDocument"/>
|
||||
/// based on the information in the document config element of
|
||||
/// <see cref="OpenApiGeneratorConfig.AdvancedConfigurationXmlDocument"/>, after its processed by the
|
||||
/// <see cref="IDocumentFilter"/>.
|
||||
/// </summary>
|
||||
public interface IDocumentConfigFilter
|
||||
{
|
||||
|
@ -20,9 +25,11 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.DocumentConfigFilters
|
|||
/// based on information in the document config element.
|
||||
/// </summary>
|
||||
/// <param name="documents">The documents to be updated.</param>
|
||||
/// <param name="documentConfigElement">The xml element containing document-level config in the config xml.</param>
|
||||
/// <param name="xmlDocuments">The list of XML documentations.</param>
|
||||
/// <param name="settings">The document config filter settings.</param>
|
||||
/// <param name="documentConfigElement">The xml element containing document-level config in the config xml,
|
||||
/// <see cref="OpenApiGeneratorConfig.AdvancedConfigurationXmlDocument"/>.</param>
|
||||
/// <param name="xmlDocuments">The list of XML documentations provided in
|
||||
/// <see cref="OpenApiGeneratorConfig.AnnotationXmlDocuments"/>.</param>
|
||||
/// <param name="settings"><see cref="DocumentConfigFilterSettings"/></param>
|
||||
void Apply(
|
||||
IDictionary<DocumentVariantInfo, OpenApiDocument> documents,
|
||||
XElement documentConfigElement,
|
|
@ -9,7 +9,7 @@ using System.Xml.Linq;
|
|||
using System.Xml.XPath;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.DocumentFilters
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.DocumentFilters
|
||||
{
|
||||
/// <summary>
|
||||
/// Parses the value of assembly tag in xml documentation and apply that as info in Open Api V3 specification document.
|
||||
|
@ -41,10 +41,7 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.DocumentFilters
|
|||
specificationDocument.Info = new OpenApiInfo
|
||||
{
|
||||
Title = xmlDocument.XPathSelectElement("//doc/assembly/name")?.Value,
|
||||
|
||||
// Assign version as 1.0.0 for the time being.
|
||||
// TODO: Customer should be able to input this in the Config file
|
||||
Version = "1.0.0"
|
||||
Version = settings.OpenApiDocumentVersion
|
||||
};
|
||||
}
|
||||
}
|
|
@ -3,7 +3,7 @@
|
|||
// Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
|
||||
// ------------------------------------------------------------
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.DocumentFilters
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.DocumentFilters
|
||||
{
|
||||
/// <summary>
|
||||
/// Settings for <see cref="IDocumentFilter"/>.
|
||||
|
@ -14,5 +14,10 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.DocumentFilters
|
|||
/// Gets or sets the type fetcher.
|
||||
/// </summary>
|
||||
public TypeFetcher TypeFetcher { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the OpenAPI document version.
|
||||
/// </summary>
|
||||
public string OpenApiDocumentVersion { get; set; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
// ------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
|
||||
// ------------------------------------------------------------
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.OperationFilters;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.DocumentFilters
|
||||
{
|
||||
/// <summary>
|
||||
/// The class representing the contract of a filter to process the <see cref="OpenApiDocument"/> based on the
|
||||
/// information provided in annotation xml(s), after its processed by the <see cref="IOperationFilter"/>.
|
||||
/// </summary>
|
||||
public interface IDocumentFilter
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains the required logic to populate certain parts of OpenAPI document.
|
||||
/// </summary>
|
||||
/// <param name="openApiDocument">The OpenAPI document to be updated.</param>
|
||||
/// <param name="xmlDocuments">The list of documents representing the annotation xmls,
|
||||
/// <see cref="OpenApiGeneratorConfig.AnnotationXmlDocuments"/>.</param>
|
||||
/// <param name="settings"><see cref="DocumentFilterSettings"/></param>
|
||||
void Apply(
|
||||
OpenApiDocument openApiDocument,
|
||||
IList<XDocument> xmlDocuments,
|
||||
DocumentFilterSettings settings);
|
||||
}
|
||||
}
|
|
@ -3,15 +3,16 @@
|
|||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
|
||||
// ------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using System.Xml.XPath;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Extensions;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Models.KnownStrings;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Extensions;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models.KnownStrings;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.DocumentFilters
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.DocumentFilters
|
||||
{
|
||||
/// <summary>
|
||||
/// Filter to parse the values from the summary tags for all the properties
|
||||
|
@ -22,11 +23,29 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.DocumentFilters
|
|||
/// <summary>
|
||||
/// Parses the values from the summary for all the properties to populate descriptions in the schema.
|
||||
/// </summary>
|
||||
/// <param name="specificationDocument">The Open Api V3 specification document to be updated.</param>
|
||||
/// <param name="openApiDocument">The Open API specification document to be updated.</param>
|
||||
/// <param name="xmlDocuments">The list of documents representing the annotation xmls.</param>
|
||||
/// <param name="settings">Settings for document filters.</param>
|
||||
public void Apply(OpenApiDocument specificationDocument, IList<XDocument> xmlDocuments, DocumentFilterSettings settings)
|
||||
public void Apply(
|
||||
OpenApiDocument openApiDocument,
|
||||
IList<XDocument> xmlDocuments,
|
||||
DocumentFilterSettings settings)
|
||||
{
|
||||
if (openApiDocument == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(openApiDocument));
|
||||
}
|
||||
|
||||
if (settings == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(settings));
|
||||
}
|
||||
|
||||
if (xmlDocuments == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(xmlDocuments));
|
||||
}
|
||||
|
||||
var propertyMembers = new List<XElement>();
|
||||
|
||||
foreach (var xmlDocument in xmlDocuments)
|
||||
|
@ -55,7 +74,7 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.DocumentFilters
|
|||
// should apply to those properties in schema A, A_B_, and A_B_C__ as well.
|
||||
var sanitizedClassName = className.SanitizeClassName();
|
||||
|
||||
var schemas = specificationDocument.Components.Schemas.Where(
|
||||
var schemas = openApiDocument.Components.Schemas.Where(
|
||||
s => s.Key == sanitizedClassName ||
|
||||
s.Key.StartsWith(sanitizedClassName + "_"))
|
||||
.ToList();
|
|
@ -11,7 +11,7 @@ using System.Xml.Linq;
|
|||
using System.Xml.XPath;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.DocumentFilters
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.DocumentFilters
|
||||
{
|
||||
/// <summary>
|
||||
/// Parses the value of url tag in xml documentation and apply that as server in Open Api V3 specification document.
|
|
@ -4,7 +4,7 @@
|
|||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.Exceptions
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Exceptions
|
||||
{
|
||||
/// <summary>
|
||||
/// The exception that is recorded when an error occurs while adding a schema to the schema reference registry.
|
|
@ -3,10 +3,10 @@
|
|||
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Extensions;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Models;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Extensions;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.Exceptions
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Exceptions
|
||||
{
|
||||
/// <summary>
|
||||
/// The exception that is thrown when different set of attributes and their values
|
|
@ -4,7 +4,7 @@
|
|||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.Exceptions
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Exceptions
|
||||
{
|
||||
/// <summary>
|
||||
/// The exception that is thrown when the URL contains the same parameter in both path and query.
|
|
@ -4,7 +4,7 @@
|
|||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.Exceptions
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Exceptions
|
||||
{
|
||||
/// <summary>
|
||||
/// The exception that is thrown when there is a mistake in the xml documentation
|
|
@ -4,7 +4,7 @@
|
|||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.Exceptions
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Exceptions
|
||||
{
|
||||
/// <summary>
|
||||
/// The exception that is recorded when the documentation contains operations with the same path and operation method.
|
|
@ -4,7 +4,7 @@
|
|||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.Exceptions
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Exceptions
|
||||
{
|
||||
/// <summary>
|
||||
/// The exception that is recorded when the documentation for a request body is invalid.
|
|
@ -4,7 +4,7 @@
|
|||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.Exceptions
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Exceptions
|
||||
{
|
||||
/// <summary>
|
||||
/// The exception that is recorded when a URL is missing or has invalid format.
|
|
@ -4,7 +4,7 @@
|
|||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.Exceptions
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Exceptions
|
||||
{
|
||||
/// <summary>
|
||||
/// The exception that is recorded when a verb that is missing or
|
|
@ -5,7 +5,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.Exceptions
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Exceptions
|
||||
{
|
||||
/// <summary>
|
||||
/// The exception that is thrown when one or more params are missing in attribute and the best effort
|
|
@ -4,7 +4,7 @@
|
|||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.Exceptions
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Exceptions
|
||||
{
|
||||
/// <summary>
|
||||
/// The exception that is thrown when the documentation for a response is missing description.
|
|
@ -4,7 +4,7 @@
|
|||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.Exceptions
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Exceptions
|
||||
{
|
||||
/// <summary>
|
||||
/// The exception that is recorded when unable to generate documentation for all the operations.
|
|
@ -4,7 +4,7 @@
|
|||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.Exceptions
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Exceptions
|
||||
{
|
||||
/// <summary>
|
||||
/// The exception that is thrown when there is an undocumented generic type in the xml documentation.
|
|
@ -4,7 +4,7 @@
|
|||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.Exceptions
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Exceptions
|
||||
{
|
||||
/// <summary>
|
||||
/// The exception that is thrown when there is an undocumented path parameter in the xml documentation.
|
|
@ -4,7 +4,7 @@
|
|||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.Exceptions
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Exceptions
|
||||
{
|
||||
/// <summary>
|
||||
/// The exception that is thrown when generic types are not documented in order in the xml documentation.
|
|
@ -6,12 +6,8 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Models;
|
||||
using Microsoft.OpenApi.Extensions;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Microsoft.OpenApi.Readers;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.Extensions
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods for <see cref="IDictionary{TKey,TValue}"/>.
|
||||
|
@ -82,68 +78,6 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Extensions
|
|||
!sourceDictionary.Except(targetDictionary).Any();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <see cref="Dictionary{TKey,TValue}"/>where TKey is <see cref="DocumentVariantInfo"/>
|
||||
/// and TValue is <see cref="string"/>
|
||||
/// To <see cref="Dictionary{TKey,TValue}"/>where TKey is <see cref="DocumentVariantInfo"/>
|
||||
/// and TValue is <see cref="OpenApiDocument"/>.
|
||||
/// </summary>
|
||||
/// <param name="sourceDictionary">The serialized OpenAPI documents dictionary.</param>
|
||||
/// <returns>Dictionary mapping document variant metadata to their respective OpenAPI document.
|
||||
/// </returns>
|
||||
public static IDictionary<DocumentVariantInfo, OpenApiDocument> ToOpenApiDocuments(
|
||||
this IDictionary<DocumentVariantInfo, string> sourceDictionary)
|
||||
{
|
||||
if (sourceDictionary == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(sourceDictionary));
|
||||
}
|
||||
|
||||
IDictionary<DocumentVariantInfo, OpenApiDocument> openApiDocuments =
|
||||
new Dictionary<DocumentVariantInfo, OpenApiDocument>();
|
||||
|
||||
foreach (var variantInfoDocumentKeyValuePair in sourceDictionary)
|
||||
{
|
||||
openApiDocuments[new DocumentVariantInfo(variantInfoDocumentKeyValuePair.Key)]
|
||||
= new OpenApiStringReader().Read(variantInfoDocumentKeyValuePair.Value, out var _);
|
||||
}
|
||||
|
||||
return openApiDocuments;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <see cref="Dictionary{TKey,TValue}"/>where TKey is <see cref="DocumentVariantInfo"/>
|
||||
/// and TValue is <see cref="OpenApiDocument"/>
|
||||
/// To <see cref="Dictionary{TKey,TValue}"/>where TKey is <see cref="DocumentVariantInfo"/>
|
||||
/// and TValue is <see cref="string"/>.
|
||||
/// </summary>
|
||||
/// <param name="sourceDictionary">The dictionary of OpenAPI documents.</param>
|
||||
/// <param name="openApiSpecVersion">The OpenAPI spec version to serialize to.</param>
|
||||
/// <param name="openApiFormat">The OpenAPI format to serialize to.</param>
|
||||
/// <returns>Dictionary mapping document variant metadata to their respective serialized OpenAPI document.
|
||||
/// </returns>
|
||||
public static IDictionary<DocumentVariantInfo, string> ToSerializedOpenApiDocuments(
|
||||
this IDictionary<DocumentVariantInfo, OpenApiDocument> sourceDictionary,
|
||||
OpenApiSpecVersion openApiSpecVersion = OpenApiSpecVersion.OpenApi3_0,
|
||||
OpenApiFormat openApiFormat = OpenApiFormat.Json)
|
||||
{
|
||||
if (sourceDictionary == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(sourceDictionary));
|
||||
}
|
||||
|
||||
IDictionary<DocumentVariantInfo, string> openApiDocuments =
|
||||
new Dictionary<DocumentVariantInfo, string>();
|
||||
|
||||
foreach (var variantInfoDocumentKeyValuePair in sourceDictionary)
|
||||
{
|
||||
openApiDocuments[new DocumentVariantInfo(variantInfoDocumentKeyValuePair.Key)]
|
||||
= variantInfoDocumentKeyValuePair.Value.Serialize(openApiSpecVersion, openApiFormat);
|
||||
}
|
||||
|
||||
return openApiDocuments;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <see cref="IDictionary{TKey, TValue}"/>where TKey is <see cref="string"/>
|
||||
/// and TValue is <see cref="string"/>to comma separated string e.g. {"key1":"value1","key2":"value2"}.
|
|
@ -7,7 +7,7 @@ using System;
|
|||
using System.Text.RegularExpressions;
|
||||
using System.Web;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.Extensions
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods for <see cref="string"/>.
|
|
@ -9,7 +9,7 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.Extensions
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods for <see cref="Type"/>.
|
|
@ -4,9 +4,9 @@
|
|||
using System.Text;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Models.KnownStrings;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models.KnownStrings;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.Extensions
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods for <see cref="XElement"/>.
|
|
@ -0,0 +1,42 @@
|
|||
// ------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
|
||||
// ------------------------------------------------------------
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration
|
||||
{
|
||||
/// <summary>
|
||||
/// The contract for OpenAPI document generator from csharp documentation.
|
||||
/// </summary>
|
||||
public interface IOpenApiGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// Generates an OpenAPI document based on the provided configuration, but ignores any variant configuration
|
||||
/// that may be present.
|
||||
/// </summary>
|
||||
/// <param name="openApiGeneratorConfig">The configuration that will be used to generate
|
||||
/// the document.</param>
|
||||
/// <param name="generationDiagnostic">The generation diagnostics.</param>
|
||||
/// <returns>The generated OpenAPI document.</returns>
|
||||
OpenApiDocument GenerateDocument(
|
||||
OpenApiGeneratorConfig openApiGeneratorConfig,
|
||||
out GenerationDiagnostic generationDiagnostic);
|
||||
|
||||
/// <summary>
|
||||
/// Generates an OpenAPI document per variant specified in configuration.
|
||||
/// In addition, a "default" variant document is generated, which contains no alterations based on
|
||||
/// variant metadata.
|
||||
/// </summary>
|
||||
/// <param name="openApiGeneratorConfig">The configuration that will be used to generate
|
||||
/// the document.</param>
|
||||
/// <param name="generationDiagnostic">The generation diagnostics.</param>
|
||||
/// <returns>Dictionary mapping document variant metadata to their respective OpenAPI document.</returns>
|
||||
IDictionary<DocumentVariantInfo, OpenApiDocument> GenerateDocuments(
|
||||
OpenApiGeneratorConfig openApiGeneratorConfig,
|
||||
out GenerationDiagnostic generationDiagnostic);
|
||||
}
|
||||
}
|
|
@ -6,36 +6,36 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using System.Xml.XPath;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.DocumentConfigFilters;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.DocumentFilters;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Exceptions;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Extensions;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Models;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.OperationConfigFilters;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.OperationFilters;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.PostProcessingDocumentFilters;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.PreprocessingOperationFilters;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.ReferenceRegistries;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.DocumentConfigFilters;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.DocumentFilters;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Exceptions;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Extensions;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.OperationConfigFilters;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.OperationFilters;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.PostProcessingDocumentFilters;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.PreprocessingOperationFilters;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.ReferenceRegistries;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides functionality to parse xml documentation and contract assemblies into OpenAPI documents.
|
||||
/// </summary>
|
||||
internal class InternalOpenApiDocumentGenerator
|
||||
internal class InternalOpenApiGenerator
|
||||
{
|
||||
private readonly CSharpCommentOpenApiGeneratorFilterConfig _cSharpCommentOpenApiGeneratorFilterConfig;
|
||||
private readonly OpenApiGeneratorFilterConfig _openApiGeneratorFilterConfig;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="InternalOpenApiDocumentGenerator"/>.
|
||||
/// Creates a new instance of <see cref="InternalOpenApiGenerator"/>.
|
||||
/// </summary>
|
||||
/// <param name="cSharpCommentOpenApiGeneratorFilterConfig">The configuration encapsulating all the filters
|
||||
/// that will be applied while generating/processing OpenAPI document from C# comments.</param>
|
||||
public InternalOpenApiDocumentGenerator(
|
||||
CSharpCommentOpenApiGeneratorFilterConfig cSharpCommentOpenApiGeneratorFilterConfig)
|
||||
/// <param name="openApiGeneratorFilterConfig">The configuration encapsulating all the filters
|
||||
/// that will be applied while generating/processing OpenAPI document from C# annotations.</param>
|
||||
public InternalOpenApiGenerator(
|
||||
OpenApiGeneratorFilterConfig openApiGeneratorFilterConfig)
|
||||
{
|
||||
_cSharpCommentOpenApiGeneratorFilterConfig = cSharpCommentOpenApiGeneratorFilterConfig;
|
||||
_openApiGeneratorFilterConfig = openApiGeneratorFilterConfig;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -53,7 +53,7 @@ namespace Microsoft.OpenApi.CSharpComment.Reader
|
|||
var paths = new OpenApiPaths();
|
||||
|
||||
foreach (var preprocessingOperationFilter in
|
||||
_cSharpCommentOpenApiGeneratorFilterConfig.PreProcessingOperationFilters)
|
||||
_openApiGeneratorFilterConfig.PreProcessingOperationFilters)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -100,7 +100,7 @@ namespace Microsoft.OpenApi.CSharpComment.Reader
|
|||
// Apply all the operation-related filters to extract information related to the operation.
|
||||
// It is important that these are applied before the config filters below
|
||||
// since the config filters may rely on information generated from operation filters.
|
||||
foreach (var operationFilter in _cSharpCommentOpenApiGeneratorFilterConfig.OperationFilters)
|
||||
foreach (var operationFilter in _openApiGeneratorFilterConfig.OperationFilters)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -125,7 +125,7 @@ namespace Microsoft.OpenApi.CSharpComment.Reader
|
|||
{
|
||||
// Apply the config-related filters to extract information from the config xml
|
||||
// that can be applied to the operations.
|
||||
foreach (var configFilter in _cSharpCommentOpenApiGeneratorFilterConfig.OperationConfigFilters)
|
||||
foreach (var configFilter in _openApiGeneratorFilterConfig.OperationConfigFilters)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -135,7 +135,7 @@ namespace Microsoft.OpenApi.CSharpComment.Reader
|
|||
new OperationConfigFilterSettings
|
||||
{
|
||||
OperationFilterSettings = operationFilterSettings,
|
||||
OperationFilters = _cSharpCommentOpenApiGeneratorFilterConfig.OperationFilters
|
||||
OperationFilters = _openApiGeneratorFilterConfig.OperationFilters
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@ -197,27 +197,22 @@ namespace Microsoft.OpenApi.CSharpComment.Reader
|
|||
/// <param name="annotationXmlDocuments">The list of XDocuments representing annotation xmls.</param>
|
||||
/// <param name="contractAssemblyPaths">The contract assembly paths.</param>
|
||||
/// <param name="configurationXml">The serialized XDocument representing the generation configuration.</param>
|
||||
/// <param name="openApiSpecVersion">Specification version of the OpenAPI documents to generate.</param>
|
||||
/// <param name="openApiFormat">Format (YAML or JSON) of the OpenAPI document to generate.</param>
|
||||
/// <param name="openApiDocumentVersion">The version of the OpenAPI document.</param>
|
||||
/// <param name="generationDiagnostic">A string representing serialized version of
|
||||
/// <see cref="GenerationDiagnostic"/>>
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// A string representing serialized version of <see cref="IDictionary{DocumentVariantInfo, OpenApiDocument}"/>>
|
||||
/// Dictionary mapping document variant metadata to their respective OpenAPI document.
|
||||
/// </returns>
|
||||
/// <remarks>
|
||||
/// Given that this function is expected to be called from an isolated domain,
|
||||
/// the input and output must be serializable to string or value type.
|
||||
/// </remarks>
|
||||
public IDictionary<DocumentVariantInfo, string> GenerateOpenApiDocuments(
|
||||
public IDictionary<DocumentVariantInfo, OpenApiDocument> GenerateOpenApiDocuments(
|
||||
IList<XDocument> annotationXmlDocuments,
|
||||
IList<string> contractAssemblyPaths,
|
||||
string configurationXml,
|
||||
OpenApiSpecVersion openApiSpecVersion,
|
||||
OpenApiFormat openApiFormat,
|
||||
string openApiDocumentVersion,
|
||||
out GenerationDiagnostic generationDiagnostic)
|
||||
{
|
||||
IDictionary<DocumentVariantInfo, string> openApiDocuments = new Dictionary<DocumentVariantInfo, string>();
|
||||
IDictionary<DocumentVariantInfo, OpenApiDocument> openApiDocuments
|
||||
= new Dictionary<DocumentVariantInfo, OpenApiDocument>();
|
||||
|
||||
var operationElements = new List<XElement>();
|
||||
|
||||
|
@ -298,7 +293,7 @@ namespace Microsoft.OpenApi.CSharpComment.Reader
|
|||
{
|
||||
var openApiDocument = variantInfoDocumentValuePair.Value;
|
||||
|
||||
foreach (var documentFilter in _cSharpCommentOpenApiGeneratorFilterConfig.DocumentFilters)
|
||||
foreach (var documentFilter in _openApiGeneratorFilterConfig.DocumentFilters)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -307,7 +302,8 @@ namespace Microsoft.OpenApi.CSharpComment.Reader
|
|||
annotationXmlDocuments,
|
||||
new DocumentFilterSettings
|
||||
{
|
||||
TypeFetcher = typeFetcher
|
||||
TypeFetcher = typeFetcher,
|
||||
OpenApiDocumentVersion = openApiDocumentVersion
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@ -320,12 +316,22 @@ namespace Microsoft.OpenApi.CSharpComment.Reader
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var filter in _openApiGeneratorFilterConfig.PostProcessingDocumentFilters)
|
||||
{
|
||||
filter.Apply(
|
||||
openApiDocument,
|
||||
new PostProcessingDocumentFilterSettings()
|
||||
{
|
||||
OperationGenerationDiagnostics = operationGenerationDiagnostics
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (documentConfigElement != null)
|
||||
{
|
||||
foreach (var documentConfigFilter in
|
||||
_cSharpCommentOpenApiGeneratorFilterConfig.DocumentConfigFilters)
|
||||
_openApiGeneratorFilterConfig.DocumentConfigFilters)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -366,7 +372,7 @@ namespace Microsoft.OpenApi.CSharpComment.Reader
|
|||
}
|
||||
|
||||
generationDiagnostic.DocumentGenerationDiagnostic = documentGenerationDiagnostic;
|
||||
return documents.ToSerializedOpenApiDocuments(openApiSpecVersion, openApiFormat);
|
||||
return documents;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -532,16 +538,6 @@ namespace Microsoft.OpenApi.CSharpComment.Reader
|
|||
referenceRegistryManagerMap[documentVariantInfo]
|
||||
.SchemaReferenceRegistry.References.CopyInto(
|
||||
specificationDocuments[documentVariantInfo].Components.Schemas);
|
||||
|
||||
foreach (var filter in _cSharpCommentOpenApiGeneratorFilterConfig.PostProcessingDocumentFilters)
|
||||
{
|
||||
filter.Apply(
|
||||
specificationDocuments[documentVariantInfo],
|
||||
new PostProcessingDocumentFilterSettings()
|
||||
{
|
||||
OperationGenerationDiagnostics = operationGenerationResults
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return operationGenerationResults;
|
|
@ -7,8 +7,8 @@
|
|||
<ProjectGuid>{14D2C330-AAA0-4813-960F-BD3D46D6CE1D}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Microsoft.OpenApi.CSharpComment.Reader</RootNamespace>
|
||||
<AssemblyName>Microsoft.OpenApi.CSharpComment.Reader</AssemblyName>
|
||||
<RootNamespace>Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration</RootNamespace>
|
||||
<AssemblyName>Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile />
|
||||
|
@ -21,7 +21,7 @@
|
|||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DocumentationFile>bin\Debug\Microsoft.OpenApi.CSharpComment.Reader.xml</DocumentationFile>
|
||||
<DocumentationFile>bin\Debug\Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
|
@ -30,7 +30,7 @@
|
|||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DocumentationFile>bin\Release\Microsoft.OpenApi.CSharpComment.Reader.xml</DocumentationFile>
|
||||
<DocumentationFile>bin\Release\Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.OpenApi, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3f5743946376f042, processorArchitecture=MSIL">
|
||||
|
@ -53,8 +53,8 @@
|
|||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CSharpCommentOpenApiGeneratorConfig.cs" />
|
||||
<Compile Include="CSharpCommentOpenApiGeneratorFilterConfig.cs" />
|
||||
<Compile Include="OpenApiGeneratorConfig.cs" />
|
||||
<Compile Include="OpenApiGeneratorFilterConfig.cs" />
|
||||
<Compile Include="DocumentConfigFilters\DocumentVariantAttributesFilter.cs" />
|
||||
<Compile Include="DocumentFilters\MemberSummaryToSchemaDescriptionFilter.cs" />
|
||||
<Compile Include="DocumentFilters\DocumentFilterSettings.cs" />
|
||||
|
@ -70,7 +70,7 @@
|
|||
<Compile Include="DocumentConfigFilters\IDocumentConfigFilter.cs" />
|
||||
<Compile Include="DocumentConfigFilters\DocumentConfigFilterSettings.cs" />
|
||||
<Compile Include="Extensions\XElementExtensions.cs" />
|
||||
<Compile Include="ICSharpCommentOpenApiGenerator.cs" />
|
||||
<Compile Include="IOpenApiGenerator.cs" />
|
||||
<Compile Include="Models\GenerationError.cs" />
|
||||
<Compile Include="Models\DocumentGenerationDiagnostic.cs" />
|
||||
<Compile Include="OperationConfigFilters\CommonAnnotationFilter.cs" />
|
||||
|
@ -106,7 +106,7 @@
|
|||
<Compile Include="Exceptions\DocumentationException.cs" />
|
||||
<Compile Include="Exceptions\MissingInAttributeException.cs" />
|
||||
<Compile Include="Extensions\DictionaryExtensions.cs" />
|
||||
<Compile Include="InternalOpenApiDocumentGenerator.cs" />
|
||||
<Compile Include="InternalOpenApiGenerator.cs" />
|
||||
<Compile Include="Models\GenerationDiagnostic.cs" />
|
||||
<Compile Include="Models\OperationGenerationDiagnostic.cs" />
|
||||
<Compile Include="ReferenceRegistries\ParameterReferenceRegistry.cs" />
|
||||
|
@ -114,13 +114,13 @@
|
|||
<Compile Include="ReferenceRegistries\SchemaReferenceRegistry.cs" />
|
||||
<Compile Include="ReferenceRegistries\ReferenceRegistryManager.cs" />
|
||||
<Compile Include="ReferenceRegistries\ReferenceRegistry.cs" />
|
||||
<Compile Include="CSharpCommentOpenApiGenerator.cs" />
|
||||
<Compile Include="OpenApiGenerator.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SpecificationGenerationMessages.cs" />
|
||||
<Compile Include="Extensions\TypeExtensions.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Microsoft.OpenApi.CSharpComment.Reader.nuspec" />
|
||||
<None Include="Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.nuspec" />
|
||||
<None Include="packages.config">
|
||||
<SubType>Designer</SubType>
|
||||
</None>
|
|
@ -1,13 +1,13 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
|
||||
<metadata>
|
||||
<id>Microsoft.OpenApi.CSharpComment.Reader</id>
|
||||
<version>1.0.0-beta019</version>
|
||||
<id>Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration</id>
|
||||
<version>1.0.0-beta020</version>
|
||||
<authors>Microsoft</authors>
|
||||
<description>Reader that translates Visual Studio C# comments into .NET objects representing OpenAPI specification.</description>
|
||||
<description>Library that translates Visual Studio C# Annotations into .NET objects representing OpenAPI specification.</description>
|
||||
<dependencies>
|
||||
<dependency id="Microsoft.OpenApi" version="1.0.0-beta014"/>
|
||||
<dependency id="Microsoft.OpenApi.Readers" version="1.0.0-beta014"/>
|
||||
<dependency id="Microsoft.OpenApi" version="1.0.0-beta015"/>
|
||||
<dependency id="Microsoft.OpenApi.Readers" version="1.0.0-beta015"/>
|
||||
</dependencies>
|
||||
</metadata>
|
||||
</package>
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.Models
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Object containing all diagnostic information related to document-level of generation process.
|
|
@ -4,9 +4,9 @@
|
|||
// ------------------------------------------------------------
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Extensions;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Extensions;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.Models
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Class encapsulating information for a variant of a document.
|
|
@ -5,7 +5,7 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using Microsoft.OpenApi.Readers.Interface;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.Models
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Object coining all diagnostic information related to OpenApi document generation.
|
|
@ -3,7 +3,7 @@
|
|||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
|
||||
// ------------------------------------------------------------
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.Models
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Model representing the generation error for the operation.
|
|
@ -3,9 +3,12 @@
|
|||
// Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
|
||||
// ------------------------------------------------------------
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.Models.KnownStrings
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models.KnownStrings
|
||||
{
|
||||
internal class KnownXmlStrings
|
||||
/// <summary>
|
||||
/// Class to store known xml tags that will be processed by the generation engine.
|
||||
/// </summary>
|
||||
public class KnownXmlStrings
|
||||
{
|
||||
public const string Annotation = "annotation";
|
||||
public const string Body = "body";
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.Models
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Object containing all diagnostic information related to operation-level of generation process.
|
|
@ -0,0 +1,65 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration
|
||||
{
|
||||
/// <summary>
|
||||
/// The class that holds functionality to generate OpenAPI document from csharp documentation.
|
||||
/// </summary>
|
||||
public class OpenApiGenerator : IOpenApiGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// Generates an OpenAPI document based on the provided configuration, but ignores any variant configuration
|
||||
/// that may be present.
|
||||
/// </summary>
|
||||
/// <param name="openApiGeneratorConfig">The configuration that will be used to generate
|
||||
/// the document.</param>
|
||||
/// <param name="generationDiagnostic">The generation diagnostics.</param>
|
||||
/// <returns>The generated OpenAPI document.</returns>
|
||||
public OpenApiDocument GenerateDocument(
|
||||
OpenApiGeneratorConfig openApiGeneratorConfig,
|
||||
out GenerationDiagnostic generationDiagnostic)
|
||||
{
|
||||
var documents = GenerateDocuments(openApiGeneratorConfig, out generationDiagnostic);
|
||||
|
||||
return documents?.Count == 0 ? null : documents[DocumentVariantInfo.Default];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates an OpenAPI document per variant specified in configuration.
|
||||
/// In addition, a "default" variant document is generated, which contains no alterations based on
|
||||
/// variant metadata.
|
||||
/// </summary>
|
||||
/// <param name="openApiGeneratorConfig">The configuration that will be used to generate
|
||||
/// the document.</param>
|
||||
/// <param name="generationDiagnostic">The generation diagnostics.</param>
|
||||
/// <returns>Dictionary mapping document variant metadata to their respective OpenAPI document.</returns>
|
||||
public IDictionary<DocumentVariantInfo, OpenApiDocument> GenerateDocuments(
|
||||
OpenApiGeneratorConfig openApiGeneratorConfig,
|
||||
out GenerationDiagnostic generationDiagnostic)
|
||||
{
|
||||
foreach (var assemblyPath in openApiGeneratorConfig.AssemblyPaths)
|
||||
{
|
||||
if (!File.Exists(assemblyPath))
|
||||
{
|
||||
throw new FileNotFoundException(assemblyPath);
|
||||
}
|
||||
}
|
||||
|
||||
var internalOpenApiGenerator = new InternalOpenApiGenerator(
|
||||
openApiGeneratorConfig.OpenApiGeneratorFilterConfig);
|
||||
|
||||
return internalOpenApiGenerator.GenerateOpenApiDocuments(
|
||||
openApiGeneratorConfig.AnnotationXmlDocuments,
|
||||
openApiGeneratorConfig.AssemblyPaths,
|
||||
openApiGeneratorConfig.AdvancedConfigurationXmlDocument?.ToString(),
|
||||
openApiGeneratorConfig.OpenApiDocumentVersion,
|
||||
out generationDiagnostic);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,51 +5,49 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration
|
||||
{
|
||||
/// <summary>
|
||||
/// The class to store the configuration that will be used to generate the OpenAPI document from csharp
|
||||
/// documentation.
|
||||
/// </summary>
|
||||
public class CSharpCommentOpenApiGeneratorConfig
|
||||
public class OpenApiGeneratorConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="CSharpCommentOpenApiGeneratorConfig"/>.
|
||||
/// Creates a new instance of <see cref="OpenApiGeneratorConfig"/>.
|
||||
/// </summary>
|
||||
/// <param name="annotationXmlDocuments">The XDocuments representing the annotation xmls.</param>
|
||||
/// <param name="assemblyPaths">The list of relative or absolute paths to the assemblies that will be used to
|
||||
/// reflect into the types provided in the xml.
|
||||
/// </param>
|
||||
/// <param name="openApiSpecificationVersion">The specification version of the OpenAPI document to generate.
|
||||
/// </param>
|
||||
public CSharpCommentOpenApiGeneratorConfig(
|
||||
/// <param name="openApiDocumentVersion">The version of the OpenAPI document.</param>
|
||||
public OpenApiGeneratorConfig(
|
||||
IList<XDocument> annotationXmlDocuments,
|
||||
IList<string> assemblyPaths,
|
||||
OpenApiSpecVersion openApiSpecificationVersion)
|
||||
string openApiDocumentVersion)
|
||||
: this(
|
||||
annotationXmlDocuments,
|
||||
assemblyPaths,
|
||||
openApiSpecificationVersion,
|
||||
new CSharpCommentOpenApiGeneratorFilterConfig())
|
||||
openApiDocumentVersion,
|
||||
new OpenApiGeneratorFilterConfig())
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="CSharpCommentOpenApiGeneratorConfig"/>.
|
||||
/// Creates a new instance of <see cref="OpenApiGeneratorConfig"/>.
|
||||
/// </summary>
|
||||
/// <param name="annotationXmlDocuments">The XDocuments representing the annotation xmls.</param>
|
||||
/// <param name="assemblyPaths">The list of relative or absolute paths to the assemblies that will be used to
|
||||
/// reflect into the types provided in the xml.
|
||||
/// </param>
|
||||
/// <param name="openApiSpecificationVersion">The specification version of the OpenAPI document to generate.
|
||||
/// </param>
|
||||
/// <param name="cSharpCommentOpenApiGeneratorFilterConfig">The configuration encapsulating all the filters
|
||||
/// that will be applied while generating/processing OpenAPI document from C# comments.</param>
|
||||
public CSharpCommentOpenApiGeneratorConfig(
|
||||
/// <param name="openApiDocumentVersion">The version of the OpenAPI document.</param>
|
||||
/// <param name="openApiGeneratorFilterConfig">The configuration encapsulating all the filters
|
||||
/// that will be applied while generating/processing OpenAPI document from C# annotations.</param>
|
||||
public OpenApiGeneratorConfig(
|
||||
IList<XDocument> annotationXmlDocuments,
|
||||
IList<string> assemblyPaths,
|
||||
OpenApiSpecVersion openApiSpecificationVersion,
|
||||
CSharpCommentOpenApiGeneratorFilterConfig cSharpCommentOpenApiGeneratorFilterConfig )
|
||||
string openApiDocumentVersion,
|
||||
OpenApiGeneratorFilterConfig openApiGeneratorFilterConfig)
|
||||
{
|
||||
AnnotationXmlDocuments = annotationXmlDocuments
|
||||
?? throw new ArgumentNullException(nameof(annotationXmlDocuments));
|
||||
|
@ -57,10 +55,15 @@ namespace Microsoft.OpenApi.CSharpComment.Reader
|
|||
AssemblyPaths = assemblyPaths
|
||||
?? throw new ArgumentNullException(nameof(assemblyPaths));
|
||||
|
||||
CSharpCommentOpenApiGeneratorFilterConfig = cSharpCommentOpenApiGeneratorFilterConfig
|
||||
?? throw new ArgumentNullException(nameof(cSharpCommentOpenApiGeneratorFilterConfig));
|
||||
OpenApiGeneratorFilterConfig = openApiGeneratorFilterConfig
|
||||
?? throw new ArgumentNullException(nameof(openApiGeneratorFilterConfig));
|
||||
|
||||
OpenApiSpecificationVersion = openApiSpecificationVersion;
|
||||
if (string.IsNullOrWhiteSpace(openApiDocumentVersion))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(openApiDocumentVersion));
|
||||
}
|
||||
|
||||
OpenApiDocumentVersion = openApiDocumentVersion;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -79,20 +82,15 @@ namespace Microsoft.OpenApi.CSharpComment.Reader
|
|||
/// </summary>
|
||||
public IList<string> AssemblyPaths { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The version of the OpenAPI document.
|
||||
/// </summary>
|
||||
public string OpenApiDocumentVersion { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The configuration encapsulating all the filters that will be applied while generating/processing OpenAPI
|
||||
/// document from C# comments.
|
||||
/// document from C# annotations.
|
||||
/// </summary>
|
||||
public CSharpCommentOpenApiGeneratorFilterConfig CSharpCommentOpenApiGeneratorFilterConfig { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The format (YAML or JSON) of the OpenAPI document to generate.
|
||||
/// </summary>
|
||||
public OpenApiFormat OpenApiFormat { get; set; } = OpenApiFormat.Json;
|
||||
|
||||
/// <summary>
|
||||
/// The specification version of the OpenAPI document to generate.
|
||||
/// </summary>
|
||||
public OpenApiSpecVersion OpenApiSpecificationVersion { get; }
|
||||
public OpenApiGeneratorFilterConfig OpenApiGeneratorFilterConfig { get; }
|
||||
}
|
||||
}
|
|
@ -4,20 +4,20 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.DocumentConfigFilters;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.DocumentFilters;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.OperationConfigFilters;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.OperationFilters;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.PostProcessingDocumentFilters;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.PreprocessingOperationFilters;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.DocumentConfigFilters;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.DocumentFilters;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.OperationConfigFilters;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.OperationFilters;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.PostProcessingDocumentFilters;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.PreprocessingOperationFilters;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration
|
||||
{
|
||||
/// <summary>
|
||||
/// The class encapsulating all the filters that will be applied while generating/processing OpenAPI document from
|
||||
/// C# comments.
|
||||
/// C# annotations.
|
||||
/// </summary>
|
||||
public class CSharpCommentOpenApiGeneratorFilterConfig
|
||||
public class OpenApiGeneratorFilterConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// List of default document config filters.
|
||||
|
@ -83,9 +83,9 @@ namespace Microsoft.OpenApi.CSharpComment.Reader
|
|||
};
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="CSharpCommentOpenApiGeneratorFilterConfig"/> with default filters.
|
||||
/// Creates a new instance of <see cref="OpenApiGeneratorFilterConfig"/> with default filters.
|
||||
/// </summary>
|
||||
public CSharpCommentOpenApiGeneratorFilterConfig()
|
||||
public OpenApiGeneratorFilterConfig()
|
||||
: this(
|
||||
DefaultDocumentFilters.ToList(),
|
||||
DefaultOperationFilters.ToList(),
|
||||
|
@ -97,7 +97,7 @@ namespace Microsoft.OpenApi.CSharpComment.Reader
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="CSharpCommentOpenApiGeneratorFilterConfig"/> with provided filters.
|
||||
/// Creates a new instance of <see cref="OpenApiGeneratorFilterConfig"/> with provided filters.
|
||||
/// </summary>
|
||||
/// <param name="documentFilters">The list of document filters.</param>
|
||||
/// <param name="operationFilters">The list of operation filters.</param>
|
||||
|
@ -105,7 +105,7 @@ namespace Microsoft.OpenApi.CSharpComment.Reader
|
|||
/// <param name="documentConfigFilters">The list of document config filters.</param>
|
||||
/// <param name="postProcessingDocumentFilters">The list of post processing document filters.</param>
|
||||
/// <param name="preProcessingOperationFilters">The list of pre processing operation filters.</param>
|
||||
public CSharpCommentOpenApiGeneratorFilterConfig(
|
||||
public OpenApiGeneratorFilterConfig(
|
||||
IList<IDocumentFilter> documentFilters,
|
||||
IList<IOperationFilter> operationFilters,
|
||||
IList<IOperationConfigFilter> operationConfigFilters,
|
|
@ -6,10 +6,10 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Models.KnownStrings;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models.KnownStrings;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.OperationConfigFilters
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.OperationConfigFilters
|
||||
{
|
||||
/// <summary>
|
||||
/// Parses the value of the annotation nodes in operation-level config and applies them to the specified operations.
|
|
@ -4,12 +4,16 @@
|
|||
// ------------------------------------------------------------
|
||||
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.OperationFilters;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.OperationConfigFilters
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.OperationConfigFilters
|
||||
{
|
||||
/// <summary>
|
||||
/// The class representing the contract of an operation config filter.
|
||||
/// The class representing the contract of a filter to process the <see cref="OpenApiOperation"/>
|
||||
/// based on the information in the operation config element in
|
||||
/// <see cref="OpenApiGeneratorConfig.AdvancedConfigurationXmlDocument"/>, after its processed by the
|
||||
/// <see cref="IOperationFilter"/>.
|
||||
/// </summary>
|
||||
public interface IOperationConfigFilter
|
||||
{
|
||||
|
@ -18,8 +22,10 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.OperationConfigFilters
|
|||
/// in the operation config element.
|
||||
/// </summary>
|
||||
/// <param name="operation">The operation to be updated.</param>
|
||||
/// <param name="element">The xml element containing operation-level config in the config xml.</param>
|
||||
/// <param name="settings">The operation config filter settings.</param>
|
||||
/// <param name="element">The xml element containing operation-level config in the config xml,
|
||||
/// <see cref="OpenApiGeneratorConfig.AdvancedConfigurationXmlDocument"/>.
|
||||
/// </param>
|
||||
/// <param name="settings"><see cref="OperationConfigFilterSettings"/></param>
|
||||
void Apply(OpenApiOperation operation, XElement element, OperationConfigFilterSettings settings);
|
||||
}
|
||||
}
|
|
@ -4,9 +4,9 @@
|
|||
// ------------------------------------------------------------
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.OperationFilters;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.OperationFilters;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.OperationConfigFilters
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.OperationConfigFilters
|
||||
{
|
||||
/// <summary>
|
||||
/// Settings for <see cref="IOperationConfigFilter"/>.
|
|
@ -6,10 +6,10 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Models.KnownStrings;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models.KnownStrings;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.OperationFilters
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.OperationFilters
|
||||
{
|
||||
/// <summary>
|
||||
/// Parses the value of group tag in xml documentation and apply that as tag in operation.
|
|
@ -6,19 +6,21 @@
|
|||
using System.Xml.Linq;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.OperationFilters
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.OperationFilters
|
||||
{
|
||||
/// <summary>
|
||||
/// The class representing the contract of a Operation filter.
|
||||
/// The class representing the contract of a filter to process the <see cref="OpenApiOperation"/>
|
||||
/// objects in <see cref="OpenApiPaths"/> based on the information provided in the operation xml element.
|
||||
/// </summary>
|
||||
public interface IOperationFilter
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains the required logic to populate certain parts of Operation object.
|
||||
/// Contains the required logic to populate certain parts of Operation object in <see cref="OpenApiOperation"/>.
|
||||
/// </summary>
|
||||
/// <param name="operation">The operation to be upated.</param>
|
||||
/// <param name="element">The xml element representing an operation in the annotation xml.</param>
|
||||
/// <param name="settings">The operation filter settings.</param>
|
||||
/// <param name="element">The xml element representing an operation in the annotation xmls provided in
|
||||
/// <see cref="OpenApiGeneratorConfig.AnnotationXmlDocuments"/>.</param>
|
||||
/// <param name="settings"><see cref="OperationFilterSettings"/></param>
|
||||
/// <remarks>
|
||||
/// Care should be taken to not overwrite the existing value in Operation if already present.
|
||||
/// This guarantees the predictable behavior that the first tag in the XML will be respected.
|
|
@ -3,9 +3,9 @@
|
|||
// Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
|
||||
// ------------------------------------------------------------
|
||||
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.ReferenceRegistries;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.ReferenceRegistries;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.OperationFilters
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.OperationFilters
|
||||
{
|
||||
/// <summary>
|
||||
/// Settings for <see cref="IOperationFilter"/>.
|
|
@ -6,12 +6,13 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Extensions;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Models.KnownStrings;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Extensions;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models.KnownStrings;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.OperationFilters
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.OperationFilters
|
||||
{
|
||||
/// <summary>
|
||||
/// Parses the value of param tag in xml documentation and apply that as parameter in operation.
|
||||
|
@ -59,9 +60,31 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.OperationFilters
|
|||
|
||||
var isRequired = paramElement.Attribute(KnownXmlStrings.Required)?.Value.Trim();
|
||||
var cref = paramElement.Attribute(KnownXmlStrings.Cref)?.Value.Trim();
|
||||
var description = paramElement.Value.RemoveBlankLines();
|
||||
|
||||
var schema = GenerateSchemaFromCref(cref, settings);
|
||||
var childNodes = paramElement.DescendantNodes().ToList();
|
||||
var description = string.Empty;
|
||||
|
||||
var lastNode = childNodes.LastOrDefault();
|
||||
|
||||
if (lastNode != null && lastNode.NodeType == XmlNodeType.Text)
|
||||
{
|
||||
description = lastNode.ToString();
|
||||
}
|
||||
|
||||
// Fetch if any see tags are present, if present populate listed types with it.
|
||||
var seeNodes = paramElement.Descendants(KnownXmlStrings.See);
|
||||
|
||||
var allListedTypes = seeNodes
|
||||
.Select(node => node.Attribute(KnownXmlStrings.Cref)?.Value)
|
||||
.Where(crefValue => crefValue != null).ToList();
|
||||
|
||||
// If no see tags are present, add the value from cref tag.
|
||||
if (!allListedTypes.Any() && !string.IsNullOrWhiteSpace(cref))
|
||||
{
|
||||
allListedTypes.Add(cref);
|
||||
}
|
||||
|
||||
var schema = GenerateSchemaFromCref(allListedTypes, settings);
|
||||
var parameterLocation = GetParameterKind(inValue);
|
||||
|
||||
operation.Parameters.Add(
|
||||
|
@ -77,19 +100,19 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.OperationFilters
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates schema from type name in cref.
|
||||
/// Generates schema from type names in cref.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// Schema from type in cref if the type is resolvable.
|
||||
/// Otherwise, default to schema for string type.
|
||||
/// </returns>
|
||||
private static OpenApiSchema GenerateSchemaFromCref(string cref, OperationFilterSettings settings)
|
||||
private static OpenApiSchema GenerateSchemaFromCref(IList<string> crefValues, OperationFilterSettings settings)
|
||||
{
|
||||
var type = typeof(string);
|
||||
|
||||
if (cref != null)
|
||||
if (crefValues.Any())
|
||||
{
|
||||
type = settings.TypeFetcher.LoadTypeFromCrefValues(new List<string>() { cref });
|
||||
type = settings.TypeFetcher.LoadTypeFromCrefValues(crefValues);
|
||||
}
|
||||
|
||||
return settings.ReferenceRegistryManager.SchemaReferenceRegistry.FindOrAddReference(type);
|
|
@ -3,16 +3,15 @@
|
|||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
|
||||
// ------------------------------------------------------------
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Exceptions;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Extensions;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Models.KnownStrings;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Exceptions;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Extensions;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models.KnownStrings;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.OperationFilters
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.OperationFilters
|
||||
{
|
||||
/// <summary>
|
||||
/// Parses the value of param tag in xml documentation and apply that as request body in operation.
|
||||
|
@ -55,19 +54,11 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.OperationFilters
|
|||
description = lastNode.ToString();
|
||||
}
|
||||
|
||||
var allListedTypes = new List<string>();
|
||||
|
||||
var seeNodes = bodyElement.Descendants(KnownXmlStrings.See);
|
||||
|
||||
foreach (var node in seeNodes)
|
||||
{
|
||||
var crefValue = node.Attribute(KnownXmlStrings.Cref)?.Value;
|
||||
|
||||
if (crefValue != null)
|
||||
{
|
||||
allListedTypes.Add(crefValue);
|
||||
}
|
||||
}
|
||||
var allListedTypes = seeNodes
|
||||
.Select(node => node.Attribute(KnownXmlStrings.Cref)?.Value)
|
||||
.Where(crefValue => crefValue != null).ToList();
|
||||
|
||||
if (!allListedTypes.Any())
|
||||
{
|
|
@ -5,11 +5,11 @@
|
|||
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Extensions;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Models.KnownStrings;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Extensions;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models.KnownStrings;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.OperationFilters
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.OperationFilters
|
||||
{
|
||||
/// <summary>
|
||||
/// Parses the value of remarks tag in xml documentation and apply that as description of the operation.
|
|
@ -3,16 +3,15 @@
|
|||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
|
||||
// ------------------------------------------------------------
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Exceptions;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Extensions;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Models.KnownStrings;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Exceptions;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Extensions;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models.KnownStrings;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.OperationFilters
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.OperationFilters
|
||||
{
|
||||
/// <summary>
|
||||
/// Parses the value of response tag in xml documentation and apply that as response in operation.
|
||||
|
@ -68,19 +67,11 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.OperationFilters
|
|||
throw new MissingResponseDescriptionException(code);
|
||||
}
|
||||
|
||||
var allListedTypes = new List<string>();
|
||||
|
||||
var seeNodes = responseElement.Descendants(KnownXmlStrings.See);
|
||||
|
||||
foreach (var node in seeNodes)
|
||||
{
|
||||
var crefValue = node.Attribute(KnownXmlStrings.Cref)?.Value;
|
||||
|
||||
if (crefValue != null)
|
||||
{
|
||||
allListedTypes.Add(crefValue);
|
||||
}
|
||||
}
|
||||
var allListedTypes = seeNodes
|
||||
.Select(node => node.Attribute(KnownXmlStrings.Cref)?.Value)
|
||||
.Where(crefValue => crefValue != null).ToList();
|
||||
|
||||
OpenApiSchema schema = null;
|
||||
|
|
@ -5,11 +5,11 @@
|
|||
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Extensions;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Models.KnownStrings;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Extensions;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models.KnownStrings;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.OperationFilters
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.OperationFilters
|
||||
{
|
||||
/// <summary>
|
||||
/// Parses the value of summary tag in xml documentation and apply that as summary of the operation.
|
|
@ -9,12 +9,12 @@ using System.Text;
|
|||
using System.Text.RegularExpressions;
|
||||
using System.Web;
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Exceptions;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Extensions;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Models.KnownStrings;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Exceptions;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Extensions;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models.KnownStrings;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration
|
||||
{
|
||||
internal static class OperationHandler
|
||||
{
|
|
@ -3,11 +3,11 @@
|
|||
// Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
|
||||
// ------------------------------------------------------------
|
||||
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.DocumentFilters;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.OperationFilters;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.DocumentFilters;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.OperationFilters;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.PostProcessingDocumentFilters
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.PostProcessingDocumentFilters
|
||||
{
|
||||
/// <summary>
|
||||
/// The class representing the contract of a filter to post process the <see cref="OpenApiDocument"/>
|
||||
|
@ -19,7 +19,7 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.PostProcessingDocumentFilters
|
|||
/// Applies the filter to post process the <see cref="OpenApiDocument"/>.
|
||||
/// </summary>
|
||||
/// <param name="openApiDocument">The OpenAPI document to process.</param>
|
||||
/// <param name="settings">The filter settings.</param>
|
||||
/// <param name="settings"><see cref="PostProcessingDocumentFilterSettings"/></param>
|
||||
void Apply(
|
||||
OpenApiDocument openApiDocument,
|
||||
PostProcessingDocumentFilterSettings settings);
|
|
@ -3,10 +3,10 @@
|
|||
// Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
|
||||
// ------------------------------------------------------------
|
||||
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Models;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.PostProcessingDocumentFilters
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.PostProcessingDocumentFilters
|
||||
{
|
||||
/// <summary>
|
||||
/// Settings for <see cref="IPostProcessingDocumentFilter"/>.
|
|
@ -7,7 +7,7 @@ using System;
|
|||
using System.Linq;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.PostProcessingDocumentFilters
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.PostProcessingDocumentFilters
|
||||
{
|
||||
/// <summary>
|
||||
/// Removes the operations from the OpenAPI document for which generation failed.
|
|
@ -8,12 +8,11 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Exceptions;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Extensions;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Models.KnownStrings;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Extensions;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models.KnownStrings;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.PreprocessingOperationFilters
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.PreprocessingOperationFilters
|
||||
{
|
||||
/// <summary>
|
||||
/// Parses the value of the URL and creates multiple operations in the Paths object when
|
|
@ -5,10 +5,10 @@
|
|||
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Models.KnownStrings;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models.KnownStrings;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.PreprocessingOperationFilters
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.PreprocessingOperationFilters
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts the alternative param tags (queryParam, pathParam, header) to standard param tags.
|
|
@ -4,10 +4,10 @@
|
|||
// ------------------------------------------------------------
|
||||
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.OperationFilters;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.OperationFilters;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.PreprocessingOperationFilters
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.PreprocessingOperationFilters
|
||||
{
|
||||
/// <summary>
|
||||
/// The class representing the contract of a filter to preprocess the <see cref="OpenApiOperation"/>
|
||||
|
@ -22,8 +22,10 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.PreprocessingOperationFilters
|
|||
/// <see cref="IOperationFilter"/>.
|
||||
/// </summary>
|
||||
/// <param name="paths">The paths to be upated.</param>
|
||||
/// <param name="element">The xml element representing an operation in the annotation xml.</param>
|
||||
/// <param name="settings">The operation filter settings.</param>
|
||||
/// <param name="element">The xml element representing an operation in the annotation xmls provided in
|
||||
/// <see cref="OpenApiGeneratorConfig.AnnotationXmlDocuments"/>.
|
||||
/// </param>
|
||||
/// <param name="settings"><see cref="PreProcessingOperationFilterSettings"/></param>
|
||||
void Apply(OpenApiPaths paths, XElement element, PreProcessingOperationFilterSettings settings);
|
||||
}
|
||||
}
|
|
@ -7,12 +7,12 @@ using System;
|
|||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Exceptions;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Extensions;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Models.KnownStrings;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Exceptions;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Extensions;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models.KnownStrings;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.PreprocessingOperationFilters
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.PreprocessingOperationFilters
|
||||
{
|
||||
/// <summary>
|
||||
/// Parses the URL to populate the in attribute of the param tags if not explicitly documented.
|
|
@ -3,7 +3,7 @@
|
|||
// Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
|
||||
// ------------------------------------------------------------
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.PreprocessingOperationFilters
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.PreprocessingOperationFilters
|
||||
{
|
||||
/// <summary>
|
||||
/// Settings for <see cref="IPreProcessingOperationFilter"/>.
|
|
@ -11,11 +11,11 @@ using System.Runtime.InteropServices;
|
|||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Microsoft.OpenApi.CSharpComment.Reader")]
|
||||
[assembly: AssemblyTitle("Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Microsoft.OpenApi.CSharpComment.Reader")]
|
||||
[assembly: AssemblyProduct("Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration")]
|
||||
[assembly: AssemblyCopyright("Copyright © Microsoft")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
@ -42,4 +42,4 @@ using System.Runtime.InteropServices;
|
|||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
[assembly: CLSCompliant(false)]
|
||||
|
||||
[assembly: InternalsVisibleTo("Microsoft.OpenApi.CSharpComment.Reader.Tests")]
|
||||
[assembly: InternalsVisibleTo("Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests")]
|
|
@ -7,7 +7,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.ReferenceRegistries
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.ReferenceRegistries
|
||||
{
|
||||
/// <summary>
|
||||
/// Reference Registry for <see cref="OpenApiExample"/>
|
|
@ -7,7 +7,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.ReferenceRegistries
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.ReferenceRegistries
|
||||
{
|
||||
/// <summary>
|
||||
/// Reference Registry for <see cref="OpenApiParameter"/>
|
|
@ -6,7 +6,7 @@
|
|||
using System.Collections.Generic;
|
||||
using Microsoft.OpenApi.Interfaces;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.ReferenceRegistries
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.ReferenceRegistries
|
||||
{
|
||||
/// <summary>
|
||||
/// Reference Registry for an <see cref="IOpenApiReferenceable"/> class.
|
|
@ -7,7 +7,7 @@ using System;
|
|||
using Microsoft.OpenApi.Interfaces;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.ReferenceRegistries
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.ReferenceRegistries
|
||||
{
|
||||
/// <summary>
|
||||
/// A class encapsulating reference registries for all <see cref="IOpenApiReferenceable"/> types.
|
|
@ -6,11 +6,11 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.OpenApi.Any;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Exceptions;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Extensions;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Exceptions;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Extensions;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.ReferenceRegistries
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.ReferenceRegistries
|
||||
{
|
||||
/// <summary>
|
||||
/// Reference Registry for <see cref="OpenApiSchema"/>
|
|
@ -3,7 +3,7 @@
|
|||
// Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
|
||||
// ------------------------------------------------------------
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration
|
||||
{
|
||||
/// <summary>
|
||||
/// Holds the specification generation messages.
|
|
@ -9,10 +9,10 @@ using System.Globalization;
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Exceptions;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Extensions;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Exceptions;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Extensions;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration
|
||||
{
|
||||
/// <summary>
|
||||
/// Proxy class for fetching type information by loading assemblies into private AppDomain.
|
|
@ -0,0 +1,65 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{EFD530F4-6D30-4346-BD65-50BD1FBFD67F}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Microsoft.OpenApi.CSharpAnnotations.NewtonsoftJsonExtensions</RootNamespace>
|
||||
<AssemblyName>Microsoft.OpenApi.CSharpAnnotations.NewtonsoftJsonExtensions</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.OpenApi, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3f5743946376f042, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Microsoft.OpenApi.1.0.0-beta014\lib\net46\Microsoft.OpenApi.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=4.0.8.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Newtonsoft.Json.4.0.8\lib\net40\Newtonsoft.Json.dll</HintPath>
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="NewtonsoftJsonPropertyAttributeFilter.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration\Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.csproj">
|
||||
<Project>{14d2c330-aaa0-4813-960f-bd3d46d6ce1d}</Project>
|
||||
<Name>Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Microsoft.OpenApi.CSharpAnnotations.NewtonsoftJsonExtensions.nuspec" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
|
||||
<metadata>
|
||||
<id>Microsoft.OpenApi.CSharpAnnotations.NewtonsoftJsonExtensions</id>
|
||||
<version>1.0.0-beta01</version>
|
||||
<authors>Microsoft</authors>
|
||||
<description>Extension that provides the newtonsoft json filter that fetches newtonsoft json property attribute and updates OpenAPI specification.</description>
|
||||
<dependencies>
|
||||
<dependency id="Microsoft.OpenApi" version="1.0.0-beta015"/>
|
||||
<dependency id="Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration" version="1.0.0-beta020"/>
|
||||
<dependency id="Newtonsoft.json" version="4.0.8"/>
|
||||
</dependencies>
|
||||
</metadata>
|
||||
</package>
|
|
@ -0,0 +1,164 @@
|
|||
// ------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
|
||||
// ------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using System.Xml.XPath;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.DocumentFilters;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Extensions;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models.KnownStrings;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.NewtonsoftJsonExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 1. Grabs newtonsoft json property attribute and if it contains name and required information for a
|
||||
/// property, updates the corresponding property schema with it.
|
||||
/// 2. Removes properties with JsonIgnore attribute from schema.
|
||||
/// </summary>
|
||||
public class NewtonsoftJsonPropertyAttributeFilter : IDocumentFilter
|
||||
{
|
||||
/// <summary>
|
||||
/// Fetches the newtonsoft json property attribute and if it contains name and required information for a
|
||||
/// property, update the corresponding property schema with it.
|
||||
/// </summary>
|
||||
/// <param name="openApiDocument">The Open API specification document to be updated.</param>
|
||||
/// <param name="xmlDocuments">The list of documents representing the annotation xmls.</param>
|
||||
/// <param name="settings">Settings for document filters.</param>
|
||||
public void Apply(
|
||||
OpenApiDocument openApiDocument,
|
||||
IList<XDocument> xmlDocuments,
|
||||
DocumentFilterSettings settings)
|
||||
{
|
||||
if (openApiDocument == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(openApiDocument));
|
||||
}
|
||||
|
||||
if (settings == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(settings));
|
||||
}
|
||||
|
||||
if (xmlDocuments == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(xmlDocuments));
|
||||
}
|
||||
|
||||
var propertyMembers = new List<XElement>();
|
||||
|
||||
foreach (var xmlDocument in xmlDocuments)
|
||||
{
|
||||
propertyMembers.AddRange(xmlDocument.XPathSelectElements("//doc/members/member")
|
||||
.Where(
|
||||
m => m.Attribute(KnownXmlStrings.Name) != null &&
|
||||
m.Attribute(KnownXmlStrings.Name).Value.StartsWith("P:")));
|
||||
}
|
||||
|
||||
foreach (var propertyMember in propertyMembers)
|
||||
{
|
||||
var fullPropertyName = propertyMember.Attribute(KnownXmlStrings.Name).Value;
|
||||
|
||||
var splitPropertyName = fullPropertyName.Split('.');
|
||||
|
||||
// Take everything before the last period and remove the "P:" prefix.
|
||||
var className =
|
||||
string.Join(".", splitPropertyName.Take(splitPropertyName.Length - 1))
|
||||
.Substring(2);
|
||||
|
||||
// We need to sanitize class name to match the format in the schema reference registry.
|
||||
// Note that this class may also match several classes in the registry given that generics
|
||||
// with different types are treated as different schemas.
|
||||
// For example, summary information for properties in class name A
|
||||
// should apply to those properties in schema A, A_B_, and A_B_C__ as well.
|
||||
var sanitizedClassName = className.SanitizeClassName();
|
||||
|
||||
var schemas = openApiDocument.Components.Schemas.Where(
|
||||
s => s.Key == sanitizedClassName ||
|
||||
s.Key.StartsWith(sanitizedClassName + "_"))
|
||||
.ToList();
|
||||
|
||||
if (!schemas.Any())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var propertyName = splitPropertyName[splitPropertyName.Length - 1];
|
||||
|
||||
var propertyInfo = settings.TypeFetcher.LoadType(className)
|
||||
?.GetProperties()
|
||||
.FirstOrDefault(p => p.Name == propertyName);
|
||||
|
||||
string jsonPropertyName = null;
|
||||
var isPropertyRequired = false;
|
||||
var isPropertyIgnored = false;
|
||||
|
||||
if (propertyInfo != null)
|
||||
{
|
||||
var jsonPropertyAttributes =
|
||||
(JsonPropertyAttribute[])propertyInfo.GetCustomAttributes(
|
||||
typeof(JsonPropertyAttribute),
|
||||
false);
|
||||
if (jsonPropertyAttributes.Any())
|
||||
{
|
||||
// Extract the property name in JsonProperty if given.
|
||||
if (jsonPropertyAttributes[0].PropertyName != null)
|
||||
{
|
||||
jsonPropertyName = jsonPropertyAttributes[0].PropertyName;
|
||||
}
|
||||
|
||||
// Check if the property is required.
|
||||
if (jsonPropertyAttributes[0].Required == Required.Always)
|
||||
{
|
||||
isPropertyRequired = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if property is ignored.
|
||||
if (propertyInfo.GetCustomAttributes(typeof(JsonIgnoreAttribute), false).Any())
|
||||
{
|
||||
isPropertyIgnored = true;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var schema in schemas)
|
||||
{
|
||||
if (schema.Value.Properties.ContainsKey(propertyName))
|
||||
{
|
||||
// Remove ignored properties from the schema.
|
||||
if (isPropertyIgnored)
|
||||
{
|
||||
schema.Value.Properties.Remove(propertyName);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isPropertyRequired)
|
||||
{
|
||||
schema.Value.Required.Add(string.IsNullOrWhiteSpace(jsonPropertyName)
|
||||
? propertyName
|
||||
: jsonPropertyName);
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(jsonPropertyName) || propertyName == jsonPropertyName)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var propertySchema = schema.Value.Properties[propertyName];
|
||||
|
||||
//Remove old key.
|
||||
schema.Value.Properties.Remove(propertyName);
|
||||
|
||||
//Add with new json property name.
|
||||
schema.Value.Properties.Add(jsonPropertyName, propertySchema);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
// ------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
|
||||
// ------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Microsoft.OpenApi.CSharpAnnotations.NewtonsoftJsonExtensions")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Microsoft.OpenApi.CSharpAnnotations.NewtonsoftJsonExtensions")]
|
||||
[assembly: AssemblyCopyright("Copyright © Microsoft")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("EFD530F4-6D30-4346-BD65-50BD1FBFD67F")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
[assembly: CLSCompliant(false)]
|
||||
|
||||
[assembly: InternalsVisibleTo("Microsoft.OpenApi.CSharpAnnotations.NewtonsoftJsonExtensions.Tests")]
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Microsoft.OpenApi" version="1.0.0-beta014" targetFramework="net462" />
|
||||
<package id="Newtonsoft.Json" version="4.0.8" targetFramework="net462" />
|
||||
</packages>
|
|
@ -1,108 +0,0 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Extensions;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Models;
|
||||
using Microsoft.OpenApi.Extensions;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader
|
||||
{
|
||||
/// <summary>
|
||||
/// The class that holds functionality to generate OpenAPI document from csharp documentation.
|
||||
/// </summary>
|
||||
public class CSharpCommentOpenApiGenerator : ICSharpCommentOpenApiGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// Generates an OpenAPI document based on the provided configuration, but ignores any variant configuration
|
||||
/// that may be present.
|
||||
/// </summary>
|
||||
/// <param name="cSharpCommentOpenApiGeneratorConfig">The configuration that will be used to generate
|
||||
/// the document.</param>
|
||||
/// <param name="generationDiagnostic">The generation diagnostics.</param>
|
||||
/// <returns>The generated OpenAPI document.</returns>
|
||||
public OpenApiDocument GenerateDocument(
|
||||
CSharpCommentOpenApiGeneratorConfig cSharpCommentOpenApiGeneratorConfig,
|
||||
out GenerationDiagnostic generationDiagnostic)
|
||||
{
|
||||
var documents = GenerateDocuments(cSharpCommentOpenApiGeneratorConfig, out generationDiagnostic);
|
||||
|
||||
return documents?.Count == 0 ? null : documents[DocumentVariantInfo.Default];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates an OpenAPI document per variant specified in configuration.
|
||||
/// In addition, a "default" variant document is generated, which contains no alterations based on
|
||||
/// variant metadata.
|
||||
/// </summary>
|
||||
/// <param name="cSharpCommentOpenApiGeneratorConfig">The configuration that will be used to generate
|
||||
/// the document.</param>
|
||||
/// <param name="generationDiagnostic">The generation diagnostics.</param>
|
||||
/// <returns>Dictionary mapping document variant metadata to their respective OpenAPI document.</returns>
|
||||
public IDictionary<DocumentVariantInfo, OpenApiDocument> GenerateDocuments(
|
||||
CSharpCommentOpenApiGeneratorConfig cSharpCommentOpenApiGeneratorConfig,
|
||||
out GenerationDiagnostic generationDiagnostic)
|
||||
{
|
||||
var result = GenerateSerializedDocuments(
|
||||
cSharpCommentOpenApiGeneratorConfig,
|
||||
out generationDiagnostic);
|
||||
|
||||
return result.ToOpenApiDocuments();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a serialized OpenAPI document based on the provided configuration, but ignores any variant
|
||||
/// configuration that may be present.
|
||||
/// </summary>
|
||||
/// <param name="cSharpCommentOpenApiGeneratorConfig">The configuration that will be used to generate
|
||||
/// the document.</param>
|
||||
/// <param name="generationDiagnostic">The generation diagnostics.</param>
|
||||
/// <returns>The generated serialized OpenAPI document.</returns>
|
||||
public string GenerateSerializedDocument(
|
||||
CSharpCommentOpenApiGeneratorConfig cSharpCommentOpenApiGeneratorConfig,
|
||||
out GenerationDiagnostic generationDiagnostic)
|
||||
{
|
||||
var document = GenerateDocument(cSharpCommentOpenApiGeneratorConfig, out generationDiagnostic);
|
||||
|
||||
return document?.Serialize(
|
||||
cSharpCommentOpenApiGeneratorConfig.OpenApiSpecificationVersion,
|
||||
cSharpCommentOpenApiGeneratorConfig.OpenApiFormat);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generates a serialized OpenAPI document per variant specified in configuration.
|
||||
/// In addition, a serialized "default" variant document is generated, which contains no alterations based on
|
||||
/// variant metadata.
|
||||
/// </summary>
|
||||
/// <param name="cSharpCommentOpenApiGeneratorConfig">The configuration that will be used to generate
|
||||
/// the document.</param>
|
||||
/// <param name="generationDiagnostic">The generation diagnostics.</param>
|
||||
/// <returns>Dictionary mapping document variant metadata to their respective serialized OpenAPI document.
|
||||
/// </returns>
|
||||
public IDictionary<DocumentVariantInfo, string> GenerateSerializedDocuments(
|
||||
CSharpCommentOpenApiGeneratorConfig cSharpCommentOpenApiGeneratorConfig,
|
||||
out GenerationDiagnostic generationDiagnostic)
|
||||
{
|
||||
foreach (var assemblyPath in cSharpCommentOpenApiGeneratorConfig.AssemblyPaths)
|
||||
{
|
||||
if (!File.Exists(assemblyPath))
|
||||
{
|
||||
throw new FileNotFoundException(assemblyPath);
|
||||
}
|
||||
}
|
||||
|
||||
var internalOpenApiDocumentGenerator = new InternalOpenApiDocumentGenerator(
|
||||
cSharpCommentOpenApiGeneratorConfig.CSharpCommentOpenApiGeneratorFilterConfig);
|
||||
|
||||
return internalOpenApiDocumentGenerator.GenerateOpenApiDocuments(
|
||||
cSharpCommentOpenApiGeneratorConfig.AnnotationXmlDocuments,
|
||||
cSharpCommentOpenApiGeneratorConfig.AssemblyPaths,
|
||||
cSharpCommentOpenApiGeneratorConfig.AdvancedConfigurationXmlDocument?.ToString(),
|
||||
cSharpCommentOpenApiGeneratorConfig.OpenApiSpecificationVersion,
|
||||
cSharpCommentOpenApiGeneratorConfig.OpenApiFormat,
|
||||
out generationDiagnostic);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
// ------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
|
||||
// ------------------------------------------------------------
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.DocumentFilters
|
||||
{
|
||||
/// <summary>
|
||||
/// The class representing the contract of a Document filter
|
||||
/// </summary>
|
||||
public interface IDocumentFilter
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains the required logic to populate certain parts of Open Api V3 specification document.
|
||||
/// </summary>
|
||||
/// <param name="specificationDocument">The Open Api V3 specification document to be updated.</param>
|
||||
/// <param name="xmlDocuments">The list of documents representing the annotation xmls.</param>
|
||||
/// <param name="settings">Settings for document filters.</param>
|
||||
void Apply(OpenApiDocument specificationDocument, IList<XDocument> xmlDocuments, DocumentFilterSettings settings);
|
||||
}
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
// ------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
|
||||
// ------------------------------------------------------------
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Models;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader
|
||||
{
|
||||
/// <summary>
|
||||
/// The contract for OpenAPI document generator from csharp documentation.
|
||||
/// </summary>
|
||||
public interface ICSharpCommentOpenApiGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// Generates an OpenAPI document based on the provided configuration, but ignores any variant configuration
|
||||
/// that may be present.
|
||||
/// </summary>
|
||||
/// <param name="cSharpCommentOpenApiGeneratorConfig">The configuration that will be used to generate
|
||||
/// the document.</param>
|
||||
/// <param name="generationDiagnostic">The generation diagnostics.</param>
|
||||
/// <returns>The generated OpenAPI document.</returns>
|
||||
OpenApiDocument GenerateDocument(
|
||||
CSharpCommentOpenApiGeneratorConfig cSharpCommentOpenApiGeneratorConfig,
|
||||
out GenerationDiagnostic generationDiagnostic);
|
||||
|
||||
/// <summary>
|
||||
/// Generates an OpenAPI document per variant specified in configuration.
|
||||
/// In addition, a "default" variant document is generated, which contains no alterations based on
|
||||
/// variant metadata.
|
||||
/// </summary>
|
||||
/// <param name="cSharpCommentOpenApiGeneratorConfig">The configuration that will be used to generate
|
||||
/// the document.</param>
|
||||
/// <param name="generationDiagnostic">The generation diagnostics.</param>
|
||||
/// <returns>Dictionary mapping document variant metadata to their respective OpenAPI document.</returns>
|
||||
IDictionary<DocumentVariantInfo, OpenApiDocument> GenerateDocuments(
|
||||
CSharpCommentOpenApiGeneratorConfig cSharpCommentOpenApiGeneratorConfig,
|
||||
out GenerationDiagnostic generationDiagnostic);
|
||||
|
||||
/// <summary>
|
||||
/// Generates a serialized OpenAPI document based on the provided configuration, but ignores any variant
|
||||
/// configuration that may be present.
|
||||
/// </summary>
|
||||
/// <param name="cSharpCommentOpenApiGeneratorConfig">The configuration that will be used to generate
|
||||
/// the document.</param>
|
||||
/// <param name="generationDiagnostic">The generation diagnostics.</param>
|
||||
/// <returns>The generated serialized OpenAPI document.</returns>
|
||||
string GenerateSerializedDocument(
|
||||
CSharpCommentOpenApiGeneratorConfig cSharpCommentOpenApiGeneratorConfig,
|
||||
out GenerationDiagnostic generationDiagnostic);
|
||||
|
||||
/// <summary>
|
||||
/// Generates a serialized OpenAPI document per variant specified in configuration.
|
||||
/// In addition, a serialized "default" variant document is generated, which contains no alterations based on
|
||||
/// variant metadata.
|
||||
/// </summary>
|
||||
/// <param name="cSharpCommentOpenApiGeneratorConfig">The configuration that will be used to generate
|
||||
/// the document.</param>
|
||||
/// <param name="generationDiagnostic">The generation diagnostics.</param>
|
||||
/// <returns>Dictionary mapping document variant metadata to their respective serialized OpenAPI document.
|
||||
/// </returns>
|
||||
IDictionary<DocumentVariantInfo, string> GenerateSerializedDocuments(
|
||||
CSharpCommentOpenApiGeneratorConfig cSharpCommentOpenApiGeneratorConfig,
|
||||
out GenerationDiagnostic generationDiagnostic);
|
||||
}
|
||||
}
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface Sample Object 4
|
|
@ -7,8 +7,8 @@
|
|||
<ProjectGuid>{62A36B02-A531-48ED-B4CF-3696A5C28B65}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts</RootNamespace>
|
||||
<AssemblyName>Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts</AssemblyName>
|
||||
<RootNamespace>Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.Contracts</RootNamespace>
|
||||
<AssemblyName>Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.Contracts</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
|
@ -20,7 +20,7 @@
|
|||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DocumentationFile>bin\Debug\Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts.xml</DocumentationFile>
|
||||
<DocumentationFile>bin\Debug\Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.Contracts.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
|
@ -29,7 +29,7 @@
|
|||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DocumentationFile>bin\Release\Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts.xml</DocumentationFile>
|
||||
<DocumentationFile>bin\Release\Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.Contracts.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
|
@ -5,11 +5,11 @@ using System.Runtime.InteropServices;
|
|||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts")]
|
||||
[assembly: AssemblyTitle("Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.Contracts")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts")]
|
||||
[assembly: AssemblyProduct("Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.Contracts")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2018")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
|
@ -3,7 +3,7 @@
|
|||
// Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
|
||||
// ------------------------------------------------------------
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// Sample enum 1
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// Sample contract for object 1
|
|
@ -6,7 +6,7 @@
|
|||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// Sample contract for object 2
|
|
@ -6,7 +6,7 @@
|
|||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// Sample contract for object 3
|
||||
|
@ -24,5 +24,11 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts
|
|||
/// </summary>
|
||||
[JsonProperty(PropertyName = "samplePropertyObjectList", Required = Required.Default)]
|
||||
public IList<SampleObject1> SamplePropertyObjectList { get; } = new List<SampleObject1>();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the sample property object list
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public IList<SampleObject2> SamplePropertyObject2List { get; } = new List<SampleObject2>();
|
||||
}
|
||||
}
|
|
@ -6,7 +6,7 @@
|
|||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// Sample contract for object 4
|
|
@ -6,7 +6,7 @@
|
|||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.SampleApis
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.SampleApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Responsible for route configuration
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
using System.Web.Http;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.SampleApis
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.SampleApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Web config.
|
|
@ -6,9 +6,9 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Http;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.Contracts;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.SampleApis.Controllers
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.SampleApis.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Define V1 operations.
|
|
@ -7,9 +7,9 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Http;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.Contracts;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.SampleApis.Controllers
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.SampleApis.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines V2 operations.
|
|
@ -7,9 +7,9 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Http;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.Contracts;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.SampleApis.Controllers
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.SampleApis.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines V3 operations.
|
|
@ -7,9 +7,9 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Http;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts;
|
||||
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.Contracts;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.SampleApis.Controllers
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.SampleApis.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines V4 operations.
|
|
@ -0,0 +1 @@
|
|||
<%@ Application Codebehind="Global.asax.cs" Inherits="Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.SampleApis.WebApiApplication" Language="C#" %>
|
|
@ -8,7 +8,7 @@ using System.Web.Http;
|
|||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.SampleApis
|
||||
namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.SampleApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Web API Application.
|
|
@ -11,8 +11,8 @@
|
|||
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Microsoft.OpenApi.CSharpComment.Reader.Tests.SampleApis</RootNamespace>
|
||||
<AssemblyName>Microsoft.OpenApi.CSharpComment.Reader.Tests.SampleApis</AssemblyName>
|
||||
<RootNamespace>Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.SampleApis</RootNamespace>
|
||||
<AssemblyName>Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.SampleApis</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
|
||||
<MvcBuildViews>false</MvcBuildViews>
|
||||
<UseIISExpress>true</UseIISExpress>
|
||||
|
@ -34,7 +34,7 @@
|
|||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DocumentationFile>bin\Microsoft.OpenApi.CSharpComment.Reader.Tests.SampleApis.xml</DocumentationFile>
|
||||
<DocumentationFile>bin\Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.SampleApis.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
|
@ -44,7 +44,7 @@
|
|||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DocumentationFile>bin\Microsoft.OpenApi.CSharpComment.Reader.Tests.SampleApis.xml</DocumentationFile>
|
||||
<DocumentationFile>bin\Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.SampleApis.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
|
@ -142,9 +142,9 @@
|
|||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts\Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts.csproj">
|
||||
<ProjectReference Include="..\Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.Contracts\Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.Contracts.csproj">
|
||||
<Project>{62a36b02-a531-48ed-b4cf-3696a5c28b65}</Project>
|
||||
<Name>Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts</Name>
|
||||
<Name>Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.Contracts</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
|
@ -9,11 +9,11 @@ using System.Runtime.InteropServices;
|
|||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Microsoft.OpenApi.CSharpComment.Reader.Tests.SampleApis")]
|
||||
[assembly: AssemblyTitle("Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.SampleApis")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Microsoft.OpenApi.CSharpComment.Reader.Tests.SampleApis")]
|
||||
[assembly: AssemblyProduct("Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.SampleApis")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2017")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше
Загрузка…
Ссылка в новой задаче