Skip to content

Commit afd19c9

Browse files
committed
Remove remaining throw statements
Handle Example in MediaType and Parameter in V3
1 parent 532fb65 commit afd19c9

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

src/Microsoft.OpenApi.Readers/ParseNodes/OpenApiAnyConverter.cs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,6 @@ public static IOpenApiAny GetSpecificOpenApiAny(IOpenApiAny openApiAny, OpenApiS
151151
{
152152
return new OpenApiInteger(intValue);
153153
}
154-
else
155-
{
156-
throw new OpenApiException("The value is not compatible with the given type and format.");
157-
}
158154
}
159155

160156
if (type == "integer" && format == "int64")
@@ -163,10 +159,6 @@ public static IOpenApiAny GetSpecificOpenApiAny(IOpenApiAny openApiAny, OpenApiS
163159
{
164160
return new OpenApiLong(longValue);
165161
}
166-
else
167-
{
168-
throw new OpenApiException("The value is not compatible with the given type and format.");
169-
}
170162
}
171163

172164
if (type == "integer")
@@ -175,10 +167,6 @@ public static IOpenApiAny GetSpecificOpenApiAny(IOpenApiAny openApiAny, OpenApiS
175167
{
176168
return new OpenApiInteger(intValue);
177169
}
178-
else
179-
{
180-
throw new OpenApiException("The value is not compatible with the given type and format.");
181-
}
182170
}
183171

184172
if (type == "number" && format == "float")
@@ -187,10 +175,6 @@ public static IOpenApiAny GetSpecificOpenApiAny(IOpenApiAny openApiAny, OpenApiS
187175
{
188176
return new OpenApiFloat(floatValue);
189177
}
190-
else
191-
{
192-
throw new OpenApiException("The value is not compatible with the given type and format.");
193-
}
194178
}
195179

196180
if (type == "number" && format == "double" )

src/Microsoft.OpenApi.Readers/V3/OpenApiMediaTypeDeserializer.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@ internal static partial class OpenApiV3Deserializer
4949
{s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p,n))}
5050
};
5151

52+
private static readonly AnyFieldMap<OpenApiMediaType> _mediaTypeAnyFields = new AnyFieldMap<OpenApiMediaType>
53+
{
54+
{
55+
OpenApiConstants.Example,
56+
new AnyFieldMapParameter<OpenApiMediaType>(
57+
s => s.Example,
58+
(s, v) => s.Example = v,
59+
s => s.Schema)
60+
}
61+
};
62+
5263
public static OpenApiMediaType LoadMediaType(ParseNode node)
5364
{
5465
var mapNode = node.CheckMapNode(OpenApiConstants.Content);
@@ -62,6 +73,8 @@ public static OpenApiMediaType LoadMediaType(ParseNode node)
6273

6374
ParseMap(mapNode, mediaType, _mediaTypeFixedFields, _mediaTypePatternFields);
6475

76+
ProcessAnyFields(mapNode, mediaType, _mediaTypeAnyFields);
77+
6578
return mediaType;
6679
}
6780
}

src/Microsoft.OpenApi.Readers/V3/OpenApiParameterDeserializer.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,17 @@ internal static partial class OpenApiV3Deserializer
115115
{s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, LoadExtension(p,n))}
116116
};
117117

118+
private static readonly AnyFieldMap<OpenApiParameter> _parameterAnyFields = new AnyFieldMap<OpenApiParameter>
119+
{
120+
{
121+
OpenApiConstants.Example,
122+
new AnyFieldMapParameter<OpenApiParameter>(
123+
s => s.Example,
124+
(s, v) => s.Example = v,
125+
s => s.Schema)
126+
}
127+
};
128+
118129
public static OpenApiParameter LoadParameter(ParseNode node)
119130
{
120131
var mapNode = node.CheckMapNode("parameter");
@@ -128,6 +139,7 @@ public static OpenApiParameter LoadParameter(ParseNode node)
128139
var parameter = new OpenApiParameter();
129140

130141
ParseMap(mapNode, parameter, _parameterFixedFields, _parameterPatternFields);
142+
ProcessAnyFields(mapNode, parameter, _parameterAnyFields);
131143

132144
return parameter;
133145
}

0 commit comments

Comments
 (0)