FixIssues71-68 (#80)
- Accept open api document version as input - Remove OpenApiSpecVersion from input
This commit is contained in:
Родитель
49a91e09bc
Коммит
8311ca9542
|
@ -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.
|
|
@ -6,8 +6,8 @@
|
|||
<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-beta014"/>
|
||||
<dependency id="Microsoft.OpenApi.CSharpComment.Reader" version="1.0.0-beta019"/>
|
||||
<dependency id="Microsoft.OpenApi" version="1.0.0-beta015"/>
|
||||
<dependency id="Microsoft.OpenApi.CSharpComment.Reader" version="1.0.0-beta020"/>
|
||||
<dependency id="Newtonsoft.json" version="4.0.8"/>
|
||||
</dependencies>
|
||||
</metadata>
|
||||
|
|
|
@ -44,46 +44,6 @@ namespace Microsoft.OpenApi.CSharpComment.Reader
|
|||
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)
|
||||
{
|
||||
|
@ -100,8 +60,7 @@ namespace Microsoft.OpenApi.CSharpComment.Reader
|
|||
cSharpCommentOpenApiGeneratorConfig.AnnotationXmlDocuments,
|
||||
cSharpCommentOpenApiGeneratorConfig.AssemblyPaths,
|
||||
cSharpCommentOpenApiGeneratorConfig.AdvancedConfigurationXmlDocument?.ToString(),
|
||||
cSharpCommentOpenApiGeneratorConfig.OpenApiSpecificationVersion,
|
||||
cSharpCommentOpenApiGeneratorConfig.OpenApiFormat,
|
||||
cSharpCommentOpenApiGeneratorConfig.OpenApiDocumentVersion,
|
||||
out generationDiagnostic);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,16 +20,15 @@ namespace Microsoft.OpenApi.CSharpComment.Reader
|
|||
/// <param name="assemblyPaths">The list of relative or absolute paths to the assemblies that will be used to
|
||||
/// reflect into the types provided in the xml.
|
||||
/// </param>
|
||||
/// <param name="openApiSpecificationVersion">The specification version of the OpenAPI document to generate.
|
||||
/// </param>
|
||||
/// <param name="openApiDocumentVersion">The version of the OpenAPI document.</param>
|
||||
public CSharpCommentOpenApiGeneratorConfig(
|
||||
IList<XDocument> annotationXmlDocuments,
|
||||
IList<string> assemblyPaths,
|
||||
OpenApiSpecVersion openApiSpecificationVersion)
|
||||
string openApiDocumentVersion)
|
||||
: this(
|
||||
annotationXmlDocuments,
|
||||
assemblyPaths,
|
||||
openApiSpecificationVersion,
|
||||
openApiDocumentVersion,
|
||||
new CSharpCommentOpenApiGeneratorFilterConfig())
|
||||
{
|
||||
}
|
||||
|
@ -41,15 +40,14 @@ namespace Microsoft.OpenApi.CSharpComment.Reader
|
|||
/// <param name="assemblyPaths">The list of relative or absolute paths to the assemblies that will be used to
|
||||
/// reflect into the types provided in the xml.
|
||||
/// </param>
|
||||
/// <param name="openApiSpecificationVersion">The specification version of the OpenAPI document to generate.
|
||||
/// </param>
|
||||
/// <param name="openApiDocumentVersion">The version of the OpenAPI document.</param>
|
||||
/// <param name="cSharpCommentOpenApiGeneratorFilterConfig">The configuration encapsulating all the filters
|
||||
/// that will be applied while generating/processing OpenAPI document from C# comments.</param>
|
||||
public CSharpCommentOpenApiGeneratorConfig(
|
||||
IList<XDocument> annotationXmlDocuments,
|
||||
IList<string> assemblyPaths,
|
||||
OpenApiSpecVersion openApiSpecificationVersion,
|
||||
CSharpCommentOpenApiGeneratorFilterConfig cSharpCommentOpenApiGeneratorFilterConfig )
|
||||
string openApiDocumentVersion,
|
||||
CSharpCommentOpenApiGeneratorFilterConfig cSharpCommentOpenApiGeneratorFilterConfig)
|
||||
{
|
||||
AnnotationXmlDocuments = annotationXmlDocuments
|
||||
?? throw new ArgumentNullException(nameof(annotationXmlDocuments));
|
||||
|
@ -60,7 +58,12 @@ namespace Microsoft.OpenApi.CSharpComment.Reader
|
|||
CSharpCommentOpenApiGeneratorFilterConfig = cSharpCommentOpenApiGeneratorFilterConfig
|
||||
?? throw new ArgumentNullException(nameof(cSharpCommentOpenApiGeneratorFilterConfig));
|
||||
|
||||
OpenApiSpecificationVersion = openApiSpecificationVersion;
|
||||
if (string.IsNullOrWhiteSpace(openApiDocumentVersion))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(openApiDocumentVersion));
|
||||
}
|
||||
|
||||
OpenApiDocumentVersion = openApiDocumentVersion;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -86,13 +89,8 @@ namespace Microsoft.OpenApi.CSharpComment.Reader
|
|||
public CSharpCommentOpenApiGeneratorFilterConfig CSharpCommentOpenApiGeneratorFilterConfig { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The format (YAML or JSON) of the OpenAPI document to generate.
|
||||
/// The version of the OpenAPI document.
|
||||
/// </summary>
|
||||
public OpenApiFormat OpenApiFormat { get; set; } = OpenApiFormat.Json;
|
||||
|
||||
/// <summary>
|
||||
/// The specification version of the OpenAPI document to generate.
|
||||
/// </summary>
|
||||
public OpenApiSpecVersion OpenApiSpecificationVersion { get; }
|
||||
public string OpenApiDocumentVersion { get; }
|
||||
}
|
||||
}
|
|
@ -41,10 +41,7 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.DocumentFilters
|
|||
specificationDocument.Info = new OpenApiInfo
|
||||
{
|
||||
Title = xmlDocument.XPathSelectElement("//doc/assembly/name")?.Value,
|
||||
|
||||
// Assign version as 1.0.0 for the time being.
|
||||
// TODO: Customer should be able to input this in the Config file
|
||||
Version = "1.0.0"
|
||||
Version = settings.OpenApiDocumentVersion
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,5 +14,10 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.DocumentFilters
|
|||
/// Gets or sets the type fetcher.
|
||||
/// </summary>
|
||||
public TypeFetcher TypeFetcher { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the OpenAPI document version.
|
||||
/// </summary>
|
||||
public string OpenApiDocumentVersion { get; set; }
|
||||
}
|
||||
}
|
|
@ -6,10 +6,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.OpenApi.CSharpComment.Reader.Models;
|
||||
using Microsoft.OpenApi.Extensions;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Microsoft.OpenApi.Readers;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.Extensions
|
||||
{
|
||||
|
@ -82,68 +78,6 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Extensions
|
|||
!sourceDictionary.Except(targetDictionary).Any();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <see cref="Dictionary{TKey,TValue}"/>where TKey is <see cref="DocumentVariantInfo"/>
|
||||
/// and TValue is <see cref="string"/>
|
||||
/// To <see cref="Dictionary{TKey,TValue}"/>where TKey is <see cref="DocumentVariantInfo"/>
|
||||
/// and TValue is <see cref="OpenApiDocument"/>.
|
||||
/// </summary>
|
||||
/// <param name="sourceDictionary">The serialized OpenAPI documents dictionary.</param>
|
||||
/// <returns>Dictionary mapping document variant metadata to their respective OpenAPI document.
|
||||
/// </returns>
|
||||
public static IDictionary<DocumentVariantInfo, OpenApiDocument> ToOpenApiDocuments(
|
||||
this IDictionary<DocumentVariantInfo, string> sourceDictionary)
|
||||
{
|
||||
if (sourceDictionary == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(sourceDictionary));
|
||||
}
|
||||
|
||||
IDictionary<DocumentVariantInfo, OpenApiDocument> openApiDocuments =
|
||||
new Dictionary<DocumentVariantInfo, OpenApiDocument>();
|
||||
|
||||
foreach (var variantInfoDocumentKeyValuePair in sourceDictionary)
|
||||
{
|
||||
openApiDocuments[new DocumentVariantInfo(variantInfoDocumentKeyValuePair.Key)]
|
||||
= new OpenApiStringReader().Read(variantInfoDocumentKeyValuePair.Value, out var _);
|
||||
}
|
||||
|
||||
return openApiDocuments;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <see cref="Dictionary{TKey,TValue}"/>where TKey is <see cref="DocumentVariantInfo"/>
|
||||
/// and TValue is <see cref="OpenApiDocument"/>
|
||||
/// To <see cref="Dictionary{TKey,TValue}"/>where TKey is <see cref="DocumentVariantInfo"/>
|
||||
/// and TValue is <see cref="string"/>.
|
||||
/// </summary>
|
||||
/// <param name="sourceDictionary">The dictionary of OpenAPI documents.</param>
|
||||
/// <param name="openApiSpecVersion">The OpenAPI spec version to serialize to.</param>
|
||||
/// <param name="openApiFormat">The OpenAPI format to serialize to.</param>
|
||||
/// <returns>Dictionary mapping document variant metadata to their respective serialized OpenAPI document.
|
||||
/// </returns>
|
||||
public static IDictionary<DocumentVariantInfo, string> ToSerializedOpenApiDocuments(
|
||||
this IDictionary<DocumentVariantInfo, OpenApiDocument> sourceDictionary,
|
||||
OpenApiSpecVersion openApiSpecVersion = OpenApiSpecVersion.OpenApi3_0,
|
||||
OpenApiFormat openApiFormat = OpenApiFormat.Json)
|
||||
{
|
||||
if (sourceDictionary == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(sourceDictionary));
|
||||
}
|
||||
|
||||
IDictionary<DocumentVariantInfo, string> openApiDocuments =
|
||||
new Dictionary<DocumentVariantInfo, string>();
|
||||
|
||||
foreach (var variantInfoDocumentKeyValuePair in sourceDictionary)
|
||||
{
|
||||
openApiDocuments[new DocumentVariantInfo(variantInfoDocumentKeyValuePair.Key)]
|
||||
= variantInfoDocumentKeyValuePair.Value.Serialize(openApiSpecVersion, openApiFormat);
|
||||
}
|
||||
|
||||
return openApiDocuments;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts <see cref="IDictionary{TKey, TValue}"/>where TKey is <see cref="string"/>
|
||||
/// and TValue is <see cref="string"/>to comma separated string e.g. {"key1":"value1","key2":"value2"}.
|
||||
|
|
|
@ -38,31 +38,5 @@ namespace Microsoft.OpenApi.CSharpComment.Reader
|
|||
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);
|
||||
}
|
||||
}
|
|
@ -197,27 +197,22 @@ namespace Microsoft.OpenApi.CSharpComment.Reader
|
|||
/// <param name="annotationXmlDocuments">The list of XDocuments representing annotation xmls.</param>
|
||||
/// <param name="contractAssemblyPaths">The contract assembly paths.</param>
|
||||
/// <param name="configurationXml">The serialized XDocument representing the generation configuration.</param>
|
||||
/// <param name="openApiSpecVersion">Specification version of the OpenAPI documents to generate.</param>
|
||||
/// <param name="openApiFormat">Format (YAML or JSON) of the OpenAPI document to generate.</param>
|
||||
/// <param name="openApiDocumentVersion">The version of the OpenAPI document.</param>
|
||||
/// <param name="generationDiagnostic">A string representing serialized version of
|
||||
/// <see cref="GenerationDiagnostic"/>>
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// A string representing serialized version of <see cref="IDictionary{DocumentVariantInfo, OpenApiDocument}"/>>
|
||||
/// Dictionary mapping document variant metadata to their respective OpenAPI document.
|
||||
/// </returns>
|
||||
/// <remarks>
|
||||
/// Given that this function is expected to be called from an isolated domain,
|
||||
/// the input and output must be serializable to string or value type.
|
||||
/// </remarks>
|
||||
public IDictionary<DocumentVariantInfo, string> GenerateOpenApiDocuments(
|
||||
public IDictionary<DocumentVariantInfo, OpenApiDocument> GenerateOpenApiDocuments(
|
||||
IList<XDocument> annotationXmlDocuments,
|
||||
IList<string> contractAssemblyPaths,
|
||||
string configurationXml,
|
||||
OpenApiSpecVersion openApiSpecVersion,
|
||||
OpenApiFormat openApiFormat,
|
||||
string openApiDocumentVersion,
|
||||
out GenerationDiagnostic generationDiagnostic)
|
||||
{
|
||||
IDictionary<DocumentVariantInfo, string> openApiDocuments = new Dictionary<DocumentVariantInfo, string>();
|
||||
IDictionary<DocumentVariantInfo, OpenApiDocument> openApiDocuments
|
||||
= new Dictionary<DocumentVariantInfo, OpenApiDocument>();
|
||||
|
||||
var operationElements = new List<XElement>();
|
||||
|
||||
|
@ -307,7 +302,8 @@ namespace Microsoft.OpenApi.CSharpComment.Reader
|
|||
annotationXmlDocuments,
|
||||
new DocumentFilterSettings
|
||||
{
|
||||
TypeFetcher = typeFetcher
|
||||
TypeFetcher = typeFetcher,
|
||||
OpenApiDocumentVersion = openApiDocumentVersion
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
|
@ -366,7 +362,7 @@ namespace Microsoft.OpenApi.CSharpComment.Reader
|
|||
}
|
||||
|
||||
generationDiagnostic.DocumentGenerationDiagnostic = documentGenerationDiagnostic;
|
||||
return documents.ToSerializedOpenApiDocuments(openApiSpecVersion, openApiFormat);
|
||||
return documents;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
|
||||
<metadata>
|
||||
<id>Microsoft.OpenApi.CSharpComment.Reader</id>
|
||||
<version>1.0.0-beta019</version>
|
||||
<version>1.0.0-beta020</version>
|
||||
<authors>Microsoft</authors>
|
||||
<description>Reader that translates Visual Studio C# comments into .NET objects representing OpenAPI specification.</description>
|
||||
<dependencies>
|
||||
<dependency id="Microsoft.OpenApi" version="1.0.0-beta014"/>
|
||||
<dependency id="Microsoft.OpenApi.Readers" version="1.0.0-beta014"/>
|
||||
<dependency id="Microsoft.OpenApi" version="1.0.0-beta015"/>
|
||||
<dependency id="Microsoft.OpenApi.Readers" version="1.0.0-beta015"/>
|
||||
</dependencies>
|
||||
</metadata>
|
||||
</package>
|
|
@ -0,0 +1,52 @@
|
|||
// ------------------------------------------------------------
|
||||
// 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 Microsoft.OpenApi.CSharpComment.Reader.Models;
|
||||
using Microsoft.OpenApi.Extensions;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace Microsoft.OpenApi.CSharpComment.Reader.Tests
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods for <see cref="IDictionary{TKey,TValue}"/>.
|
||||
/// </summary>
|
||||
internal static class DictionaryExtensions
|
||||
{
|
||||
/// <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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -36,7 +36,6 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.DocumentVariantTests
|
|||
IList<string> inputXmlFiles,
|
||||
IList<string> inputBinaryFiles,
|
||||
string configXmlFile,
|
||||
OpenApiSpecVersion openApiSpecVersion,
|
||||
int expectedOperationGenerationResultsCount,
|
||||
IDictionary<DocumentVariantInfo, string> documentVariantInfoToExpectedJsonFileMap,
|
||||
DocumentGenerationDiagnostic expectedDocumentGenerationResult)
|
||||
|
@ -52,7 +51,7 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.DocumentVariantTests
|
|||
|
||||
var generator = new CSharpCommentOpenApiGenerator();
|
||||
|
||||
var input = new CSharpCommentOpenApiGeneratorConfig(documents, inputBinaryFiles, openApiSpecVersion)
|
||||
var input = new CSharpCommentOpenApiGeneratorConfig(documents, inputBinaryFiles, "1.0.0")
|
||||
{
|
||||
AdvancedConfigurationXmlDocument = configDocument
|
||||
};
|
||||
|
@ -130,7 +129,6 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.DocumentVariantTests
|
|||
IList<string> inputXmlFiles,
|
||||
IList<string> inputBinaryFiles,
|
||||
string configXmlFile,
|
||||
OpenApiSpecVersion openApiSpecVersion,
|
||||
int expectedOperationGenerationResultsCount,
|
||||
IDictionary<DocumentVariantInfo, string> documentVariantInfoToExpectedJsonFileMap)
|
||||
{
|
||||
|
@ -144,7 +142,7 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.DocumentVariantTests
|
|||
var configDocument = XDocument.Load(configPath);
|
||||
|
||||
var generator = new CSharpCommentOpenApiGenerator();
|
||||
var input = new CSharpCommentOpenApiGeneratorConfig(documents, inputBinaryFiles, openApiSpecVersion)
|
||||
var input = new CSharpCommentOpenApiGeneratorConfig(documents, inputBinaryFiles, "1.0.0")
|
||||
{
|
||||
AdvancedConfigurationXmlDocument = configDocument
|
||||
};
|
||||
|
@ -179,7 +177,7 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.DocumentVariantTests
|
|||
|
||||
openApiDocuments.TryGetValue(documentVariantInfo, out var specificationDocument);
|
||||
|
||||
var actualDocumentAsString = specificationDocument.SerializeAsJson(openApiSpecVersion);
|
||||
var actualDocumentAsString = specificationDocument.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0);
|
||||
|
||||
_output.WriteLine(JsonConvert.SerializeObject(documentVariantInfo));
|
||||
_output.WriteLine(actualDocumentAsString);
|
||||
|
|
|
@ -40,7 +40,6 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.DocumentVariantTests
|
|||
Path.Combine(
|
||||
InputDirectory,
|
||||
"ConfigOneDocumentVariantTagSwaggerNoOptions.xml"),
|
||||
OpenApiSpecVersion.OpenApi3_0,
|
||||
9,
|
||||
new Dictionary<DocumentVariantInfo, string>
|
||||
{
|
||||
|
@ -108,7 +107,6 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.DocumentVariantTests
|
|||
Path.Combine(
|
||||
InputDirectory,
|
||||
"ConfigOneDocumentVariantTag.xml"),
|
||||
OpenApiSpecVersion.OpenApi3_0,
|
||||
9,
|
||||
new Dictionary<DocumentVariantInfo, string>
|
||||
{
|
||||
|
@ -187,7 +185,6 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.DocumentVariantTests
|
|||
Path.Combine(
|
||||
InputDirectory,
|
||||
"ConfigMultipleDocumentVariantTagsWithCommonAnnotations.xml"),
|
||||
OpenApiSpecVersion.OpenApi3_0,
|
||||
9,
|
||||
new Dictionary<DocumentVariantInfo, string>
|
||||
{
|
||||
|
@ -262,7 +259,6 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.DocumentVariantTests
|
|||
Path.Combine(
|
||||
InputDirectory,
|
||||
"ConfigOneDocumentVariantTag.xml"),
|
||||
OpenApiSpecVersion.OpenApi3_0,
|
||||
9,
|
||||
new Dictionary<DocumentVariantInfo, string>
|
||||
{
|
||||
|
@ -316,7 +312,6 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.DocumentVariantTests
|
|||
Path.Combine(
|
||||
InputDirectory,
|
||||
"ConfigOneDocumentVariantTagSwaggerNoOptions.xml"),
|
||||
OpenApiSpecVersion.OpenApi3_0,
|
||||
9,
|
||||
new Dictionary<DocumentVariantInfo, string>
|
||||
{
|
||||
|
@ -359,7 +354,6 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.DocumentVariantTests
|
|||
Path.Combine(
|
||||
InputDirectory,
|
||||
"ConfigOneDocumentVariantTagSwaggerNoOptions.xml"),
|
||||
OpenApiSpecVersion.OpenApi3_0,
|
||||
9,
|
||||
new Dictionary<DocumentVariantInfo, string>
|
||||
{
|
||||
|
@ -413,7 +407,6 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.DocumentVariantTests
|
|||
Path.Combine(
|
||||
InputDirectory,
|
||||
"ConfigOneDocumentVariantTag.xml"),
|
||||
OpenApiSpecVersion.OpenApi3_0,
|
||||
9,
|
||||
new Dictionary<DocumentVariantInfo, string>
|
||||
{
|
||||
|
|
|
@ -87,6 +87,7 @@
|
|||
<Otherwise />
|
||||
</Choose>
|
||||
<ItemGroup>
|
||||
<Compile Include="DictionaryExtensions.cs" />
|
||||
<Compile Include="DictionaryJsonConverter.cs" />
|
||||
<Compile Include="DocumentVariantTests\DocumentVariantTest.cs" />
|
||||
<Compile Include="FilterTests\BranchOptionalPathParametersFilterTest.cs" />
|
||||
|
|
|
@ -53,7 +53,6 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.OpenApiDocumentGeneratorT
|
|||
InputDirectory,
|
||||
"Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts.dll")
|
||||
},
|
||||
OpenApiSpecVersion.OpenApi3_0,
|
||||
9,
|
||||
Path.Combine(
|
||||
OutputDirectory,
|
||||
|
@ -108,7 +107,6 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.OpenApiDocumentGeneratorT
|
|||
InputDirectory,
|
||||
"Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts.dll")
|
||||
},
|
||||
OpenApiSpecVersion.OpenApi3_0,
|
||||
9,
|
||||
Path.Combine(
|
||||
OutputDirectory,
|
||||
|
@ -169,7 +167,6 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.OpenApiDocumentGeneratorT
|
|||
InputDirectory,
|
||||
"Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts.dll")
|
||||
},
|
||||
OpenApiSpecVersion.OpenApi3_0,
|
||||
9,
|
||||
Path.Combine(
|
||||
OutputDirectory,
|
||||
|
@ -226,7 +223,6 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.OpenApiDocumentGeneratorT
|
|||
InputDirectory,
|
||||
"Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts.dll")
|
||||
},
|
||||
OpenApiSpecVersion.OpenApi3_0,
|
||||
9,
|
||||
Path.Combine(
|
||||
OutputDirectory,
|
||||
|
@ -284,7 +280,6 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.OpenApiDocumentGeneratorT
|
|||
InputDirectory,
|
||||
"Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts.dll")
|
||||
},
|
||||
OpenApiSpecVersion.OpenApi3_0,
|
||||
9,
|
||||
Path.Combine(
|
||||
OutputDirectory,
|
||||
|
@ -342,7 +337,6 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.OpenApiDocumentGeneratorT
|
|||
InputDirectory,
|
||||
"Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts.dll")
|
||||
},
|
||||
OpenApiSpecVersion.OpenApi3_0,
|
||||
9,
|
||||
Path.Combine(
|
||||
OutputDirectory,
|
||||
|
@ -397,7 +391,6 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.OpenApiDocumentGeneratorT
|
|||
InputDirectory,
|
||||
"Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts.dll")
|
||||
},
|
||||
OpenApiSpecVersion.OpenApi3_0,
|
||||
9,
|
||||
Path.Combine(
|
||||
OutputDirectory,
|
||||
|
@ -452,7 +445,6 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.OpenApiDocumentGeneratorT
|
|||
InputDirectory,
|
||||
"Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts.dll")
|
||||
},
|
||||
OpenApiSpecVersion.OpenApi3_0,
|
||||
9,
|
||||
Path.Combine(
|
||||
OutputDirectory,
|
||||
|
@ -509,7 +501,6 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.OpenApiDocumentGeneratorT
|
|||
InputDirectory,
|
||||
"Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts.dll")
|
||||
},
|
||||
OpenApiSpecVersion.OpenApi3_0,
|
||||
9,
|
||||
Path.Combine(
|
||||
OutputDirectory,
|
||||
|
@ -571,7 +562,6 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.OpenApiDocumentGeneratorT
|
|||
InputDirectory,
|
||||
"Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts.dll")
|
||||
},
|
||||
OpenApiSpecVersion.OpenApi3_0,
|
||||
9,
|
||||
Path.Combine(
|
||||
OutputDirectory,
|
||||
|
@ -632,7 +622,6 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.OpenApiDocumentGeneratorT
|
|||
"Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts.dll")
|
||||
},
|
||||
new UpdateSchemaWithNewtonsoftJsonPropertyAttributeFilter(),
|
||||
OpenApiSpecVersion.OpenApi3_0,
|
||||
1,
|
||||
Path.Combine(
|
||||
OutputDirectory,
|
||||
|
@ -660,7 +649,7 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.OpenApiDocumentGeneratorT
|
|||
InputDirectory,
|
||||
"Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts.dll")
|
||||
},
|
||||
OpenApiSpecVersion.OpenApi3_0,
|
||||
"1.0.0",
|
||||
9,
|
||||
Path.Combine(
|
||||
OutputDirectory,
|
||||
|
@ -685,7 +674,7 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.OpenApiDocumentGeneratorT
|
|||
InputDirectory,
|
||||
"Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts.dll")
|
||||
},
|
||||
OpenApiSpecVersion.OpenApi3_0,
|
||||
"2.0.0",
|
||||
1,
|
||||
Path.Combine(
|
||||
OutputDirectory,
|
||||
|
@ -710,7 +699,7 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.OpenApiDocumentGeneratorT
|
|||
InputDirectory,
|
||||
"Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts.dll")
|
||||
},
|
||||
OpenApiSpecVersion.OpenApi3_0,
|
||||
"1.0.0",
|
||||
9,
|
||||
Path.Combine(
|
||||
OutputDirectory,
|
||||
|
@ -736,7 +725,7 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.OpenApiDocumentGeneratorT
|
|||
InputDirectory,
|
||||
"Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts.dll")
|
||||
},
|
||||
OpenApiSpecVersion.OpenApi3_0,
|
||||
"1.0.0",
|
||||
9,
|
||||
Path.Combine(
|
||||
OutputDirectory,
|
||||
|
@ -761,7 +750,7 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.OpenApiDocumentGeneratorT
|
|||
InputDirectory,
|
||||
"Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts.dll")
|
||||
},
|
||||
OpenApiSpecVersion.OpenApi3_0,
|
||||
"1.0.0",
|
||||
9,
|
||||
Path.Combine(
|
||||
OutputDirectory,
|
||||
|
@ -786,7 +775,7 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.OpenApiDocumentGeneratorT
|
|||
InputDirectory,
|
||||
"Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts.dll")
|
||||
},
|
||||
OpenApiSpecVersion.OpenApi3_0,
|
||||
"1.0.0",
|
||||
9,
|
||||
Path.Combine(
|
||||
OutputDirectory,
|
||||
|
@ -811,7 +800,7 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.OpenApiDocumentGeneratorT
|
|||
InputDirectory,
|
||||
"Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts.dll")
|
||||
},
|
||||
OpenApiSpecVersion.OpenApi3_0,
|
||||
"1.0.0",
|
||||
9,
|
||||
Path.Combine(
|
||||
OutputDirectory,
|
||||
|
@ -836,7 +825,7 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.OpenApiDocumentGeneratorT
|
|||
InputDirectory,
|
||||
"Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts.dll")
|
||||
},
|
||||
OpenApiSpecVersion.OpenApi3_0,
|
||||
"1.0.0",
|
||||
9,
|
||||
Path.Combine(
|
||||
OutputDirectory,
|
||||
|
@ -861,7 +850,7 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.OpenApiDocumentGeneratorT
|
|||
InputDirectory,
|
||||
"Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts.dll")
|
||||
},
|
||||
OpenApiSpecVersion.OpenApi3_0,
|
||||
"1.0.0",
|
||||
9,
|
||||
Path.Combine(
|
||||
OutputDirectory,
|
||||
|
@ -886,7 +875,7 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.OpenApiDocumentGeneratorT
|
|||
InputDirectory,
|
||||
"Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts.dll")
|
||||
},
|
||||
OpenApiSpecVersion.OpenApi3_0,
|
||||
"1.0.0",
|
||||
9,
|
||||
Path.Combine(
|
||||
OutputDirectory,
|
||||
|
@ -911,7 +900,7 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.OpenApiDocumentGeneratorT
|
|||
InputDirectory,
|
||||
"Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts.dll")
|
||||
},
|
||||
OpenApiSpecVersion.OpenApi3_0,
|
||||
"1.0.0",
|
||||
9,
|
||||
Path.Combine(
|
||||
OutputDirectory,
|
||||
|
@ -936,7 +925,7 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.OpenApiDocumentGeneratorT
|
|||
InputDirectory,
|
||||
"Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts.dll")
|
||||
},
|
||||
OpenApiSpecVersion.OpenApi3_0,
|
||||
"1.0.0",
|
||||
9,
|
||||
Path.Combine(
|
||||
OutputDirectory,
|
||||
|
@ -944,124 +933,12 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.OpenApiDocumentGeneratorT
|
|||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A short version of the <see cref="GetTestCasesForValidDocumentationShouldReturnCorrectDocument"/>
|
||||
/// so that we can simply test the serialization without wasting time on all test cases.
|
||||
/// </summary>
|
||||
public static IEnumerable<object[]> GetTestCasesForValidDocumentationShouldReturnCorrectSerializedDocument()
|
||||
{
|
||||
// Standard, original valid XML document with JSON - V3 Open Api Document as output
|
||||
yield return new object[]
|
||||
{
|
||||
"Standard valid XML document (V3-JSON)",
|
||||
new List<string>
|
||||
{
|
||||
Path.Combine(InputDirectory, "Annotation.xml"),
|
||||
Path.Combine(InputDirectory, "Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts.xml")
|
||||
},
|
||||
new List<string>
|
||||
{
|
||||
Path.Combine(
|
||||
InputDirectory,
|
||||
"Microsoft.OpenApi.CSharpComment.Reader.Tests.SampleApis.dll"),
|
||||
Path.Combine(
|
||||
InputDirectory,
|
||||
"Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts.dll")
|
||||
},
|
||||
OpenApiSpecVersion.OpenApi3_0,
|
||||
OpenApiFormat.Json,
|
||||
9,
|
||||
Path.Combine(
|
||||
OutputDirectory,
|
||||
"Annotation.Json")
|
||||
};
|
||||
|
||||
// Standard, original valid XML document with YAML - V3 Open Api Document as output
|
||||
yield return new object[]
|
||||
{
|
||||
"Standard valid XML document (V3-YAML)",
|
||||
new List<string>
|
||||
{
|
||||
Path.Combine(InputDirectory, "Annotation.xml"),
|
||||
Path.Combine(InputDirectory, "Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts.xml")
|
||||
},
|
||||
new List<string>
|
||||
{
|
||||
Path.Combine(
|
||||
InputDirectory,
|
||||
"Microsoft.OpenApi.CSharpComment.Reader.Tests.SampleApis.dll"),
|
||||
Path.Combine(
|
||||
InputDirectory,
|
||||
"Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts.dll")
|
||||
},
|
||||
OpenApiSpecVersion.OpenApi3_0,
|
||||
OpenApiFormat.Yaml,
|
||||
9,
|
||||
Path.Combine(
|
||||
OutputDirectory,
|
||||
"Annotation.Json")
|
||||
};
|
||||
|
||||
// Standard, original valid XML document with YAML - V2 Open Api Document as output
|
||||
yield return new object[]
|
||||
{
|
||||
"Standard valid XML document (V2-YAML)",
|
||||
new List<string>
|
||||
{
|
||||
Path.Combine(InputDirectory, "Annotation.xml"),
|
||||
Path.Combine(InputDirectory, "Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts.xml")
|
||||
},
|
||||
new List<string>
|
||||
{
|
||||
Path.Combine(
|
||||
InputDirectory,
|
||||
"Microsoft.OpenApi.CSharpComment.Reader.Tests.SampleApis.dll"),
|
||||
Path.Combine(
|
||||
InputDirectory,
|
||||
"Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts.dll")
|
||||
},
|
||||
OpenApiSpecVersion.OpenApi2_0,
|
||||
OpenApiFormat.Yaml,
|
||||
9,
|
||||
Path.Combine(
|
||||
OutputDirectory,
|
||||
"AnnotationV2.Json")
|
||||
};
|
||||
|
||||
// Standard, original valid XML document with JSON - V2 Open Api Document as output
|
||||
yield return new object[]
|
||||
{
|
||||
"Standard valid XML document (V2-JSON)",
|
||||
new List<string>
|
||||
{
|
||||
Path.Combine(InputDirectory, "Annotation.xml"),
|
||||
Path.Combine(InputDirectory, "Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts.xml")
|
||||
},
|
||||
new List<string>
|
||||
{
|
||||
Path.Combine(
|
||||
InputDirectory,
|
||||
"Microsoft.OpenApi.CSharpComment.Reader.Tests.SampleApis.dll"),
|
||||
Path.Combine(
|
||||
InputDirectory,
|
||||
"Microsoft.OpenApi.CSharpComment.Reader.Tests.Contracts.dll")
|
||||
},
|
||||
OpenApiSpecVersion.OpenApi2_0,
|
||||
OpenApiFormat.Json,
|
||||
9,
|
||||
Path.Combine(
|
||||
OutputDirectory,
|
||||
"AnnotationV2.Json")
|
||||
};
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(GetTestCasesForInvalidDocumentationShouldYieldFailure))]
|
||||
public void InvalidDocumentationShouldYieldFailure(
|
||||
string testCaseName,
|
||||
IList<string> inputXmlFiles,
|
||||
IList<string> inputBinaryFiles,
|
||||
OpenApiSpecVersion openApiSpecVersion,
|
||||
int expectedOperationGenerationResultsCount,
|
||||
string expectedJsonFile,
|
||||
DocumentGenerationDiagnostic expectedDocumentGenerationResult,
|
||||
|
@ -1073,7 +950,7 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.OpenApiDocumentGeneratorT
|
|||
|
||||
documents.AddRange(inputXmlFiles.Select(XDocument.Load));
|
||||
|
||||
var input = new CSharpCommentOpenApiGeneratorConfig(documents, inputBinaryFiles, openApiSpecVersion);
|
||||
var input = new CSharpCommentOpenApiGeneratorConfig(documents, inputBinaryFiles, "1.0.0");
|
||||
|
||||
GenerationDiagnostic result;
|
||||
|
||||
|
@ -1097,7 +974,8 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.OpenApiDocumentGeneratorT
|
|||
p => p.Errors.Count > 0)
|
||||
.ToList();
|
||||
|
||||
var actualDocument = openApiDocuments[DocumentVariantInfo.Default].SerializeAsJson(openApiSpecVersion);
|
||||
var actualDocument = openApiDocuments[DocumentVariantInfo.Default]
|
||||
.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0);
|
||||
var expectedDocument = File.ReadAllText(expectedJsonFile);
|
||||
|
||||
|
||||
|
@ -1128,7 +1006,6 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.OpenApiDocumentGeneratorT
|
|||
string testCaseName,
|
||||
IList<string> inputXmlFiles,
|
||||
IList<string> inputBinaryFiles,
|
||||
OpenApiSpecVersion openApiSpecVersion,
|
||||
int expectedOperationGenerationResultsCount,
|
||||
string expectedJsonFile,
|
||||
DocumentGenerationDiagnostic expectedDocumentGenerationResult,
|
||||
|
@ -1140,7 +1017,7 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.OpenApiDocumentGeneratorT
|
|||
|
||||
documents.AddRange(inputXmlFiles.Select(XDocument.Load));
|
||||
|
||||
var input = new CSharpCommentOpenApiGeneratorConfig(documents, inputBinaryFiles, openApiSpecVersion);
|
||||
var input = new CSharpCommentOpenApiGeneratorConfig(documents, inputBinaryFiles, "1.0.0");
|
||||
|
||||
GenerationDiagnostic result;
|
||||
|
||||
|
@ -1164,7 +1041,8 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.OpenApiDocumentGeneratorT
|
|||
p => p.Errors.Count > 0)
|
||||
.ToList();
|
||||
|
||||
var actualDocument = openApiDocuments[DocumentVariantInfo.Default].SerializeAsJson(openApiSpecVersion);
|
||||
var actualDocument = openApiDocuments[DocumentVariantInfo.Default]
|
||||
.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0);
|
||||
var expectedDocument = File.ReadAllText(expectedJsonFile);
|
||||
|
||||
_output.WriteLine(actualDocument);
|
||||
|
@ -1189,15 +1067,15 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.OpenApiDocumentGeneratorT
|
|||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(OpenApiSpecVersion.OpenApi3_0)]
|
||||
public void NoOperationsToParseShouldReturnEmptyDocument(OpenApiSpecVersion openApiSpecVersion)
|
||||
[InlineData("1.0.0")]
|
||||
public void NoOperationsToParseShouldReturnEmptyDocument(string openApiDocumentVersion)
|
||||
{
|
||||
var path = Path.Combine(InputDirectory, "AnnotationNoOperationsToParse.xml");
|
||||
|
||||
var document = XDocument.Load(path);
|
||||
|
||||
var input = new CSharpCommentOpenApiGeneratorConfig(new List<XDocument>() {document}, new List<string>(),
|
||||
openApiSpecVersion);
|
||||
openApiDocumentVersion);
|
||||
|
||||
GenerationDiagnostic result;
|
||||
|
||||
|
@ -1227,7 +1105,7 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.OpenApiDocumentGeneratorT
|
|||
string testCaseName,
|
||||
IList<string> inputXmlFiles,
|
||||
IList<string> inputBinaryFiles,
|
||||
OpenApiSpecVersion openApiSpecVersion,
|
||||
string openApiDocumentVersion,
|
||||
int expectedOperationGenerationResultsCount,
|
||||
string expectedJsonFile)
|
||||
{
|
||||
|
@ -1237,7 +1115,7 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.OpenApiDocumentGeneratorT
|
|||
|
||||
documents.AddRange(inputXmlFiles.Select(XDocument.Load));
|
||||
|
||||
var input = new CSharpCommentOpenApiGeneratorConfig(documents, inputBinaryFiles, openApiSpecVersion);
|
||||
var input = new CSharpCommentOpenApiGeneratorConfig(documents, inputBinaryFiles, openApiDocumentVersion);
|
||||
|
||||
GenerationDiagnostic result;
|
||||
|
||||
|
@ -1258,7 +1136,8 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.OpenApiDocumentGeneratorT
|
|||
result.OperationGenerationDiagnostics.Where(p => p.Errors.Count > 0).Count().Should().Be(0);
|
||||
result.OperationGenerationDiagnostics.Count.Should().Be(expectedOperationGenerationResultsCount);
|
||||
|
||||
var actualDocument = openApiDocuments[DocumentVariantInfo.Default].SerializeAsJson(openApiSpecVersion);
|
||||
var actualDocument = openApiDocuments[DocumentVariantInfo.Default]
|
||||
.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0);
|
||||
var expectedDocument = File.ReadAllText(expectedJsonFile);
|
||||
|
||||
_output.WriteLine(actualDocument);
|
||||
|
@ -1283,7 +1162,6 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.OpenApiDocumentGeneratorT
|
|||
IList<string> inputXmlFiles,
|
||||
IList<string> inputBinaryFiles,
|
||||
IDocumentFilter documentFilter,
|
||||
OpenApiSpecVersion openApiSpecVersion,
|
||||
int expectedOperationGenerationResultsCount,
|
||||
string expectedJsonFile)
|
||||
{
|
||||
|
@ -1293,7 +1171,7 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.OpenApiDocumentGeneratorT
|
|||
|
||||
documents.AddRange(inputXmlFiles.Select(XDocument.Load));
|
||||
|
||||
var input = new CSharpCommentOpenApiGeneratorConfig(documents, inputBinaryFiles, openApiSpecVersion);
|
||||
var input = new CSharpCommentOpenApiGeneratorConfig(documents, inputBinaryFiles, "1.0.0");
|
||||
input.CSharpCommentOpenApiGeneratorFilterConfig.DocumentFilters.Add(documentFilter);
|
||||
|
||||
GenerationDiagnostic result;
|
||||
|
@ -1317,65 +1195,8 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.OpenApiDocumentGeneratorT
|
|||
result.OperationGenerationDiagnostics.Where(p => p.Errors.Count > 0).Count().Should().Be(0);
|
||||
result.OperationGenerationDiagnostics.Count.Should().Be(expectedOperationGenerationResultsCount);
|
||||
|
||||
var actualDocument = openApiDocuments[DocumentVariantInfo.Default].SerializeAsJson(openApiSpecVersion);
|
||||
var expectedDocument = File.ReadAllText(expectedJsonFile);
|
||||
|
||||
_output.WriteLine(actualDocument);
|
||||
|
||||
var openApiStringReader = new OpenApiStringReader();
|
||||
|
||||
var actualDeserializedDocument = openApiStringReader.Read(
|
||||
actualDocument,
|
||||
out OpenApiDiagnostic diagnostic);
|
||||
|
||||
diagnostic.Errors.Count.Should().Be(0);
|
||||
|
||||
actualDeserializedDocument
|
||||
.Should()
|
||||
.BeEquivalentTo(openApiStringReader.Read(expectedDocument, out var _));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(GetTestCasesForValidDocumentationShouldReturnCorrectSerializedDocument))]
|
||||
public void ValidDocumentationShouldReturnCorrectSerializedDocument(
|
||||
string testCaseName,
|
||||
IList<string> inputXmlFiles,
|
||||
IList<string> inputBinaryFiles,
|
||||
OpenApiSpecVersion openApiSpecVersion,
|
||||
OpenApiFormat openApiFormat,
|
||||
int expectedOperationGenerationResultsCount,
|
||||
string expectedJsonFile)
|
||||
{
|
||||
_output.WriteLine(testCaseName);
|
||||
|
||||
var documents = new List<XDocument>();
|
||||
|
||||
documents.AddRange(inputXmlFiles.Select(XDocument.Load));
|
||||
|
||||
var input = new CSharpCommentOpenApiGeneratorConfig(documents, inputBinaryFiles, openApiSpecVersion)
|
||||
{
|
||||
OpenApiFormat = openApiFormat
|
||||
};
|
||||
|
||||
var generator = new CSharpCommentOpenApiGenerator();
|
||||
|
||||
GenerationDiagnostic result;
|
||||
|
||||
var serializedDocuments = generator.GenerateSerializedDocuments(input, out result);
|
||||
|
||||
result.Should().NotBeNull();
|
||||
serializedDocuments.Should().NotBeNull();
|
||||
|
||||
_output.WriteLine(JsonConvert.SerializeObject(serializedDocuments));
|
||||
|
||||
result.DocumentGenerationDiagnostic.Errors.Count.Should().Be(0);
|
||||
|
||||
serializedDocuments[DocumentVariantInfo.Default].Should().NotBeNull();
|
||||
|
||||
result.OperationGenerationDiagnostics.Where(p => p.Errors.Count > 0).Count().Should().Be(0);
|
||||
result.OperationGenerationDiagnostics.Count.Should().Be(expectedOperationGenerationResultsCount);
|
||||
|
||||
var actualDocument = serializedDocuments[DocumentVariantInfo.Default];
|
||||
var actualDocument = openApiDocuments[DocumentVariantInfo.Default]
|
||||
.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0);
|
||||
var expectedDocument = File.ReadAllText(expectedJsonFile);
|
||||
|
||||
_output.WriteLine(actualDocument);
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"openapi": "3.0.1",
|
||||
"info": {
|
||||
"title": "Microsoft.OpenApi.CSharpComment.Reader.Tests.SampleApis",
|
||||
"version": "1.0.0"
|
||||
"version": "2.0.0"
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
|
|
|
@ -34,7 +34,6 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.OperationConfigTests
|
|||
IList<string> inputXmlFiles,
|
||||
IList<string> inputBinaryFiles,
|
||||
string configXmlFile,
|
||||
OpenApiSpecVersion openApiSpecVersion,
|
||||
int expectedOperationGenerationResultsCount,
|
||||
string expectedJsonFile)
|
||||
{
|
||||
|
@ -45,7 +44,7 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.OperationConfigTests
|
|||
var configDocument = XDocument.Load(configXmlFile);
|
||||
|
||||
var generator = new CSharpCommentOpenApiGenerator();
|
||||
var input = new CSharpCommentOpenApiGeneratorConfig(documents, inputBinaryFiles, openApiSpecVersion)
|
||||
var input = new CSharpCommentOpenApiGeneratorConfig(documents, inputBinaryFiles, "1.0.0")
|
||||
{
|
||||
AdvancedConfigurationXmlDocument = configDocument
|
||||
};
|
||||
|
@ -61,7 +60,8 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.OperationConfigTests
|
|||
openApiDocuments[DocumentVariantInfo.Default].Should().NotBeNull();
|
||||
result.OperationGenerationDiagnostics.Count.Should().Be(expectedOperationGenerationResultsCount);
|
||||
|
||||
var actualDocument = openApiDocuments[DocumentVariantInfo.Default].SerializeAsJson(openApiSpecVersion);
|
||||
var actualDocument = openApiDocuments[DocumentVariantInfo.Default]
|
||||
.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0);
|
||||
var expectedDocument = File.ReadAllText(expectedJsonFile);
|
||||
|
||||
_output.WriteLine(actualDocument);
|
||||
|
@ -104,7 +104,6 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.OperationConfigTests
|
|||
Path.Combine(
|
||||
InputDirectory,
|
||||
"ConfigNoOperation.xml"),
|
||||
OpenApiSpecVersion.OpenApi3_0,
|
||||
7,
|
||||
Path.Combine(
|
||||
OutputDirectory,
|
||||
|
@ -132,7 +131,6 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.OperationConfigTests
|
|||
Path.Combine(
|
||||
InputDirectory,
|
||||
"ConfigBlankOperation.xml"),
|
||||
OpenApiSpecVersion.OpenApi3_0,
|
||||
7,
|
||||
Path.Combine(
|
||||
OutputDirectory,
|
||||
|
@ -160,7 +158,6 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.OperationConfigTests
|
|||
Path.Combine(
|
||||
InputDirectory,
|
||||
"ConfigApplyToAllOperations.xml"),
|
||||
OpenApiSpecVersion.OpenApi3_0,
|
||||
7,
|
||||
Path.Combine(
|
||||
OutputDirectory,
|
||||
|
@ -188,7 +185,6 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.OperationConfigTests
|
|||
Path.Combine(
|
||||
InputDirectory,
|
||||
"ConfigApplyToSomeOperations.xml"),
|
||||
OpenApiSpecVersion.OpenApi3_0,
|
||||
7,
|
||||
Path.Combine(
|
||||
OutputDirectory,
|
||||
|
@ -216,7 +212,6 @@ namespace Microsoft.OpenApi.CSharpComment.Reader.Tests.OperationConfigTests
|
|||
Path.Combine(
|
||||
InputDirectory,
|
||||
"ConfigOverridden.xml"),
|
||||
OpenApiSpecVersion.OpenApi3_0,
|
||||
7,
|
||||
Path.Combine(
|
||||
OutputDirectory,
|
||||
|
|
Загрузка…
Ссылка в новой задаче