Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------

using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using Microsoft.OData.Edm;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.OData.Common;
using Microsoft.OpenApi.OData.Edm;
Expand All @@ -32,7 +36,8 @@ public static OpenApiInfo CreateInfo(this ODataContext context)
{
Title = context.GetTitle(),
Version = context.GetVersion(),
Description = context.GetDescription()
Description = context.GetDescription(),
Extensions = context.GetExtensions()
};
}

Expand Down Expand Up @@ -93,5 +98,26 @@ private static string GetDescription(this ODataContext context)
// so a default description should be provided if no Core.LongDescription annotation is present.
return "This OData service is located at " + context.Settings.ServiceRoot.OriginalString;
}

private static Dictionary<string, IOpenApiExtension> GetExtensions(this ODataContext context)
{
Debug.Assert(context != null);

if (context.Settings.IncludeAssemblyInfo)
{
return new Dictionary<string, IOpenApiExtension>()
{
{
"x-ms-generated-by",
new OpenApiObject
{
{ "toolName", new OpenApiString("Microsoft.OpenApi.OData") },
{ "toolVersion", new OpenApiString(Assembly.GetExecutingAssembly().GetName().Version.ToString()) }
}
}
};
}
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
<PackageReleaseNotes>
- Use convert setting to toggle between referencing @odata.count and @odata.nextLink #282
- Fixes URL Path parameters of type datetime generated as strings with quotes #262
- Add support for alternate keys #120
- Set assembly version used for conversion in OpenApiInfo object #208
- Add support for alternate keys parameters #120
</PackageReleaseNotes>
<AssemblyName>Microsoft.OpenApi.OData.Reader</AssemblyName>
<AssemblyOriginatorKeyFile>..\..\tool\Microsoft.OpenApi.OData.snk</AssemblyOriginatorKeyFile>
Expand Down
7 changes: 7 additions & 0 deletions src/Microsoft.OpenApi.OData.Reader/OpenApiConvertSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,12 @@ public string PathPrefix
/// </summary>
public bool UseSuccessStatusCodeRange { get; set; } = false;

/// <summary>
/// Gets/Sets a value indicating whether to show the version of the assembly used for generating
/// Open API document
/// </summary>
public bool IncludeAssemblyInfo { get; set; } = true;

/// <summary>
/// Get/Sets a dictionary containing a mapping of HTTP methods to custom link relation types
/// </summary>
Expand Down Expand Up @@ -335,6 +341,7 @@ internal OpenApiConvertSettings Clone()
AppendBoundOperationsOnDerivedTypeCastSegments = this.AppendBoundOperationsOnDerivedTypeCastSegments,
UseSuccessStatusCodeRange = this.UseSuccessStatusCodeRange,
EnableCount = this.EnableCount,
IncludeAssemblyInfo = this.IncludeAssemblyInfo,
RefBaseCollectionPaginationCountResponse = this.RefBaseCollectionPaginationCountResponse
};

Expand Down
2 changes: 2 additions & 0 deletions src/Microsoft.OpenApi.OData.Reader/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Microsoft.OpenApi.OData.OpenApiConvertSettings.ExpandDerivedTypesNavigationPrope
Microsoft.OpenApi.OData.OpenApiConvertSettings.ExpandDerivedTypesNavigationProperties.set -> void
Microsoft.OpenApi.OData.OpenApiConvertSettings.CustomXMLAttributesMapping.get -> System.Collections.Generic.Dictionary<string, string>
Microsoft.OpenApi.OData.OpenApiConvertSettings.CustomXMLAttributesMapping.set -> void
Microsoft.OpenApi.OData.OpenApiConvertSettings.IncludeAssemblyInfo.get -> bool
Microsoft.OpenApi.OData.OpenApiConvertSettings.IncludeAssemblyInfo.set -> void
Microsoft.OpenApi.OData.OpenApiConvertSettings.RefBaseCollectionPaginationCountResponse.get -> bool
Microsoft.OpenApi.OData.OpenApiConvertSettings.RefBaseCollectionPaginationCountResponse.set -> void
Microsoft.OpenApi.OData.OpenApiConvertSettings.RequireRestrictionAnnotationsToGenerateComplexPropertyPaths.get -> bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public void EmptyEdmModelToOpenApiJsonWorks(OpenApiSpecVersion specVersion)
IEdmModel model = EdmModelHelper.EmptyModel;
var openApiConvertSettings = new OpenApiConvertSettings();
openApiConvertSettings.OpenApiSpecVersion = specVersion;
openApiConvertSettings.IncludeAssemblyInfo = false;

