// ------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. // ------------------------------------------------------------ using System; using Microsoft.OpenApi.OData.Common; using Microsoft.OpenApi.OData.Edm; using Microsoft.OpenApi.OData.Extensions; namespace Microsoft.OpenApi.OData { /// /// Convert settings. /// public class OpenApiConvertSettings { /// /// Gets/sets the service root. /// public Uri ServiceRoot { get; set; } = new Uri("http://localhost"); /// /// Gets/sets the metadata version. /// public Version Version { get; set; } = new Version(1, 0, 1); /// /// Gets/set a value indicating whether to output key as segment path. /// public bool? EnableKeyAsSegment { get; set; } /// /// Gets/set a value indicating whether to output un-qualified operation call. /// public bool EnableUnqualifiedCall { get; set; } /// /// Gets/set a value indicating whether to output the path for Edm operation. /// public bool EnableOperationPath { get; set; } = true; /// /// Gets/set a value indicating whether to output the path for Edm operation import. /// public bool EnableOperationImportPath { get; set; } = true; /// /// Gets/set a value indicating whether to output the path for Edm navigation property. /// public bool EnableNavigationPropertyPath { get; set; } = true; /// /// Gets/set a value indicating the tags name depth. /// public int TagDepth { get; set; } = 4; /// /// Gets/set a value indicating whether we prefix entity type name before single key. /// public bool PrefixEntityTypeNameBeforeKey { get; set; } = false; /// /// Gets/sets a value indicating whether the version of openApi to serialize to is v2. /// Currently only impacts nullable references for EdmTypeSchemaGenerator /// public OpenApiSpecVersion OpenApiSpecVersion { get; set; } = OpenApiSpecVersion.OpenApi3_0; /// /// Gets/sets a value indicating to set the OperationId on Open API operation. /// public bool EnableOperationId { get; set; } = true; /// /// Gets/sets a value indicating whether to output the binding function as Uri escape function if applied the UriEscapeFunction term. /// public bool EnableUriEscapeFunctionCall { get; set; } = false; /// /// Gets/sets a value indicating whether to verify the edm model before converter. /// public bool VerifyEdmModel { get; set; } /// /// Gets/sets a value indicating whether the server is IEEE754 compatible. /// If it is IEEE754Compatible, the server will write quoted string for INT64 and decimal to prevent data loss; /// otherwise keep number without quotes. /// public bool IEEE754Compatible { get; set; } /// /// Gets or sets $Top example value. /// public int TopExample { get; set; } = 50; /// /// Gets/sets a value indicating whether or not to allow paging a collection of entities. /// public bool EnablePagination { get; set; } /// /// Gets/sets a value that specifies the name of the operation for retrieving the next page in a collection of entities. /// public string PageableOperationName { get; set; } = "listMore"; /// /// Gets/sets a value indicating whether or not to allow discriminator value support. /// public bool EnableDiscriminatorValue { get; set; } = false; /// /// Gets/sets a value indicating whether or not to show the derived types of a base type reference in the responses payload. /// public bool EnableDerivedTypesReferencesForResponses { get; set; } = false; /// /// Gets/sets a value indicating whether or not to show the derived types of a base type reference in the requestBody payload. /// public bool EnableDerivedTypesReferencesForRequestBody { get; set; } = false; /// /// Gets/sets a value that specifies a prefix to be prepended to all generated paths. /// public string PathPrefix { get { if (RoutePathPrefixProvider != null) { return RoutePathPrefixProvider.PathPrefix; } return null; } set { if (string.IsNullOrWhiteSpace(value)) { throw Error.ArgumentNullOrEmpty("value"); } RoutePathPrefixProvider = new ODataRoutePathPrefixProvider { PathPrefix = value }; } } /// /// Gets/sets a route path prefix provider. /// public IODataRoutePathPrefixProvider RoutePathPrefixProvider { get; set; } /// /// Gets/Sets a value indicating whether or not to show the OpenAPI links in the responses. /// public bool ShowLinks { get; set; } = false; /// /// Gets/Sets a value indicating whether or not to show schema examples. /// public bool ShowSchemaExamples { get; set; } = false; /// /// Gets/Sets a value indicating whether or not to require the /// Validation.DerivedTypeConstraint to be applied to NavigationSources /// to bind operations of derived types to them. /// public bool RequireDerivedTypesConstraintForBoundOperations { get; set; } = false; /// /// Gets/sets a value indicating whether or not to show the root path of the described API. /// public bool ShowRootPath { get; set; } = false; /// /// Gets/sets a value indicating whether or not to show the group path extension. /// public bool ShowMsDosGroupPath { get; set; } = true; /// /// Gets/sets a the path provider. /// public IODataPathProvider PathProvider { get; set; } /// /// Gets/sets a value indicating whether or not add OData $count segments in the description for collections. /// public bool EnableDollarCountPath { get; set; } = true; internal OpenApiConvertSettings Clone() { var newSettings = new OpenApiConvertSettings { ServiceRoot = this.ServiceRoot, Version = this.Version, EnableKeyAsSegment = this.EnableKeyAsSegment, EnableUnqualifiedCall = this.EnableUnqualifiedCall, EnableOperationPath = this.EnableOperationPath, EnableOperationImportPath = this.EnableOperationImportPath, EnableNavigationPropertyPath = this.EnableNavigationPropertyPath, TagDepth = this.TagDepth, PrefixEntityTypeNameBeforeKey = this.PrefixEntityTypeNameBeforeKey, OpenApiSpecVersion = this.OpenApiSpecVersion, EnableOperationId = this.EnableOperationId, VerifyEdmModel = this.VerifyEdmModel, IEEE754Compatible = this.IEEE754Compatible, TopExample = this.TopExample, EnableUriEscapeFunctionCall = this.EnableUriEscapeFunctionCall, EnablePagination = this.EnablePagination, PageableOperationName = this.PageableOperationName, EnableDiscriminatorValue = this.EnableDiscriminatorValue, EnableDerivedTypesReferencesForResponses = this.EnableDerivedTypesReferencesForResponses, EnableDerivedTypesReferencesForRequestBody = this.EnableDerivedTypesReferencesForRequestBody, RoutePathPrefixProvider = this.RoutePathPrefixProvider, ShowLinks = this.ShowLinks, RequireDerivedTypesConstraintForBoundOperations = this.RequireDerivedTypesConstraintForBoundOperations, ShowSchemaExamples = this.ShowSchemaExamples, ShowRootPath = this.ShowRootPath, PathProvider = this.PathProvider, EnableDollarCountPath = this.EnableDollarCountPath, }; return newSettings; } } }