-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathOpenApiConvertSettings.cs
284 lines (241 loc) · 12.4 KB
/
OpenApiConvertSettings.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
// ------------------------------------------------------------
// 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
{
/// <summary>
/// Convert settings.
/// </summary>
public class OpenApiConvertSettings
{
/// <summary>
/// Gets/sets the service root.
/// </summary>
public Uri ServiceRoot { get; set; } = new Uri("http://localhost");
/// <summary>
/// Gets/sets the metadata version.
/// </summary>
public Version Version { get; set; } = new Version(1, 0, 1);
/// <summary>
/// Gets/set a value indicating whether to output key as segment path.
/// </summary>
public bool? EnableKeyAsSegment { get; set; }
/// <summary>
/// Gets/set a value indicating whether to output un-qualified operation call.
/// </summary>
public bool EnableUnqualifiedCall { get; set; }
/// <summary>
/// Gets/set a value indicating whether to output the path for Edm operation.
/// </summary>
public bool EnableOperationPath { get; set; } = true;
/// <summary>
/// Gets/set a value indicating whether to output the path for Edm operation import.
/// </summary>
public bool EnableOperationImportPath { get; set; } = true;
/// <summary>
/// Gets/set a value indicating whether to output the path for Edm navigation property.
/// </summary>
public bool EnableNavigationPropertyPath { get; set; } = true;
/// <summary>
/// Gets/set a value indicating the tags name depth.
/// </summary>
public int TagDepth { get; set; } = 4;
/// <summary>
/// Gets/set a value indicating whether we prefix entity type name before single key.
/// </summary>
public bool PrefixEntityTypeNameBeforeKey { get; set; } = false;
/// <summary>
/// Gets/sets a value indicating whether the version of openApi to serialize to is v2.
/// Currently only impacts nullable references for EdmTypeSchemaGenerator
/// </summary>
public OpenApiSpecVersion OpenApiSpecVersion { get; set; } = OpenApiSpecVersion.OpenApi3_0;
/// <summary>
/// Gets/sets a value indicating to set the OperationId on Open API operation.
/// </summary>
public bool EnableOperationId { get; set; } = true;
/// <summary>
/// Gets/sets a value indicating whether to output the binding function as Uri escape function if applied the UriEscapeFunction term.
/// </summary>
public bool EnableUriEscapeFunctionCall { get; set; } = false;
/// <summary>
/// Gets/sets a value indicating whether to verify the edm model before converter.
/// </summary>
public bool VerifyEdmModel { get; set; }
/// <summary>
/// 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.
/// </summary>
public bool IEEE754Compatible { get; set; }
/// <summary>
/// Gets or sets $Top example value.
/// </summary>
public int TopExample { get; set; } = 50;
/// <summary>
/// Gets/sets a value indicating whether or not to allow paging a collection of entities.
/// </summary>
public bool EnablePagination { get; set; }
/// <summary>
/// Gets/sets a value that specifies the name of the operation for retrieving the next page in a collection of entities.
/// </summary>
public string PageableOperationName { get; set; } = "listMore";
/// <summary>
/// Gets/sets a value indicating whether or not to allow discriminator value support.
/// </summary>
public bool EnableDiscriminatorValue { get; set; } = false;
/// <summary>
/// Gets/sets a value indicating whether or not to show the derived types of a base type reference in the responses payload.
/// </summary>
public bool EnableDerivedTypesReferencesForResponses { get; set; } = false;
/// <summary>
/// Gets/sets a value indicating whether or not to show the derived types of a base type reference in the requestBody payload.
/// </summary>
public bool EnableDerivedTypesReferencesForRequestBody { get; set; } = false;
/// <summary>
/// Gets/sets a value that specifies a prefix to be prepended to all generated paths.
/// </summary>
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
};
}
}
/// <summary>
/// Gets/sets a route path prefix provider.
/// </summary>
public IODataRoutePathPrefixProvider RoutePathPrefixProvider { get; set; }
/// <summary>
/// Gets/Sets a value indicating whether or not to show the OpenAPI links in the responses.
/// </summary>
public bool ShowLinks { get; set; } = false;
/// <summary>
/// Gets/Sets a value indicating whether or not to show schema examples.
/// </summary>
public bool ShowSchemaExamples { get; set; } = false;
/// <summary>
/// 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.
/// </summary>
public bool RequireDerivedTypesConstraintForBoundOperations { get; set; } = false;
/// <summary>
/// Gets/sets a value indicating whether or not to show the root path of the described API.
/// </summary>
public bool ShowRootPath { get; set; } = false;
/// <summary>
/// Gets/sets a value indicating whether or not to show the group path extension.
/// </summary>
public bool ShowMsDosGroupPath { get; set; } = true;
/// <summary>
/// Gets/sets a the path provider.
/// </summary>
public IODataPathProvider PathProvider { get; set; }
/// <summary>
/// Gets/sets a value indicating whether or not add OData $count segments in the description for collections.
/// </summary>
public bool EnableDollarCountPath { get; set; } = true;
/// <summary>
/// Gets/sets a value indicating whether or not single quotes surrounding string parameters in url templates should be added.
/// </summary>
public bool AddSingleQuotesForStringParameters { get; set; } = false;
/// <summary>
/// Gets/sets a value indicating whether or not to include the OData type cast segments.
/// </summary>
public bool EnableODataTypeCast { get; set; } = true;
/// <summary>
/// Gets/sets a value indicating whether or not to require a derived types constraint to include the OData type cast segments.
/// </summary>
public bool RequireDerivedTypesConstraintForODataTypeCastSegments { get; set; } = true;
/// <summary>
/// Gets/sets a value indicating whether or not to set the deprecated tag for the operation when a revision is present as well as the "x-ms-deprecation" extension with additional information.
/// </summary>
public bool EnableDeprecationInformation { get; set; } = true;
/// <summary>
/// Gets/sets a value indicating whether or not to add a "x-ms-enum" extension to the enum type schema for V2 and V3 descriptions.
/// V3.1 will won't add the extension.
/// https://github.com/Azure/autorest/blob/main/docs/extensions/readme.md#x-ms-enum
/// </summary>
public bool AddEnumDescriptionExtension { get; set; } = false;
/// <summary>
/// Gets/sets a value indicating whether the error responses should be described as a default response or as 4XX and 5XX error responses.
/// </summary>
public bool ErrorResponsesAsDefault { get; set; } = true;
/// <summary>
/// Gets/Sets the name of the complex type to look for in the main namespace to use as the inner error type.
/// </summary>
public string InnerErrorComplexTypeName { get; set; } = "InnerError";
/// <summary>
/// Gets/Sets a value indicating whether path parameters should be declared on path item object.
/// If true, path parameters will be declared on the path item object, otherwise they
/// will be declared on the operation object.
/// </summary>
public bool DeclarePathParametersOnPathItem { get; set; } = false;
/// <summary>
/// Gets/Sets a value indicating whether or not to use restrictions annotations to generate paths for complex properties.
/// </summary>
public bool RequireRestrictionAnnotationsToGenerateComplexPropertyPaths { 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,
AddSingleQuotesForStringParameters = this.AddSingleQuotesForStringParameters,
EnableODataTypeCast = this.EnableODataTypeCast,
RequireDerivedTypesConstraintForODataTypeCastSegments = this.RequireDerivedTypesConstraintForODataTypeCastSegments,
EnableDeprecationInformation = this.EnableDeprecationInformation,
AddEnumDescriptionExtension = this.AddEnumDescriptionExtension,
ErrorResponsesAsDefault = this.ErrorResponsesAsDefault,
InnerErrorComplexTypeName = this.InnerErrorComplexTypeName,
RequireRestrictionAnnotationsToGenerateComplexPropertyPaths = this.RequireRestrictionAnnotationsToGenerateComplexPropertyPaths
};
return newSettings;
}
}
}