Skip to content

Commit f76fddf

Browse files
committed
clean up file
1 parent 6bb2546 commit f76fddf

File tree

1 file changed

+35
-45
lines changed

1 file changed

+35
-45
lines changed

src/Microsoft.OpenApi/Reader/V2/OpenApiSchemaDeserializer.cs

Lines changed: 35 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using System.Collections.Generic;
55
using System.Globalization;
6-
using Microsoft.OpenApi.Interfaces;
76
using Microsoft.OpenApi.Models;
87
using Microsoft.OpenApi.Extensions;
98
using Microsoft.OpenApi.Reader.ParseNodes;
@@ -17,116 +16,116 @@ namespace Microsoft.OpenApi.Reader.V2
1716
/// </summary>
1817
internal static partial class OpenApiV2Deserializer
1918
{
20-
private static readonly FixedFieldMap<OpenApiSchema> _schemaFixedFields = new()
19+
private static readonly FixedFieldMap<OpenApiSchema> _openApiSchemaFixedFields = new()
2120
{
2221
{
2322
"title",
24-
(o, n) => o.Title = n.GetScalarValue()
23+
(o, n, _) => o.Title = n.GetScalarValue()
2524
},
2625
{
2726
"multipleOf",
28-
(o, n) => o.MultipleOf = decimal.Parse(n.GetScalarValue(), NumberStyles.Float, CultureInfo.InvariantCulture)
27+
(o, n, _) => o.MultipleOf = decimal.Parse(n.GetScalarValue(), NumberStyles.Float, CultureInfo.InvariantCulture)
2928
},
3029
{
3130
"maximum",
32-
(o, n) => o.Maximum = ParserHelper.ParseDecimalWithFallbackOnOverflow(n.GetScalarValue(), decimal.MaxValue)
31+
(o, n,_) => o.Maximum = ParserHelper.ParseDecimalWithFallbackOnOverflow(n.GetScalarValue(), decimal.MaxValue)
3332
},
3433
{
3534
"exclusiveMaximum",
36-
(o, n) => o.ExclusiveMaximum = bool.Parse(n.GetScalarValue())
35+
(o, n, _) => o.ExclusiveMaximum = bool.Parse(n.GetScalarValue())
3736
},
3837
{
3938
"minimum",
40-
(o, n) => o.Minimum = ParserHelper.ParseDecimalWithFallbackOnOverflow(n.GetScalarValue(), decimal.MinValue)
39+
(o, n, _) => o.Minimum = ParserHelper.ParseDecimalWithFallbackOnOverflow(n.GetScalarValue(), decimal.MinValue)
4140
},
4241
{
4342
"exclusiveMinimum",
44-
(o, n) => o.ExclusiveMinimum = bool.Parse(n.GetScalarValue())
43+
(o, n, _) => o.ExclusiveMinimum = bool.Parse(n.GetScalarValue())
4544
},
4645
{
4746
"maxLength",
48-
(o, n) => o.MaxLength = int.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture)
47+
(o, n, _) => o.MaxLength = int.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture)
4948
},
5049
{
5150
"minLength",
52-
(o, n) => o.MinLength = int.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture)
51+
(o, n, _) => o.MinLength = int.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture)
5352
},
5453
{
5554
"pattern",
56-
(o, n) => o.Pattern = n.GetScalarValue()
55+
(o, n, _) => o.Pattern = n.GetScalarValue()
5756
},
5857
{
5958
"maxItems",
60-
(o, n) => o.MaxItems = int.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture)
59+
(o, n, _) => o.MaxItems = int.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture)
6160
},
6261
{
6362
"minItems",
64-
(o, n) => o.MinItems = int.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture)
63+
(o, n, _) => o.MinItems = int.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture)
6564
},
6665
{
6766
"uniqueItems",
68-
(o, n) => o.UniqueItems = bool.Parse(n.GetScalarValue())
67+
(o, n, _) => o.UniqueItems = bool.Parse(n.GetScalarValue())
6968
},
7069
{
7170
"maxProperties",
72-
(o, n) => o.MaxProperties = int.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture)
71+
(o, n, _) => o.MaxProperties = int.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture)
7372
},
7473
{
7574
"minProperties",
76-
(o, n) => o.MinProperties = int.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture)
75+
(o, n, _) => o.MinProperties = int.Parse(n.GetScalarValue(), CultureInfo.InvariantCulture)
7776
},
7877
{
7978
"required",
80-
(o, n) => o.Required = new HashSet<string>(n.CreateSimpleList(n2 => n2.GetScalarValue()))
79+
(o, n, _) => o.Required = new HashSet<string>(n.CreateSimpleList((n2, p) => n2.GetScalarValue()))
8180
},
8281
{
8382
"enum",
84-
(o, n) => o.Enum = n.CreateListOfAny()
83+
(o, n, _) => o.Enum = n.CreateListOfAny()
8584
},
8685

