Skip to content

Commit ab7602e

Browse files
committed
Replace type with the corresponding JsonSchemaType enum value
1 parent 92d7721 commit ab7602e

25 files changed

+172
-315
lines changed

src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiEdmTypeSchemaGenerator.cs

Lines changed: 52 additions & 171 deletions
Large diffs are not rendered by default.

src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiErrorSchemaGenerator.cs

Lines changed: 15 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// ------------------------------------------------------------
1+
// ------------------------------------------------------------
22
// Copyright (c) Microsoft Corporation. All rights reserved.
33
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
44
// ------------------------------------------------------------
@@ -68,7 +68,7 @@ public static OpenApiSchema CreateErrorSchema(string rootNamespaceName)
6868
{
6969
return new OpenApiSchema
7070
{
71-
Type = "object",
71+
Type = JsonSchemaType.Object,
7272
Required = new HashSet<string>
7373
{
7474
"error"
@@ -77,15 +77,7 @@ public static OpenApiSchema CreateErrorSchema(string rootNamespaceName)
7777
{
7878
{
7979
"error",
80-
new OpenApiSchema
81-
{
82-
UnresolvedReference = true,
83-
Reference = new OpenApiReference
84-
{
85-
Type = ReferenceType.Schema,
86-
Id = $"{rootNamespaceName}{MainErrorClassName}"
87-
}
88-
}
80+
new OpenApiSchemaReference($"{rootNamespaceName}{MainErrorClassName}", null)
8981
}
9082
}
9183
};
@@ -111,7 +103,7 @@ public static OpenApiSchema CreateInnerErrorSchema(ODataContext context)
111103

112104
return new OpenApiSchema
113105
{
114-
Type = "object",
106+
Type = JsonSchemaType.Object,
115107
Description = "The structure of this object is service-specific"
116108
};
117109
}
@@ -125,50 +117,34 @@ public static OpenApiSchema CreateErrorMainSchema(string rootNamespaceName)
125117
{
126118
return new OpenApiSchema
127119
{
128-
Type = "object",
120+
Type = JsonSchemaType.Object,
129121
Required = new HashSet<string>
130122
{
131123
"code", "message"
132124
},
133125
Properties = new Dictionary<string, OpenApiSchema>
134126
{
135127
{
136-
"code", new OpenApiSchema { Type = "string", Nullable = false }
128+
"code", new OpenApiSchema { Type = JsonSchemaType.String, Nullable = false }
137129
},
138130
{
139-
"message", new OpenApiSchema { Type = "string", Nullable = false, Extensions = new Dictionary<string, IOpenApiExtension>
131+
"message", new OpenApiSchema { Type = JsonSchemaType.String, Nullable = false, Extensions = new Dictionary<string, IOpenApiExtension>
140132
{ { OpenApiPrimaryErrorMessageExtension.Name, new OpenApiPrimaryErrorMessageExtension { IsPrimaryErrorMessage = true } } } }
141133
},
142134
{
143-
"target", new OpenApiSchema { Type = "string", Nullable = true }
135+
"target", new OpenApiSchema { Type = JsonSchemaType.String, Nullable = true }
144136
},
145137
{
146138
"details",
147139
new OpenApiSchema
148140
{
149-
Type = "array",
150-
Items = new OpenApiSchema
151-
{
152-
UnresolvedReference = true,
153-
Reference = new OpenApiReference
154-
{
155-
Type = ReferenceType.Schema,
156-
Id = $"{rootNamespaceName}{ErrorDetailsClassName}"
157-
}
158-
}
141+
Type = JsonSchemaType.Array,
142+
Items = new OpenApiSchemaReference($"{rootNamespaceName}{ErrorDetailsClassName}", null)
159143
}
160144
},
161145
{
162146
"innerError",
163-
new OpenApiSchema
164-
{
165-
UnresolvedReference = true,
166-
Reference = new OpenApiReference
167-
{
168-
Type = ReferenceType.Schema,
169-
Id = $"{rootNamespaceName}{InnerErrorClassName}"
170-
}
171-
}
147+
new OpenApiSchemaReference($"{rootNamespaceName}{InnerErrorClassName}", null)
172148
}
173149
}
174150
};
@@ -182,21 +158,21 @@ public static OpenApiSchema CreateErrorDetailSchema()
182158
{
183159
return new OpenApiSchema
184160
{
185-
Type = "object",
161+
Type = JsonSchemaType.Object,
186162
Required = new HashSet<string>
187163
{
188164
"code", "message"
189165
},
190166
Properties = new Dictionary<string, OpenApiSchema>
191167
{
192168
{
193-
"code", new OpenApiSchema { Type = "string", Nullable = false, }
169+
"code", new OpenApiSchema { Type = JsonSchemaType.String, Nullable = false, }
194170
},
195171
{
196-
"message", new OpenApiSchema { Type = "string", Nullable = false, }
172+
"message", new OpenApiSchema { Type = JsonSchemaType.String, Nullable = false, }
197173
},
198174
{
199-
"target", new OpenApiSchema { Type = "string", Nullable = true, }
175+
"target", new OpenApiSchema { Type = JsonSchemaType.String, Nullable = true, }
200176
}
201177
}
202178
};

src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiParameterGenerator.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ public static IList<OpenApiParameter> CreateParameters(this ODataContext context
103103
{
104104
Schema = new OpenApiSchema
105105
{
106-
Type = "array",
106+
Type = JsonSchemaType.Array,
107107
Items = new OpenApiSchema
108108
{
109-
Type = "string"
109+
Type = JsonSchemaType.String
110110
},
111111

112112
// These Parameter Objects optionally can contain the field description,
@@ -641,11 +641,11 @@ public static OpenApiParameter CreateOrderBy(this ODataContext context, IEdmVoca
641641
Description = "Order items by property values",
642642
Schema = new OpenApiSchema
643643
{
644-
Type = "array",
644+
Type = JsonSchemaType.Array,
645645
UniqueItems = true,
646646
Items = new OpenApiSchema
647647
{
648-
Type = "string",
648+
Type = JsonSchemaType.String,
649649
Enum = context.Settings.UseStringArrayForQueryOptionsSchema ? null : orderByItems
650650
}
651651
},
@@ -747,11 +747,11 @@ public static OpenApiParameter CreateSelect(this ODataContext context, IEdmVocab
747747
Description = "Select properties to be returned",
748748
Schema = new OpenApiSchema
749749
{
750-
Type = "array",
750+
Type = JsonSchemaType.Array,
751751
UniqueItems = true,
752752
Items = new OpenApiSchema
753753
{
754-
Type = "string",
754+
Type = JsonSchemaType.String,
755755
Enum = context.Settings.UseStringArrayForQueryOptionsSchema ? null : selectItems
756756
}
757757
},
@@ -851,11 +851,11 @@ public static OpenApiParameter CreateExpand(this ODataContext context, IEdmVocab
851851
Description = "Expand related entities",
852852
Schema = new OpenApiSchema
853853
{
854-
Type = "array",
854+
Type = JsonSchemaType.Array,
855855
UniqueItems = true,
856856
Items = new OpenApiSchema
857857
{
858-
Type = "string",
858+
Type = JsonSchemaType.String,
859859
Enum = context.Settings.UseStringArrayForQueryOptionsSchema ? null : expandItems
860860
}
861861
},
@@ -874,10 +874,10 @@ private static OpenApiParameter CreateTop(int topExample)
874874
Description = "Show only the first n items",
875875
Schema = new OpenApiSchema
876876
{
877-
Type = "integer",
877+
Type = JsonSchemaType.Integer,
878878
Minimum = 0,
879879
},
880-
Example = new OpenApiInteger(topExample),
880+
Example = topExample,
881881
Style = ParameterStyle.Form,
882882
Explode = false
883883
};
@@ -893,7 +893,7 @@ private static OpenApiParameter CreateSkip()
893893
Description = "Skip the first n items",
894894
Schema = new OpenApiSchema
895895
{
896-
Type = "integer",
896+
Type = JsonSchemaType.Integer,
897897
Minimum = 0,
898898
},
899899
Style = ParameterStyle.Form,
@@ -911,7 +911,7 @@ private static OpenApiParameter CreateCount()
911911
Description = "Include count of items",
912912
Schema = new OpenApiSchema
913913
{
914-
Type = "boolean"
914+
Type = JsonSchemaType.Boolean
915915
},
916916
Style = ParameterStyle.Form,
917917
Explode = false
@@ -928,7 +928,7 @@ private static OpenApiParameter CreateFilter()
928928
Description = "Filter items by property values",
929929
Schema = new OpenApiSchema
930930
{
931-
Type = "string"
931+
Type = JsonSchemaType.String
932932
},
933933
Style = ParameterStyle.Form,
934934
Explode = false
@@ -945,7 +945,7 @@ private static OpenApiParameter CreateSearch()
945945
Description = "Search items by search phrases",
946946
Schema = new OpenApiSchema
947947
{
948-
Type = "string"
948+
Type = JsonSchemaType.String
949949
},
950950
Style = ParameterStyle.Form,
951951
Explode = false

src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiRequestBodyGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// ------------------------------------------------------------
1+
// ------------------------------------------------------------
22
// Copyright (c) Microsoft Corporation. All rights reserved.
33
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
44
// ------------------------------------------------------------
@@ -63,7 +63,7 @@ public static OpenApiRequestBody CreateRequestBody(this ODataContext context, IE
6363

6464
OpenApiSchema parametersSchema = new OpenApiSchema
6565
{
66-
Type = "object",
66+
Type = JsonSchemaType.Object,
6767
Properties = new Dictionary<string, OpenApiSchema>()
6868
};
6969

src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiResponseGenerator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public static OpenApiResponse CreateOperationResponse(this ODataContext context,
163163
{
164164
OpenApiSchema baseSchema = new()
165165
{
166-
Type = Constants.ObjectType,
166+
Type = JsonSchemaType.Object,
167167
Properties = new Dictionary<string, OpenApiSchema>
168168
{
169169
{
@@ -207,15 +207,15 @@ public static OpenApiResponse CreateOperationResponse(this ODataContext context,
207207

208208
schema.Title = operation.ReturnType.Definition.AsElementType() is not IEdmEntityType entityType
209209
? null : $"Collection of {entityType.Name}";
210-
schema.Type = "object";
210+
schema.Type = JsonSchemaType.Object;
211211
}
212212
else if (operation.ReturnType.IsPrimitive())
213213
{
214214
// A property or operation response that is of a primitive type is represented as an object with a single name/value pair,
215215
// whose name is value and whose value is a primitive value.
216216
schema = new OpenApiSchema
217217
{
218-
Type = "object",
218+
Type = JsonSchemaType.Object,
219219
Properties = new Dictionary<string, OpenApiSchema>
220220
{
221221
{

0 commit comments

Comments
 (0)