Merge branch 'master' into readme-update

This commit is contained in:
ravennasoftware 2018-03-28 16:28:42 -07:00
Родитель b29b2ec53e 2b424b77e4
Коммит 427b57bf6b
229 изменённых файлов: 5677 добавлений и 3070 удалений

21
LICENSE Normal file
Просмотреть файл

@ -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 EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{D792CF54-C0D5-4B16-ACD2-6C8932CACA54}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{D792CF54-C0D5-4B16-ACD2-6C8932CACA54}"
EndProject 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 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 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 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 EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution 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}.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.ActiveCfg = Release|Any CPU
{62A36B02-A531-48ED-B4CF-3696A5C28B65}.Release|Any CPU.Build.0 = 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 EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@ -46,6 +58,8 @@ Global
{4FC8150B-8A9B-4FF9-9213-53AF986CDB30} = {D792CF54-C0D5-4B16-ACD2-6C8932CACA54} {4FC8150B-8A9B-4FF9-9213-53AF986CDB30} = {D792CF54-C0D5-4B16-ACD2-6C8932CACA54}
{2257ED33-96B6-4D37-B023-337F1E073FE4} = {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} {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 EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7D72D95C-9B27-4041-805D-2911C573830C} 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. // 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> /// <summary>
/// Settings for <see cref="IDocumentConfigFilter"/>. /// Settings for <see cref="IDocumentConfigFilter"/>.

Просмотреть файл