// Act
string json = WriteEdmModelAsOpenApi(model, OpenApiFormat.Json, openApiConvertSettings);
Expand All @@ -64,7 +65,8 @@ public void EmptyEdmModelToOpenApiYamlWorks(OpenApiSpecVersion specVersion)
// Arrange
IEdmModel model = EdmModelHelper.EmptyModel;
var openApiConvertSettings = new OpenApiConvertSettings();
openApiConvertSettings.OpenApiSpecVersion = specVersion;
openApiConvertSettings.OpenApiSpecVersion = specVersion;
openApiConvertSettings.IncludeAssemblyInfo = false;

// Act
string yaml = WriteEdmModelAsOpenApi(model, OpenApiFormat.Yaml, openApiConvertSettings);
Expand All @@ -91,7 +93,8 @@ public void BasicEdmModelToOpenApiJsonWorks(OpenApiSpecVersion specVersion)
var openApiConvertSettings = new OpenApiConvertSettings
{
OpenApiSpecVersion = specVersion,
ShowSchemaExamples = true // test for schema examples
ShowSchemaExamples = true, // test for schema examples
IncludeAssemblyInfo = false
};

// Act
Expand Down Expand Up @@ -119,7 +122,8 @@ public void BasicEdmModelToOpenApiYamlWorks(OpenApiSpecVersion specVersion)
var openApiConvertSettings = new OpenApiConvertSettings
{
OpenApiSpecVersion = specVersion,
ShowSchemaExamples = true
ShowSchemaExamples = true,
IncludeAssemblyInfo = false
};

// Act
Expand Down Expand Up @@ -148,7 +152,8 @@ public void MultipleSchemasEdmModelToOpenApiJsonWorks(OpenApiSpecVersion specVer
{
OpenApiSpecVersion = specVersion,
ShowLinks = true, // test Links
ShowSchemaExamples = true
ShowSchemaExamples = true,
IncludeAssemblyInfo = false
};

// Act
Expand Down Expand Up @@ -177,7 +182,8 @@ public void MultipleSchemasEdmModelToOpenApiYamlWorks(OpenApiSpecVersion specVer
{
OpenApiSpecVersion = specVersion,
ShowLinks = true, // test Links
ShowSchemaExamples = true
ShowSchemaExamples = true,
IncludeAssemblyInfo = false
};

// Act
Expand Down Expand Up @@ -211,7 +217,8 @@ public void TripServiceMetadataToOpenApiJsonWorks(OpenApiSpecVersion specVersion
OpenApiSpecVersion = specVersion,
AddSingleQuotesForStringParameters = true,
AddEnumDescriptionExtension = true,
AppendBoundOperationsOnDerivedTypeCastSegments = true
AppendBoundOperationsOnDerivedTypeCastSegments = true,
IncludeAssemblyInfo = false
};
// Act
string json = WriteEdmModelAsOpenApi(model, OpenApiFormat.Json, settings);
Expand Down Expand Up @@ -245,7 +252,8 @@ public void TripServiceMetadataToOpenApiYamlWorks(OpenApiSpecVersion specVersion
OpenApiSpecVersion = specVersion,
AddSingleQuotesForStringParameters = true,
AddEnumDescriptionExtension = true,
AppendBoundOperationsOnDerivedTypeCastSegments = true
AppendBoundOperationsOnDerivedTypeCastSegments = true,
IncludeAssemblyInfo = false
};

// Act
Expand Down