8786
{
8887
"type",
89-
(o, n) => o.Type = n.GetScalarValue()
88+
(o, n, _) => o.Type = n.GetScalarValue()
9089
},
9190
{
9291
"allOf",
93-
(o, n) => o.AllOf = n.CreateList(LoadSchema)
92+
(o, n, t) => o.AllOf = n.CreateList(LoadOpenApiSchema, t)
9493
},
9594
{
9695
"items",
97-
(o, n) => o.Items = LoadSchema(n)
96+
(o, n, _) => o.Items = LoadOpenApiSchema(n)
9897
},
9998
{
10099
"properties",
101-
(o, n) => o.Properties = n.CreateMap(LoadSchema)
100+
(o, n, t) => o.Properties = n.CreateMap(LoadOpenApiSchema, t)
102101
},
103102
{
104-
"additionalProperties", (o, n) =>
103+
"additionalProperties", (o, n, _) =>
105104
{
106105
if (n is ValueNode)
107106
{
108107
o.AdditionalPropertiesAllowed = bool.Parse(n.GetScalarValue());
109108
}
110109
else
111110
{
112-
o.AdditionalProperties = LoadSchema(n);
111+
o.AdditionalProperties = LoadOpenApiSchema(n);
113112
}
114113
}
115114
},
116115
{
117116
"description",
118-
(o, n) => o.Description = n.GetScalarValue()
117+
(o, n, _) => o.Description = n.GetScalarValue()
119118
},
120119
{
121120
"format",
122-
(o, n) => o.Format = n.GetScalarValue()
121+
(o, n, _) => o.Format = n.GetScalarValue()
123122
},
124123
{
125124
"default",
126-
(o, n) => o.Default = n.CreateAny()
125+
(o, n, _) => o.Default = n.CreateAny()
127126
},
128127
{
129-
"discriminator", (o, n) =>
128+
"discriminator", (o, n, _) =>
130129
{
131130
o.Discriminator = new()
132131
{
@@ -136,28 +135,28 @@ internal static partial class OpenApiV2Deserializer
136135
},
137136
{
138137
"readOnly",
139-
(o, n) => o.ReadOnly = bool.Parse(n.GetScalarValue())
138+
(o, n, _) => o.ReadOnly = bool.Parse(n.GetScalarValue())
140139
},
141140
{
142141
"xml",
143-
(o, n) => o.Xml = LoadXml(n)
142+
(o, n, _) => o.Xml = LoadXml(n)
144143
},
145144
{
146145
"externalDocs",
147-
(o, n) => o.ExternalDocs = LoadExternalDocs(n)
146+
(o, n, _) => o.ExternalDocs = LoadExternalDocs(n)
148147
},
149148
{
150149
"example",
151-
(o, n) => o.Example = n.CreateAny()
150+
(o, n, _) => o.Example = n.CreateAny()
152151
},
153152
};
154153

155-
private static readonly PatternFieldMap<OpenApiSchema> _schemaPatternFields = new PatternFieldMap<OpenApiSchema>
154+
private static readonly PatternFieldMap<OpenApiSchema> _openApiSchemaPatternFields = new PatternFieldMap<OpenApiSchema>
156155
{
157-
{s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p, n))}
156+
{s => s.StartsWith("x-"), (o, p, n, _) => o.AddExtension(p, LoadExtension(p, n))}
158157
};
159158

160-
public static OpenApiSchema LoadSchema(ParseNode node)
159+
public static OpenApiSchema LoadOpenApiSchema(ParseNode node, OpenApiDocument hostDocument = null)
161160
{
162161
var mapNode = node.CheckMapNode("schema");
163162

@@ -171,19 +170,10 @@ public static OpenApiSchema LoadSchema(ParseNode node)
171170

172171
foreach (var propertyNode in mapNode)
173172
{
174-
propertyNode.ParseField(schema, _schemaFixedFields, _schemaPatternFields);
173+
propertyNode.ParseField(schema, _openApiSchemaFixedFields, _openApiSchemaPatternFields);
175174
}
176175

177176
return schema;
178177
}
179-
180-
private static Dictionary<string, IOpenApiExtension> LoadExtensions(string value, IOpenApiExtension extension)
181-
{
182-
var extensions = new Dictionary<string, IOpenApiExtension>
183-
{
184-
{ value, extension }
185-
};
186-
return extensions;
187-
}
188178
}
189179
}

0 commit comments

Comments
 (0)