@ -6,12 +6,12 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Xml.Linq; using System.Xml.Linq;
using Microsoft.OpenApi.CSharpComment.Reader.Exceptions; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Exceptions;
using Microsoft.OpenApi.CSharpComment.Reader.Models; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models;
using Microsoft.OpenApi.CSharpComment.Reader.Models.KnownStrings; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models.KnownStrings;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
namespace Microsoft.OpenApi.CSharpComment.Reader.DocumentConfigFilters namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.DocumentConfigFilters
{ {
/// <summary> /// <summary>
/// Populate the <see cref="DocumentVariantInfo.Attributes"/>. /// Populate the <see cref="DocumentVariantInfo.Attributes"/>.

Просмотреть файл

@ -5,13 +5,18 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Xml.Linq; 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; using Microsoft.OpenApi.Models;
namespace Microsoft.OpenApi.CSharpComment.Reader.DocumentConfigFilters namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.DocumentConfigFilters
{ {
/// <summary> /// <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> /// </summary>
public interface IDocumentConfigFilter public interface IDocumentConfigFilter
{ {
@ -20,9 +25,11 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.DocumentConfigFilters
/// based on information in the document config element. /// based on information in the document config element.
/// </summary> /// </summary>
/// <param name="documents">The documents to be updated.</param> /// <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="documentConfigElement">The xml element containing document-level config in the config xml,
/// <param name="xmlDocuments">The list of XML documentations.</param> /// <see cref="OpenApiGeneratorConfig.AdvancedConfigurationXmlDocument"/>.</param>
/// <param name="settings">The document config filter settings.</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( void Apply(
IDictionary<DocumentVariantInfo, OpenApiDocument> documents, IDictionary<DocumentVariantInfo, OpenApiDocument> documents,
XElement documentConfigElement, XElement documentConfigElement,

Просмотреть файл

@ -9,7 +9,7 @@ using System.Xml.Linq;
using System.Xml.XPath; using System.Xml.XPath;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
namespace Microsoft.OpenApi.CSharpComment.Reader.DocumentFilters namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.DocumentFilters
{ {
/// <summary> /// <summary>
/// Parses the value of assembly tag in xml documentation and apply that as info in Open Api V3 specification document. /// 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 specificationDocument.Info = new OpenApiInfo
{ {
Title = xmlDocument.XPathSelectElement("//doc/assembly/name")?.Value, Title = xmlDocument.XPathSelectElement("//doc/assembly/name")?.Value,
Version = settings.OpenApiDocumentVersion
// 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"
}; };
} }
} }

Просмотреть файл

@ -3,7 +3,7 @@
// Licensed under the MIT License (MIT). See License.txt in the repo root for license information. // 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> /// <summary>
/// Settings for <see cref="IDocumentFilter"/>. /// Settings for <see cref="IDocumentFilter"/>.
@ -14,5 +14,10 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.DocumentFilters
/// Gets or sets the type fetcher. /// Gets or sets the type fetcher.
/// </summary> /// </summary>
public TypeFetcher TypeFetcher { get; set; } 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. // Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------ // ------------------------------------------------------------
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Xml.Linq; using System.Xml.Linq;
using System.Xml.XPath; using System.Xml.XPath;
using Microsoft.OpenApi.CSharpComment.Reader.Extensions; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Extensions;
using Microsoft.OpenApi.CSharpComment.Reader.Models.KnownStrings; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models.KnownStrings;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
namespace Microsoft.OpenApi.CSharpComment.Reader.DocumentFilters namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.DocumentFilters
{ {
/// <summary> /// <summary>
/// Filter to parse the values from the summary tags for all the properties /// Filter to parse the values from the summary tags for all the properties
@ -22,11 +23,29 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.DocumentFilters
/// <summary> /// <summary>
/// Parses the values from the summary for all the properties to populate descriptions in the schema. /// Parses the values from the summary for all the properties to populate descriptions in the schema.
/// </summary> /// </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="xmlDocuments">The list of documents representing the annotation xmls.</param>
/// <param name="settings">Settings for document filters.</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>(); var propertyMembers = new List<XElement>();
foreach (var xmlDocument in xmlDocuments) 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. // should apply to those properties in schema A, A_B_, and A_B_C__ as well.
var sanitizedClassName = className.SanitizeClassName(); var sanitizedClassName = className.SanitizeClassName();
var schemas = specificationDocument.Components.Schemas.Where( var schemas = openApiDocument.Components.Schemas.Where(
s => s.Key == sanitizedClassName || s => s.Key == sanitizedClassName ||
s.Key.StartsWith(sanitizedClassName + "_")) s.Key.StartsWith(sanitizedClassName + "_"))
.ToList(); .ToList();

Просмотреть файл

@ -11,7 +11,7 @@ using System.Xml.Linq;
using System.Xml.XPath; using System.Xml.XPath;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
namespace Microsoft.OpenApi.CSharpComment.Reader.DocumentFilters namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.DocumentFilters
{ {
/// <summary> /// <summary>
/// Parses the value of url tag in xml documentation and apply that as server in Open Api V3 specification document. /// 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;
using System.Runtime.Serialization; using System.Runtime.Serialization;
namespace Microsoft.OpenApi.CSharpComment.Reader.Exceptions namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Exceptions
{ {
/// <summary> /// <summary>
/// The exception that is recorded when an error occurs while adding a schema to the schema reference registry. /// 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;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using Microsoft.OpenApi.CSharpComment.Reader.Extensions; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Extensions;
using Microsoft.OpenApi.CSharpComment.Reader.Models; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models;
namespace Microsoft.OpenApi.CSharpComment.Reader.Exceptions namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Exceptions
{ {
/// <summary> /// <summary>
/// The exception that is thrown when different set of attributes and their values /// The exception that is thrown when different set of attributes and their values

Просмотреть файл

@ -4,7 +4,7 @@
using System; using System;
using System.Runtime.Serialization; using System.Runtime.Serialization;
namespace Microsoft.OpenApi.CSharpComment.Reader.Exceptions namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Exceptions
{ {
/// <summary> /// <summary>
/// The exception that is thrown when the URL contains the same parameter in both path and query. /// 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;
using System.Runtime.Serialization; using System.Runtime.Serialization;
namespace Microsoft.OpenApi.CSharpComment.Reader.Exceptions namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Exceptions
{ {
/// <summary> /// <summary>
/// The exception that is thrown when there is a mistake in the xml documentation /// The exception that is thrown when there is a mistake in the xml documentation

Просмотреть файл

@ -4,7 +4,7 @@
using System; using System;
using System.Runtime.Serialization; using System.Runtime.Serialization;
namespace Microsoft.OpenApi.CSharpComment.Reader.Exceptions namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Exceptions
{ {
/// <summary> /// <summary>
/// The exception that is recorded when the documentation contains operations with the same path and operation method. /// 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;
using System.Runtime.Serialization; using System.Runtime.Serialization;
namespace Microsoft.OpenApi.CSharpComment.Reader.Exceptions namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Exceptions
{ {
/// <summary> /// <summary>
/// The exception that is recorded when the documentation for a request body is invalid. /// The exception that is recorded when the documentation for a request body is invalid.

Просмотреть файл

@ -4,7 +4,7 @@
using System; using System;
using System.Runtime.Serialization; using System.Runtime.Serialization;
namespace Microsoft.OpenApi.CSharpComment.Reader.Exceptions namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Exceptions
{ {
/// <summary> /// <summary>
/// The exception that is recorded when a URL is missing or has invalid format. /// The exception that is recorded when a URL is missing or has invalid format.

Просмотреть файл

@ -4,7 +4,7 @@
using System; using System;
using System.Runtime.Serialization; using System.Runtime.Serialization;
namespace Microsoft.OpenApi.CSharpComment.Reader.Exceptions namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Exceptions
{ {
/// <summary> /// <summary>
/// The exception that is recorded when a verb that is missing or /// The exception that is recorded when a verb that is missing or

Просмотреть файл

@ -5,7 +5,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.Serialization; using System.Runtime.Serialization;
namespace Microsoft.OpenApi.CSharpComment.Reader.Exceptions namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Exceptions
{ {
/// <summary> /// <summary>
/// The exception that is thrown when one or more params are missing in attribute and the best effort /// 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;
using System.Runtime.Serialization; using System.Runtime.Serialization;
namespace Microsoft.OpenApi.CSharpComment.Reader.Exceptions namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Exceptions
{ {
/// <summary> /// <summary>
/// The exception that is thrown when the documentation for a response is missing description. /// The exception that is thrown when the documentation for a response is missing description.

Просмотреть файл

@ -4,7 +4,7 @@
using System; using System;
using System.Runtime.Serialization; using System.Runtime.Serialization;
namespace Microsoft.OpenApi.CSharpComment.Reader.Exceptions namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Exceptions
{ {
/// <summary> /// <summary>
/// The exception that is recorded when unable to generate documentation for all the operations. /// The exception that is recorded when unable to generate documentation for all the operations.

Просмотреть файл

@ -4,7 +4,7 @@
using System; using System;
using System.Runtime.Serialization; using System.Runtime.Serialization;
namespace Microsoft.OpenApi.CSharpComment.Reader.Exceptions namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Exceptions
{ {
/// <summary> /// <summary>
/// The exception that is thrown when there is an undocumented generic type in the xml documentation. /// The exception that is thrown when there is an undocumented generic type in the xml documentation.

Просмотреть файл

@ -4,7 +4,7 @@
using System; using System;
using System.Runtime.Serialization; using System.Runtime.Serialization;
namespace Microsoft.OpenApi.CSharpComment.Reader.Exceptions namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Exceptions
{ {
/// <summary> /// <summary>
/// The exception that is thrown when there is an undocumented path parameter in the xml documentation. /// The exception that is thrown when there is an undocumented path parameter in the xml documentation.

Просмотреть файл

@ -4,7 +4,7 @@
using System; using System;
using System.Runtime.Serialization; using System.Runtime.Serialization;
namespace Microsoft.OpenApi.CSharpComment.Reader.Exceptions namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Exceptions
{ {
/// <summary> /// <summary>
/// The exception that is thrown when generic types are not documented in order in the xml documentation. /// 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;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; 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> /// <summary>
/// Extension methods for <see cref="IDictionary{TKey,TValue}"/>. /// Extension methods for <see cref="IDictionary{TKey,TValue}"/>.
@ -82,68 +78,6 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Extensions
!sourceDictionary.Except(targetDictionary).Any(); !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> /// <summary>
/// Converts <see cref="IDictionary{TKey, TValue}"/>where TKey is <see cref="string"/> /// 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"}. /// 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.Text.RegularExpressions;
using System.Web; using System.Web;
namespace Microsoft.OpenApi.CSharpComment.Reader.Extensions namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Extensions
{ {
/// <summary> /// <summary>
/// Extension methods for <see cref="string"/>. /// Extension methods for <see cref="string"/>.

Просмотреть файл

@ -9,7 +9,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
namespace Microsoft.OpenApi.CSharpComment.Reader.Extensions namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Extensions
{ {
/// <summary> /// <summary>
/// Extension methods for <see cref="Type"/>. /// Extension methods for <see cref="Type"/>.

Просмотреть файл

@ -4,9 +4,9 @@
using System.Text; using System.Text;
using System.Xml; using System.Xml;
using System.Xml.Linq; 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> /// <summary>
/// Extension methods for <see cref="XElement"/>. /// 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.Linq;
using System.Xml.Linq; using System.Xml.Linq;
using System.Xml.XPath; using System.Xml.XPath;
using Microsoft.OpenApi.CSharpComment.Reader.DocumentConfigFilters; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.DocumentConfigFilters;
using Microsoft.OpenApi.CSharpComment.Reader.DocumentFilters; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.DocumentFilters;
using Microsoft.OpenApi.CSharpComment.Reader.Exceptions; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Exceptions;
using Microsoft.OpenApi.CSharpComment.Reader.Extensions; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Extensions;
using Microsoft.OpenApi.CSharpComment.Reader.Models; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models;
using Microsoft.OpenApi.CSharpComment.Reader.OperationConfigFilters; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.OperationConfigFilters;
using Microsoft.OpenApi.CSharpComment.Reader.OperationFilters; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.OperationFilters;
using Microsoft.OpenApi.CSharpComment.Reader.PostProcessingDocumentFilters; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.PostProcessingDocumentFilters;
using Microsoft.OpenApi.CSharpComment.Reader.PreprocessingOperationFilters; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.PreprocessingOperationFilters;
using Microsoft.OpenApi.CSharpComment.Reader.ReferenceRegistries; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.ReferenceRegistries;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
namespace Microsoft.OpenApi.CSharpComment.Reader namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration
{ {
/// <summary> /// <summary>
/// Provides functionality to parse xml documentation and contract assemblies into OpenAPI documents. /// Provides functionality to parse xml documentation and contract assemblies into OpenAPI documents.
/// </summary> /// </summary>
internal class InternalOpenApiDocumentGenerator internal class InternalOpenApiGenerator
{ {
private readonly CSharpCommentOpenApiGeneratorFilterConfig _cSharpCommentOpenApiGeneratorFilterConfig; private readonly OpenApiGeneratorFilterConfig _openApiGeneratorFilterConfig;
/// <summary> /// <summary>
/// Creates a new instance of <see cref="InternalOpenApiDocumentGenerator"/>. /// Creates a new instance of <see cref="InternalOpenApiGenerator"/>.
/// </summary> /// </summary>
/// <param name="cSharpCommentOpenApiGeneratorFilterConfig">The configuration encapsulating all the filters /// <param name="openApiGeneratorFilterConfig">The configuration encapsulating all the filters
/// that will be applied while generating/processing OpenAPI document from C# comments.</param> /// that will be applied while generating/processing OpenAPI document from C# annotations.</param>
public InternalOpenApiDocumentGenerator( public InternalOpenApiGenerator(
CSharpCommentOpenApiGeneratorFilterConfig cSharpCommentOpenApiGeneratorFilterConfig) OpenApiGeneratorFilterConfig openApiGeneratorFilterConfig)
{ {
_cSharpCommentOpenApiGeneratorFilterConfig = cSharpCommentOpenApiGeneratorFilterConfig; _openApiGeneratorFilterConfig = openApiGeneratorFilterConfig;
} }
/// <summary> /// <summary>
@ -53,7 +53,7 @@ namespace Microsoft.OpenApi.CSharpComment.Reader
var paths = new OpenApiPaths(); var paths = new OpenApiPaths();
foreach (var preprocessingOperationFilter in foreach (var preprocessingOperationFilter in
_cSharpCommentOpenApiGeneratorFilterConfig.PreProcessingOperationFilters) _openApiGeneratorFilterConfig.PreProcessingOperationFilters)
{ {
try try
{ {
@ -100,7 +100,7 @@ namespace Microsoft.OpenApi.CSharpComment.Reader
// Apply all the operation-related filters to extract information related to the operation. // 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 // It is important that these are applied before the config filters below
// since the config filters may rely on information generated from operation filters. // 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 try
{ {
@ -125,7 +125,7 @@ namespace Microsoft.OpenApi.CSharpComment.Reader
{ {
// Apply the config-related filters to extract information from the config xml // Apply the config-related filters to extract information from the config xml
// that can be applied to the operations. // that can be applied to the operations.
foreach (var configFilter in _cSharpCommentOpenApiGeneratorFilterConfig.OperationConfigFilters) foreach (var configFilter in _openApiGeneratorFilterConfig.OperationConfigFilters)
{ {
try try
{ {
@ -135,7 +135,7 @@ namespace Microsoft.OpenApi.CSharpComment.Reader
new OperationConfigFilterSettings new OperationConfigFilterSettings
{ {
OperationFilterSettings = operationFilterSettings, OperationFilterSettings = operationFilterSettings,
OperationFilters = _cSharpCommentOpenApiGeneratorFilterConfig.OperationFilters OperationFilters = _openApiGeneratorFilterConfig.OperationFilters
}); });
} }
catch (Exception e) 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="annotationXmlDocuments">The list of XDocuments representing annotation xmls.</param>
/// <param name="contractAssemblyPaths">The contract assembly paths.</param> /// <param name="contractAssemblyPaths">The contract assembly paths.</param>
/// <param name="configurationXml">The serialized XDocument representing the generation configuration.</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="openApiDocumentVersion">The version of the OpenAPI document.</param>
/// <param name="openApiFormat">Format (YAML or JSON) of the OpenAPI document to generate.</param>
/// <param name="generationDiagnostic">A string representing serialized version of /// <param name="generationDiagnostic">A string representing serialized version of
/// <see cref="GenerationDiagnostic"/>> /// <see cref="GenerationDiagnostic"/>>
/// </param> /// </param>
/// <returns> /// <returns>
/// A string representing serialized version of <see cref="IDictionary{DocumentVariantInfo, OpenApiDocument}"/>> /// Dictionary mapping document variant metadata to their respective OpenAPI document.
/// </returns> /// </returns>
/// <remarks> public IDictionary<DocumentVariantInfo, OpenApiDocument> GenerateOpenApiDocuments(
/// 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(
IList<XDocument> annotationXmlDocuments, IList<XDocument> annotationXmlDocuments,
IList<string> contractAssemblyPaths, IList<string> contractAssemblyPaths,
string configurationXml, string configurationXml,
OpenApiSpecVersion openApiSpecVersion, string openApiDocumentVersion,
OpenApiFormat openApiFormat,
out GenerationDiagnostic generationDiagnostic) out GenerationDiagnostic generationDiagnostic)
{ {
IDictionary<DocumentVariantInfo, string> openApiDocuments = new Dictionary<DocumentVariantInfo, string>(); IDictionary<DocumentVariantInfo, OpenApiDocument> openApiDocuments
= new Dictionary<DocumentVariantInfo, OpenApiDocument>();
var operationElements = new List<XElement>(); var operationElements = new List<XElement>();
@ -298,7 +293,7 @@ namespace Microsoft.OpenApi.CSharpComment.Reader
{ {
var openApiDocument = variantInfoDocumentValuePair.Value; var openApiDocument = variantInfoDocumentValuePair.Value;
foreach (var documentFilter in _cSharpCommentOpenApiGeneratorFilterConfig.DocumentFilters) foreach (var documentFilter in _openApiGeneratorFilterConfig.DocumentFilters)
{ {
try try
{ {
@ -307,7 +302,8 @@ namespace Microsoft.OpenApi.CSharpComment.Reader
annotationXmlDocuments, annotationXmlDocuments,
new DocumentFilterSettings new DocumentFilterSettings
{ {
TypeFetcher = typeFetcher TypeFetcher = typeFetcher,
OpenApiDocumentVersion = openApiDocumentVersion
}); });
} }
catch (Exception e) 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) if (documentConfigElement != null)
{ {
foreach (var documentConfigFilter in foreach (var documentConfigFilter in
_cSharpCommentOpenApiGeneratorFilterConfig.DocumentConfigFilters) _openApiGeneratorFilterConfig.DocumentConfigFilters)
{ {
try try
{ {
@ -366,7 +372,7 @@ namespace Microsoft.OpenApi.CSharpComment.Reader
} }
generationDiagnostic.DocumentGenerationDiagnostic = documentGenerationDiagnostic; generationDiagnostic.DocumentGenerationDiagnostic = documentGenerationDiagnostic;
return documents.ToSerializedOpenApiDocuments(openApiSpecVersion, openApiFormat); return documents;
} }
catch (Exception e) catch (Exception e)
{ {
@ -532,16 +538,6 @@ namespace Microsoft.OpenApi.CSharpComment.Reader
referenceRegistryManagerMap[documentVariantInfo] referenceRegistryManagerMap[documentVariantInfo]
.SchemaReferenceRegistry.References.CopyInto( .SchemaReferenceRegistry.References.CopyInto(
specificationDocuments[documentVariantInfo].Components.Schemas); specificationDocuments[documentVariantInfo].Components.Schemas);
foreach (var filter in _cSharpCommentOpenApiGeneratorFilterConfig.PostProcessingDocumentFilters)
{
filter.Apply(
specificationDocuments[documentVariantInfo],
new PostProcessingDocumentFilterSettings()
{
OperationGenerationDiagnostics = operationGenerationResults
});
}
} }
return operationGenerationResults; return operationGenerationResults;

Просмотреть файл

@ -7,8 +7,8 @@
<ProjectGuid>{14D2C330-AAA0-4813-960F-BD3D46D6CE1D}</ProjectGuid> <ProjectGuid>{14D2C330-AAA0-4813-960F-BD3D46D6CE1D}</ProjectGuid>
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Microsoft.OpenApi.CSharpComment.Reader</RootNamespace> <RootNamespace>Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration</RootNamespace>
<AssemblyName>Microsoft.OpenApi.CSharpComment.Reader</AssemblyName> <AssemblyName>Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion> <TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<TargetFrameworkProfile /> <TargetFrameworkProfile />
@ -21,7 +21,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Debug\Microsoft.OpenApi.CSharpComment.Reader.xml</DocumentationFile> <DocumentationFile>bin\Debug\Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.xml</DocumentationFile>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
@ -30,7 +30,7 @@
<DefineConstants>TRACE</DefineConstants> <DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Release\Microsoft.OpenApi.CSharpComment.Reader.xml</DocumentationFile> <DocumentationFile>bin\Release\Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.xml</DocumentationFile>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Microsoft.OpenApi, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3f5743946376f042, processorArchitecture=MSIL"> <Reference Include="Microsoft.OpenApi, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3f5743946376f042, processorArchitecture=MSIL">
@ -53,8 +53,8 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="CSharpCommentOpenApiGeneratorConfig.cs" /> <Compile Include="OpenApiGeneratorConfig.cs" />
<Compile Include="CSharpCommentOpenApiGeneratorFilterConfig.cs" /> <Compile Include="OpenApiGeneratorFilterConfig.cs" />
<Compile Include="DocumentConfigFilters\DocumentVariantAttributesFilter.cs" /> <Compile Include="DocumentConfigFilters\DocumentVariantAttributesFilter.cs" />
<Compile Include="DocumentFilters\MemberSummaryToSchemaDescriptionFilter.cs" /> <Compile Include="DocumentFilters\MemberSummaryToSchemaDescriptionFilter.cs" />
<Compile Include="DocumentFilters\DocumentFilterSettings.cs" /> <Compile Include="DocumentFilters\DocumentFilterSettings.cs" />
@ -70,7 +70,7 @@
<Compile Include="DocumentConfigFilters\IDocumentConfigFilter.cs" /> <Compile Include="DocumentConfigFilters\IDocumentConfigFilter.cs" />
<Compile Include="DocumentConfigFilters\DocumentConfigFilterSettings.cs" /> <Compile Include="DocumentConfigFilters\DocumentConfigFilterSettings.cs" />
<Compile Include="Extensions\XElementExtensions.cs" /> <Compile Include="Extensions\XElementExtensions.cs" />
<Compile Include="ICSharpCommentOpenApiGenerator.cs" /> <Compile Include="IOpenApiGenerator.cs" />
<Compile Include="Models\GenerationError.cs" /> <Compile Include="Models\GenerationError.cs" />
<Compile Include="Models\DocumentGenerationDiagnostic.cs" /> <Compile Include="Models\DocumentGenerationDiagnostic.cs" />
<Compile Include="OperationConfigFilters\CommonAnnotationFilter.cs" /> <Compile Include="OperationConfigFilters\CommonAnnotationFilter.cs" />
@ -106,7 +106,7 @@
<Compile Include="Exceptions\DocumentationException.cs" /> <Compile Include="Exceptions\DocumentationException.cs" />
<Compile Include="Exceptions\MissingInAttributeException.cs" /> <Compile Include="Exceptions\MissingInAttributeException.cs" />
<Compile Include="Extensions\DictionaryExtensions.cs" /> <Compile Include="Extensions\DictionaryExtensions.cs" />
<Compile Include="InternalOpenApiDocumentGenerator.cs" /> <Compile Include="InternalOpenApiGenerator.cs" />
<Compile Include="Models\GenerationDiagnostic.cs" /> <Compile Include="Models\GenerationDiagnostic.cs" />
<Compile Include="Models\OperationGenerationDiagnostic.cs" /> <Compile Include="Models\OperationGenerationDiagnostic.cs" />
<Compile Include="ReferenceRegistries\ParameterReferenceRegistry.cs" /> <Compile Include="ReferenceRegistries\ParameterReferenceRegistry.cs" />
@ -114,13 +114,13 @@
<Compile Include="ReferenceRegistries\SchemaReferenceRegistry.cs" /> <Compile Include="ReferenceRegistries\SchemaReferenceRegistry.cs" />
<Compile Include="ReferenceRegistries\ReferenceRegistryManager.cs" /> <Compile Include="ReferenceRegistries\ReferenceRegistryManager.cs" />
<Compile Include="ReferenceRegistries\ReferenceRegistry.cs" /> <Compile Include="ReferenceRegistries\ReferenceRegistry.cs" />
<Compile Include="CSharpCommentOpenApiGenerator.cs" /> <Compile Include="OpenApiGenerator.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SpecificationGenerationMessages.cs" /> <Compile Include="SpecificationGenerationMessages.cs" />
<Compile Include="Extensions\TypeExtensions.cs" /> <Compile Include="Extensions\TypeExtensions.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="Microsoft.OpenApi.CSharpComment.Reader.nuspec" /> <None Include="Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.nuspec" />
<None Include="packages.config"> <None Include="packages.config">
<SubType>Designer</SubType> <SubType>Designer</SubType>
</None> </None>

Просмотреть файл

@ -1,13 +1,13 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"> <package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata> <metadata>
<id>Microsoft.OpenApi.CSharpComment.Reader</id> <id>Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration</id>
<version>1.0.0-beta019</version> <version>1.0.0-beta020</version>
<authors>Microsoft</authors> <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> <dependencies>
<dependency id="Microsoft.OpenApi" version="1.0.0-beta014"/> <dependency id="Microsoft.OpenApi" version="1.0.0-beta015"/>
<dependency id="Microsoft.OpenApi.Readers" version="1.0.0-beta014"/> <dependency id="Microsoft.OpenApi.Readers" version="1.0.0-beta015"/>
</dependencies> </dependencies>
</metadata> </metadata>
</package> </package>

Просмотреть файл

@ -5,7 +5,7 @@
using System.Collections.Generic; using System.Collections.Generic;
namespace Microsoft.OpenApi.CSharpComment.Reader.Models namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models
{ {
/// <summary> /// <summary>
/// Object containing all diagnostic information related to document-level of generation process. /// Object containing all diagnostic information related to document-level of generation process.

Просмотреть файл

@ -4,9 +4,9 @@
// ------------------------------------------------------------ // ------------------------------------------------------------
using System.Collections.Generic; 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> /// <summary>
/// Class encapsulating information for a variant of a document. /// Class encapsulating information for a variant of a document.

Просмотреть файл

@ -5,7 +5,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using Microsoft.OpenApi.Readers.Interface; using Microsoft.OpenApi.Readers.Interface;
namespace Microsoft.OpenApi.CSharpComment.Reader.Models namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models
{ {
/// <summary> /// <summary>
/// Object coining all diagnostic information related to OpenApi document generation. /// 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. // 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> /// <summary>
/// Model representing the generation error for the operation. /// 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. // 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 Annotation = "annotation";
public const string Body = "body"; public const string Body = "body";

Просмотреть файл

@ -5,7 +5,7 @@
using System.Collections.Generic; using System.Collections.Generic;
namespace Microsoft.OpenApi.CSharpComment.Reader.Models namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models
{ {
/// <summary> /// <summary>
/// Object containing all diagnostic information related to operation-level of generation process. /// 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.Collections.Generic;
using System.Xml.Linq; using System.Xml.Linq;
namespace Microsoft.OpenApi.CSharpComment.Reader namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration
{ {
/// <summary> /// <summary>
/// The class to store the configuration that will be used to generate the OpenAPI document from csharp /// The class to store the configuration that will be used to generate the OpenAPI document from csharp
/// documentation. /// documentation.
/// </summary> /// </summary>
public class CSharpCommentOpenApiGeneratorConfig public class OpenApiGeneratorConfig
{ {
/// <summary> /// <summary>
/// Creates a new instance of <see cref="CSharpCommentOpenApiGeneratorConfig"/>. /// Creates a new instance of <see cref="OpenApiGeneratorConfig"/>.
/// </summary> /// </summary>
/// <param name="annotationXmlDocuments">The XDocuments representing the annotation xmls.</param> /// <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 /// <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. /// reflect into the types provided in the xml.
/// </param> /// </param>
/// <param name="openApiSpecificationVersion">The specification version of the OpenAPI document to generate. /// <param name="openApiDocumentVersion">The version of the OpenAPI document.</param>
/// </param> public OpenApiGeneratorConfig(
public CSharpCommentOpenApiGeneratorConfig(
IList<XDocument> annotationXmlDocuments, IList<XDocument> annotationXmlDocuments,
IList<string> assemblyPaths, IList<string> assemblyPaths,
OpenApiSpecVersion openApiSpecificationVersion) string openApiDocumentVersion)
: this( : this(
annotationXmlDocuments, annotationXmlDocuments,
assemblyPaths, assemblyPaths,
openApiSpecificationVersion, openApiDocumentVersion,
new CSharpCommentOpenApiGeneratorFilterConfig()) new OpenApiGeneratorFilterConfig())
{ {
} }
/// <summary> /// <summary>
/// Creates a new instance of <see cref="CSharpCommentOpenApiGeneratorConfig"/>. /// Creates a new instance of <see cref="OpenApiGeneratorConfig"/>.
/// </summary> /// </summary>
/// <param name="annotationXmlDocuments">The XDocuments representing the annotation xmls.</param> /// <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 /// <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. /// reflect into the types provided in the xml.
/// </param> /// </param>
/// <param name="openApiSpecificationVersion">The specification version of the OpenAPI document to generate. /// <param name="openApiDocumentVersion">The version of the OpenAPI document.</param>
/// </param> /// <param name="openApiGeneratorFilterConfig">The configuration encapsulating all the filters
/// <param name="cSharpCommentOpenApiGeneratorFilterConfig">The configuration encapsulating all the filters /// that will be applied while generating/processing OpenAPI document from C# annotations.</param>
/// that will be applied while generating/processing OpenAPI document from C# comments.</param> public OpenApiGeneratorConfig(
public CSharpCommentOpenApiGeneratorConfig(
IList<XDocument> annotationXmlDocuments, IList<XDocument> annotationXmlDocuments,
IList<string> assemblyPaths, IList<string> assemblyPaths,
OpenApiSpecVersion openApiSpecificationVersion, string openApiDocumentVersion,
CSharpCommentOpenApiGeneratorFilterConfig cSharpCommentOpenApiGeneratorFilterConfig ) OpenApiGeneratorFilterConfig openApiGeneratorFilterConfig)
{ {
AnnotationXmlDocuments = annotationXmlDocuments AnnotationXmlDocuments = annotationXmlDocuments
?? throw new ArgumentNullException(nameof(annotationXmlDocuments)); ?? throw new ArgumentNullException(nameof(annotationXmlDocuments));
@ -57,10 +55,15 @@ namespace Microsoft.OpenApi.CSharpComment.Reader
AssemblyPaths = assemblyPaths AssemblyPaths = assemblyPaths
?? throw new ArgumentNullException(nameof(assemblyPaths)); ?? throw new ArgumentNullException(nameof(assemblyPaths));
CSharpCommentOpenApiGeneratorFilterConfig = cSharpCommentOpenApiGeneratorFilterConfig OpenApiGeneratorFilterConfig = openApiGeneratorFilterConfig
?? throw new ArgumentNullException(nameof(cSharpCommentOpenApiGeneratorFilterConfig)); ?? throw new ArgumentNullException(nameof(openApiGeneratorFilterConfig));
OpenApiSpecificationVersion = openApiSpecificationVersion; if (string.IsNullOrWhiteSpace(openApiDocumentVersion))
{
throw new ArgumentNullException(nameof(openApiDocumentVersion));
}
OpenApiDocumentVersion = openApiDocumentVersion;
} }
/// <summary> /// <summary>
@ -79,20 +82,15 @@ namespace Microsoft.OpenApi.CSharpComment.Reader
/// </summary> /// </summary>
public IList<string> AssemblyPaths { get; } public IList<string> AssemblyPaths { get; }
/// <summary>
/// The version of the OpenAPI document.
/// </summary>
public string OpenApiDocumentVersion { get; }
/// <summary> /// <summary>
/// The configuration encapsulating all the filters that will be applied while generating/processing OpenAPI /// The configuration encapsulating all the filters that will be applied while generating/processing OpenAPI
/// document from C# comments. /// document from C# annotations.
/// </summary> /// </summary>
public CSharpCommentOpenApiGeneratorFilterConfig CSharpCommentOpenApiGeneratorFilterConfig { get; } public OpenApiGeneratorFilterConfig OpenApiGeneratorFilterConfig { 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; }
} }
} }

Просмотреть файл

@ -4,20 +4,20 @@
using System; using System;
using System.Linq; using System.Linq;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.OpenApi.CSharpComment.Reader.DocumentConfigFilters; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.DocumentConfigFilters;
using Microsoft.OpenApi.CSharpComment.Reader.DocumentFilters; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.DocumentFilters;
using Microsoft.OpenApi.CSharpComment.Reader.OperationConfigFilters; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.OperationConfigFilters;
using Microsoft.OpenApi.CSharpComment.Reader.OperationFilters; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.OperationFilters;
using Microsoft.OpenApi.CSharpComment.Reader.PostProcessingDocumentFilters; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.PostProcessingDocumentFilters;
using Microsoft.OpenApi.CSharpComment.Reader.PreprocessingOperationFilters; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.PreprocessingOperationFilters;
namespace Microsoft.OpenApi.CSharpComment.Reader namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration
{ {
/// <summary> /// <summary>
/// The class encapsulating all the filters that will be applied while generating/processing OpenAPI document from /// The class encapsulating all the filters that will be applied while generating/processing OpenAPI document from
/// C# comments. /// C# annotations.
/// </summary> /// </summary>
public class CSharpCommentOpenApiGeneratorFilterConfig public class OpenApiGeneratorFilterConfig
{ {
/// <summary> /// <summary>
/// List of default document config filters. /// List of default document config filters.
@ -83,9 +83,9 @@ namespace Microsoft.OpenApi.CSharpComment.Reader
}; };
/// <summary> /// <summary>
/// Creates a new instance of <see cref="CSharpCommentOpenApiGeneratorFilterConfig"/> with default filters. /// Creates a new instance of <see cref="OpenApiGeneratorFilterConfig"/> with default filters.
/// </summary> /// </summary>
public CSharpCommentOpenApiGeneratorFilterConfig() public OpenApiGeneratorFilterConfig()
: this( : this(
DefaultDocumentFilters.ToList(), DefaultDocumentFilters.ToList(),
DefaultOperationFilters.ToList(), DefaultOperationFilters.ToList(),
@ -97,7 +97,7 @@ namespace Microsoft.OpenApi.CSharpComment.Reader
} }
/// <summary> /// <summary>
/// Creates a new instance of <see cref="CSharpCommentOpenApiGeneratorFilterConfig"/> with provided filters. /// Creates a new instance of <see cref="OpenApiGeneratorFilterConfig"/> with provided filters.
/// </summary> /// </summary>
/// <param name="documentFilters">The list of document filters.</param> /// <param name="documentFilters">The list of document filters.</param>
/// <param name="operationFilters">The list of operation 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="documentConfigFilters">The list of document config filters.</param>
/// <param name="postProcessingDocumentFilters">The list of post processing document filters.</param> /// <param name="postProcessingDocumentFilters">The list of post processing document filters.</param>
/// <param name="preProcessingOperationFilters">The list of pre processing operation filters.</param> /// <param name="preProcessingOperationFilters">The list of pre processing operation filters.</param>
public CSharpCommentOpenApiGeneratorFilterConfig( public OpenApiGeneratorFilterConfig(
IList<IDocumentFilter> documentFilters, IList<IDocumentFilter> documentFilters,
IList<IOperationFilter> operationFilters, IList<IOperationFilter> operationFilters,
IList<IOperationConfigFilter> operationConfigFilters, IList<IOperationConfigFilter> operationConfigFilters,

Просмотреть файл

@ -6,10 +6,10 @@
using System; using System;
using System.Linq; using System.Linq;
using System.Xml.Linq; using System.Xml.Linq;
using Microsoft.OpenApi.CSharpComment.Reader.Models.KnownStrings; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models.KnownStrings;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
namespace Microsoft.OpenApi.CSharpComment.Reader.OperationConfigFilters namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.OperationConfigFilters
{ {
/// <summary> /// <summary>
/// Parses the value of the annotation nodes in operation-level config and applies them to the specified operations. /// 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 System.Xml.Linq;
using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.OperationFilters;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
namespace Microsoft.OpenApi.CSharpComment.Reader.OperationConfigFilters namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.OperationConfigFilters
{ {
/// <summary> /// <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> /// </summary>
public interface IOperationConfigFilter public interface IOperationConfigFilter
{ {
@ -18,8 +22,10 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.OperationConfigFilters
/// in the operation config element. /// in the operation config element.
/// </summary> /// </summary>
/// <param name="operation">The operation to be updated.</param> /// <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="element">The xml element containing operation-level config in the config xml,
/// <param name="settings">The operation config filter settings.</param> /// <see cref="OpenApiGeneratorConfig.AdvancedConfigurationXmlDocument"/>.
/// </param>
/// <param name="settings"><see cref="OperationConfigFilterSettings"/></param>
void Apply(OpenApiOperation operation, XElement element, OperationConfigFilterSettings settings); void Apply(OpenApiOperation operation, XElement element, OperationConfigFilterSettings settings);
} }
} }

Просмотреть файл

@ -4,9 +4,9 @@
// ------------------------------------------------------------ // ------------------------------------------------------------
using System.Collections.Generic; 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> /// <summary>
/// Settings for <see cref="IOperationConfigFilter"/>. /// Settings for <see cref="IOperationConfigFilter"/>.

Просмотреть файл

@ -6,10 +6,10 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Xml.Linq; using System.Xml.Linq;
using Microsoft.OpenApi.CSharpComment.Reader.Models.KnownStrings; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models.KnownStrings;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
namespace Microsoft.OpenApi.CSharpComment.Reader.OperationFilters namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.OperationFilters
{ {
/// <summary> /// <summary>
/// Parses the value of group tag in xml documentation and apply that as tag in operation. /// 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 System.Xml.Linq;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
namespace Microsoft.OpenApi.CSharpComment.Reader.OperationFilters namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.OperationFilters
{ {
/// <summary> /// <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> /// </summary>
public interface IOperationFilter public interface IOperationFilter
{ {
/// <summary> /// <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> /// </summary>
/// <param name="operation">The operation to be upated.</param> /// <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="element">The xml element representing an operation in the annotation xmls provided in
/// <param name="settings">The operation filter settings.</param> /// <see cref="OpenApiGeneratorConfig.AnnotationXmlDocuments"/>.</param>
/// <param name="settings"><see cref="OperationFilterSettings"/></param>
/// <remarks> /// <remarks>
/// Care should be taken to not overwrite the existing value in Operation if already present. /// 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. /// 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. // 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> /// <summary>
/// Settings for <see cref="IOperationFilter"/>. /// Settings for <see cref="IOperationFilter"/>.

Просмотреть файл

@ -6,12 +6,13 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Xml;
using System.Xml.Linq; using System.Xml.Linq;
using Microsoft.OpenApi.CSharpComment.Reader.Extensions; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Extensions;
using Microsoft.OpenApi.CSharpComment.Reader.Models.KnownStrings; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models.KnownStrings;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
namespace Microsoft.OpenApi.CSharpComment.Reader.OperationFilters namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.OperationFilters
{ {
/// <summary> /// <summary>
/// Parses the value of param tag in xml documentation and apply that as parameter in operation. /// 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 isRequired = paramElement.Attribute(KnownXmlStrings.Required)?.Value.Trim();
var cref = paramElement.Attribute(KnownXmlStrings.Cref)?.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); var parameterLocation = GetParameterKind(inValue);
operation.Parameters.Add( operation.Parameters.Add(
@ -77,19 +100,19 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.OperationFilters
} }
/// <summary> /// <summary>
/// Generates schema from type name in cref. /// Generates schema from type names in cref.
/// </summary> /// </summary>
/// <returns> /// <returns>
/// Schema from type in cref if the type is resolvable. /// Schema from type in cref if the type is resolvable.
/// Otherwise, default to schema for string type. /// Otherwise, default to schema for string type.
/// </returns> /// </returns>
private static OpenApiSchema GenerateSchemaFromCref(string cref, OperationFilterSettings settings) private static OpenApiSchema GenerateSchemaFromCref(IList<string> crefValues, OperationFilterSettings settings)
{ {
var type = typeof(string); 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); 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. // Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------ // ------------------------------------------------------------
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Xml; using System.Xml;
using System.Xml.Linq; using System.Xml.Linq;
using Microsoft.OpenApi.CSharpComment.Reader.Exceptions; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Exceptions;
using Microsoft.OpenApi.CSharpComment.Reader.Extensions; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Extensions;
using Microsoft.OpenApi.CSharpComment.Reader.Models.KnownStrings; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models.KnownStrings;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
namespace Microsoft.OpenApi.CSharpComment.Reader.OperationFilters namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.OperationFilters
{ {
/// <summary> /// <summary>
/// Parses the value of param tag in xml documentation and apply that as request body in operation. /// 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(); description = lastNode.ToString();
} }
var allListedTypes = new List<string>();
var seeNodes = bodyElement.Descendants(KnownXmlStrings.See); var seeNodes = bodyElement.Descendants(KnownXmlStrings.See);
foreach (var node in seeNodes) var allListedTypes = seeNodes
{ .Select(node => node.Attribute(KnownXmlStrings.Cref)?.Value)
var crefValue = node.Attribute(KnownXmlStrings.Cref)?.Value; .Where(crefValue => crefValue != null).ToList();
if (crefValue != null)
{
allListedTypes.Add(crefValue);
}
}
if (!allListedTypes.Any()) if (!allListedTypes.Any())
{ {

Просмотреть файл

@ -5,11 +5,11 @@
using System.Linq; using System.Linq;
using System.Xml.Linq; using System.Xml.Linq;
using Microsoft.OpenApi.CSharpComment.Reader.Extensions; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Extensions;
using Microsoft.OpenApi.CSharpComment.Reader.Models.KnownStrings; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models.KnownStrings;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
namespace Microsoft.OpenApi.CSharpComment.Reader.OperationFilters namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.OperationFilters
{ {
/// <summary> /// <summary>
/// Parses the value of remarks tag in xml documentation and apply that as description of the operation. /// 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. // Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------ // ------------------------------------------------------------
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Xml; using System.Xml;
using System.Xml.Linq; using System.Xml.Linq;
using Microsoft.OpenApi.CSharpComment.Reader.Exceptions; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Exceptions;
using Microsoft.OpenApi.CSharpComment.Reader.Extensions; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Extensions;
using Microsoft.OpenApi.CSharpComment.Reader.Models.KnownStrings; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models.KnownStrings;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
namespace Microsoft.OpenApi.CSharpComment.Reader.OperationFilters namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.OperationFilters
{ {
/// <summary> /// <summary>
/// Parses the value of response tag in xml documentation and apply that as response in operation. /// 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); throw new MissingResponseDescriptionException(code);
} }
var allListedTypes = new List<string>();
var seeNodes = responseElement.Descendants(KnownXmlStrings.See); var seeNodes = responseElement.Descendants(KnownXmlStrings.See);
foreach (var node in seeNodes) var allListedTypes = seeNodes
{ .Select(node => node.Attribute(KnownXmlStrings.Cref)?.Value)
var crefValue = node.Attribute(KnownXmlStrings.Cref)?.Value; .Where(crefValue => crefValue != null).ToList();
if (crefValue != null)
{
allListedTypes.Add(crefValue);
}
}
OpenApiSchema schema = null; OpenApiSchema schema = null;

Просмотреть файл

@ -5,11 +5,11 @@
using System.Linq; using System.Linq;
using System.Xml.Linq; using System.Xml.Linq;
using Microsoft.OpenApi.CSharpComment.Reader.Extensions; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Extensions;
using Microsoft.OpenApi.CSharpComment.Reader.Models.KnownStrings; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models.KnownStrings;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
namespace Microsoft.OpenApi.CSharpComment.Reader.OperationFilters namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.OperationFilters
{ {
/// <summary> /// <summary>
/// Parses the value of summary tag in xml documentation and apply that as summary of the operation. /// 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.Text.RegularExpressions;
using System.Web; using System.Web;
using System.Xml.Linq; using System.Xml.Linq;
using Microsoft.OpenApi.CSharpComment.Reader.Exceptions; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Exceptions;
using Microsoft.OpenApi.CSharpComment.Reader.Extensions; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Extensions;
using Microsoft.OpenApi.CSharpComment.Reader.Models.KnownStrings; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models.KnownStrings;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
namespace Microsoft.OpenApi.CSharpComment.Reader namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration
{ {
internal static class OperationHandler internal static class OperationHandler
{ {

Просмотреть файл

@ -3,11 +3,11 @@
// Licensed under the MIT License (MIT). See License.txt in the repo root for license information. // 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.CSharpAnnotations.DocumentGeneration.DocumentFilters;
using Microsoft.OpenApi.CSharpComment.Reader.OperationFilters; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.OperationFilters;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
namespace Microsoft.OpenApi.CSharpComment.Reader.PostProcessingDocumentFilters namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.PostProcessingDocumentFilters
{ {
/// <summary> /// <summary>
/// The class representing the contract of a filter to post process the <see cref="OpenApiDocument"/> /// 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"/>. /// Applies the filter to post process the <see cref="OpenApiDocument"/>.
/// </summary> /// </summary>
/// <param name="openApiDocument">The OpenAPI document to process.</param> /// <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( void Apply(
OpenApiDocument openApiDocument, OpenApiDocument openApiDocument,
PostProcessingDocumentFilterSettings settings); PostProcessingDocumentFilterSettings settings);

Просмотреть файл

@ -3,10 +3,10 @@
// Licensed under the MIT License (MIT). See License.txt in the repo root for license information. // 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; using System.Collections.Generic;
namespace Microsoft.OpenApi.CSharpComment.Reader.PostProcessingDocumentFilters namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.PostProcessingDocumentFilters
{ {
/// <summary> /// <summary>
/// Settings for <see cref="IPostProcessingDocumentFilter"/>. /// Settings for <see cref="IPostProcessingDocumentFilter"/>.

Просмотреть файл

@ -7,7 +7,7 @@ using System;
using System.Linq; using System.Linq;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
namespace Microsoft.OpenApi.CSharpComment.Reader.PostProcessingDocumentFilters namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.PostProcessingDocumentFilters
{ {
/// <summary> /// <summary>
/// Removes the operations from the OpenAPI document for which generation failed. /// Removes the operations from the OpenAPI document for which generation failed.

Просмотреть файл

@ -8,12 +8,11 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Xml.Linq; using System.Xml.Linq;
using Microsoft.OpenApi.CSharpComment.Reader.Exceptions; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Extensions;
using Microsoft.OpenApi.CSharpComment.Reader.Extensions; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models.KnownStrings;
using Microsoft.OpenApi.CSharpComment.Reader.Models.KnownStrings;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
namespace Microsoft.OpenApi.CSharpComment.Reader.PreprocessingOperationFilters namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.PreprocessingOperationFilters
{ {
/// <summary> /// <summary>
/// Parses the value of the URL and creates multiple operations in the Paths object when /// Parses the value of the URL and creates multiple operations in the Paths object when

Просмотреть файл

@ -5,10 +5,10 @@
using System.Linq; using System.Linq;
using System.Xml.Linq; using System.Xml.Linq;
using Microsoft.OpenApi.CSharpComment.Reader.Models.KnownStrings; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models.KnownStrings;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
namespace Microsoft.OpenApi.CSharpComment.Reader.PreprocessingOperationFilters namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.PreprocessingOperationFilters
{ {
/// <summary> /// <summary>
/// Converts the alternative param tags (queryParam, pathParam, header) to standard param tags. /// Converts the alternative param tags (queryParam, pathParam, header) to standard param tags.

Просмотреть файл

@ -4,10 +4,10 @@
// ------------------------------------------------------------ // ------------------------------------------------------------
using System.Xml.Linq; using System.Xml.Linq;
using Microsoft.OpenApi.CSharpComment.Reader.OperationFilters; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.OperationFilters;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
namespace Microsoft.OpenApi.CSharpComment.Reader.PreprocessingOperationFilters namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.PreprocessingOperationFilters
{ {
/// <summary> /// <summary>
/// The class representing the contract of a filter to preprocess the <see cref="OpenApiOperation"/> /// 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"/>. /// <see cref="IOperationFilter"/>.
/// </summary> /// </summary>
/// <param name="paths">The paths to be upated.</param> /// <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="element">The xml element representing an operation in the annotation xmls provided in
/// <param name="settings">The operation filter settings.</param> /// <see cref="OpenApiGeneratorConfig.AnnotationXmlDocuments"/>.
/// </param>
/// <param name="settings"><see cref="PreProcessingOperationFilterSettings"/></param>
void Apply(OpenApiPaths paths, XElement element, PreProcessingOperationFilterSettings settings); void Apply(OpenApiPaths paths, XElement element, PreProcessingOperationFilterSettings settings);
} }
} }

Просмотреть файл

@ -7,12 +7,12 @@ using System;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Xml.Linq; using System.Xml.Linq;
using Microsoft.OpenApi.CSharpComment.Reader.Exceptions; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Exceptions;
using Microsoft.OpenApi.CSharpComment.Reader.Extensions; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Extensions;
using Microsoft.OpenApi.CSharpComment.Reader.Models.KnownStrings; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Models.KnownStrings;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
namespace Microsoft.OpenApi.CSharpComment.Reader.PreprocessingOperationFilters namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.PreprocessingOperationFilters
{ {
/// <summary> /// <summary>
/// Parses the URL to populate the in attribute of the param tags if not explicitly documented. /// 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. // 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> /// <summary>
/// Settings for <see cref="IPreProcessingOperationFilter"/>. /// Settings for <see cref="IPreProcessingOperationFilter"/>.

Просмотреть файл

@ -11,11 +11,11 @@ using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following // General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information // set of attributes. Change these attribute values to modify the information
// associated with an assembly. // associated with an assembly.
[assembly: AssemblyTitle("Microsoft.OpenApi.CSharpComment.Reader")] [assembly: AssemblyTitle("Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration")]
[assembly: AssemblyDescription("")] [assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")] [assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")] [assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Microsoft.OpenApi.CSharpComment.Reader")] [assembly: AssemblyProduct("Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration")]
[assembly: AssemblyCopyright("Copyright © Microsoft")] [assembly: AssemblyCopyright("Copyright © Microsoft")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]
@ -42,4 +42,4 @@ using System.Runtime.InteropServices;
[assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: CLSCompliant(false)] [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 System.Collections.Generic;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
namespace Microsoft.OpenApi.CSharpComment.Reader.ReferenceRegistries namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.ReferenceRegistries
{ {
/// <summary> /// <summary>
/// Reference Registry for <see cref="OpenApiExample"/> /// Reference Registry for <see cref="OpenApiExample"/>

Просмотреть файл

@ -7,7 +7,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
namespace Microsoft.OpenApi.CSharpComment.Reader.ReferenceRegistries namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.ReferenceRegistries
{ {
/// <summary> /// <summary>
/// Reference Registry for <see cref="OpenApiParameter"/> /// Reference Registry for <see cref="OpenApiParameter"/>

Просмотреть файл

@ -6,7 +6,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Interfaces;
namespace Microsoft.OpenApi.CSharpComment.Reader.ReferenceRegistries namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.ReferenceRegistries
{ {
/// <summary> /// <summary>
/// Reference Registry for an <see cref="IOpenApiReferenceable"/> class. /// Reference Registry for an <see cref="IOpenApiReferenceable"/> class.

Просмотреть файл

@ -7,7 +7,7 @@ using System;
using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
namespace Microsoft.OpenApi.CSharpComment.Reader.ReferenceRegistries namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.ReferenceRegistries
{ {
/// <summary> /// <summary>
/// A class encapsulating reference registries for all <see cref="IOpenApiReferenceable"/> types. /// A class encapsulating reference registries for all <see cref="IOpenApiReferenceable"/> types.

Просмотреть файл

@ -6,11 +6,11 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.CSharpComment.Reader.Exceptions; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Exceptions;
using Microsoft.OpenApi.CSharpComment.Reader.Extensions; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Extensions;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
namespace Microsoft.OpenApi.CSharpComment.Reader.ReferenceRegistries namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.ReferenceRegistries
{ {
/// <summary> /// <summary>
/// Reference Registry for <see cref="OpenApiSchema"/> /// 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. // 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> /// <summary>
/// Holds the specification generation messages. /// Holds the specification generation messages.

Просмотреть файл

@ -9,10 +9,10 @@ using System.Globalization;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using Microsoft.OpenApi.CSharpComment.Reader.Exceptions; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Exceptions;
using Microsoft.OpenApi.CSharpComment.Reader.Extensions; using Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Extensions;
namespace Microsoft.OpenApi.CSharpComment.Reader namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration
{ {
/// <summary> /// <summary>
/// Proxy class for fetching type information by loading assemblies into private AppDomain. /// 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; using Newtonsoft.Json;
namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.Contracts
{ {
/// <summary> /// <summary>
/// Interface Sample Object 4 /// Interface Sample Object 4

Просмотреть файл

@ -7,8 +7,8 @@
<ProjectGuid>{62A36B02-A531-48ED-B4CF-3696A5C28B65}</ProjectGuid> <ProjectGuid>{62A36B02-A531-48ED-B4CF-3696A5C28B65}</ProjectGuid>
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts</RootNamespace> <RootNamespace>Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.Contracts</RootNamespace>
<AssemblyName>Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts</AssemblyName> <AssemblyName>Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.Contracts</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion> <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
</PropertyGroup> </PropertyGroup>
@ -20,7 +20,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <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>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
@ -29,7 +29,7 @@
<DefineConstants>TRACE</DefineConstants> <DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <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> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> <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 // General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information // set of attributes. Change these attribute values to modify the information
// associated with an assembly. // associated with an assembly.
[assembly: AssemblyTitle("Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts")] [assembly: AssemblyTitle("Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.Contracts")]
[assembly: AssemblyDescription("")] [assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")] [assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")] [assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts")] [assembly: AssemblyProduct("Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.Contracts")]
[assembly: AssemblyCopyright("Copyright © 2018")] [assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]

Просмотреть файл

@ -3,7 +3,7 @@
// Licensed under the MIT License (MIT). See License.txt in the repo root for license information. // 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> /// <summary>
/// Sample enum 1 /// Sample enum 1

Просмотреть файл

@ -5,7 +5,7 @@
using Newtonsoft.Json; using Newtonsoft.Json;
namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.Contracts
{ {
/// <summary> /// <summary>
/// Sample contract for object 1 /// Sample contract for object 1

Просмотреть файл

@ -6,7 +6,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.Contracts
{ {
/// <summary> /// <summary>
/// Sample contract for object 2 /// Sample contract for object 2

Просмотреть файл

@ -6,7 +6,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.Contracts
{ {
/// <summary> /// <summary>
/// Sample contract for object 3 /// Sample contract for object 3
@ -24,5 +24,11 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts
/// </summary> /// </summary>
[JsonProperty(PropertyName = "samplePropertyObjectList", Required = Required.Default)] [JsonProperty(PropertyName = "samplePropertyObjectList", Required = Required.Default)]
public IList<SampleObject1> SamplePropertyObjectList { get; } = new List<SampleObject1>(); 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 System.Collections.Generic;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.Contracts
{ {
/// <summary> /// <summary>
/// Sample contract for object 4 /// Sample contract for object 4

Просмотреть файл

@ -6,7 +6,7 @@
using System.Web.Mvc; using System.Web.Mvc;
using System.Web.Routing; using System.Web.Routing;
namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.SampleApis namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.SampleApis
{ {
/// <summary> /// <summary>
/// Responsible for route configuration /// Responsible for route configuration

Просмотреть файл

@ -5,7 +5,7 @@
using System.Web.Http; using System.Web.Http;
namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.SampleApis namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.SampleApis
{ {
/// <summary> /// <summary>
/// Web config. /// Web config.

Просмотреть файл

@ -6,9 +6,9 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Web.Http; 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> /// <summary>
/// Define V1 operations. /// Define V1 operations.

Просмотреть файл

@ -7,9 +7,9 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Web.Http; 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> /// <summary>
/// Defines V2 operations. /// Defines V2 operations.

Просмотреть файл

@ -7,9 +7,9 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Web.Http; 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> /// <summary>
/// Defines V3 operations. /// Defines V3 operations.

Просмотреть файл

@ -7,9 +7,9 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Web.Http; 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> /// <summary>
/// Defines V4 operations. /// 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.Mvc;
using System.Web.Routing; using System.Web.Routing;
namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.SampleApis namespace Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.SampleApis
{ {
/// <summary> /// <summary>
/// Web API Application. /// Web API Application.

Просмотреть файл

@ -11,8 +11,8 @@
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids> <ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Microsoft.OpenApi.CSharpComment.Reader.Tests.SampleApis</RootNamespace> <RootNamespace>Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.SampleApis</RootNamespace>
<AssemblyName>Microsoft.OpenApi.CSharpComment.Reader.Tests.SampleApis</AssemblyName> <AssemblyName>Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.SampleApis</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion> <TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<MvcBuildViews>false</MvcBuildViews> <MvcBuildViews>false</MvcBuildViews>
<UseIISExpress>true</UseIISExpress> <UseIISExpress>true</UseIISExpress>
@ -34,7 +34,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <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>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
@ -44,7 +44,7 @@
<DefineConstants>TRACE</DefineConstants> <DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <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>
<ItemGroup> <ItemGroup>
<Reference Include="Microsoft.CSharp" /> <Reference Include="Microsoft.CSharp" />
@ -142,9 +142,9 @@
</None> </None>
</ItemGroup> </ItemGroup>
<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> <Project>{62a36b02-a531-48ed-b4cf-3696a5c28b65}</Project>
<Name>Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts</Name> <Name>Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.Contracts</Name>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<PropertyGroup> <PropertyGroup>

Просмотреть файл

@ -9,11 +9,11 @@ using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following // General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information // set of attributes. Change these attribute values to modify the information
// associated with an assembly. // associated with an assembly.
[assembly: AssemblyTitle("Microsoft.OpenApi.CSharpComment.Reader.Tests.SampleApis")] [assembly: AssemblyTitle("Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.SampleApis")]
[assembly: AssemblyDescription("")] [assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")] [assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")] [assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Microsoft.OpenApi.CSharpComment.Reader.Tests.SampleApis")] [assembly: AssemblyProduct("Microsoft.OpenApi.CSharpAnnotations.DocumentGeneration.Tests.SampleApis")]
[assembly: AssemblyCopyright("Copyright © 2017")] [assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше