Skip to content

Commit d42bd94

Browse files
committed
Resolved merge conflicts
2 parents a5667a0 + d1a05fa commit d42bd94

File tree

56 files changed

+471
-286
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+471
-286
lines changed

src/Microsoft.OpenApi.Readers/OpenApiDiagnostic.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT license.
33

44
using System.Collections.Generic;
5+
using Microsoft.OpenApi.Models;
56
using Microsoft.OpenApi.Readers.Interface;
67

78
namespace Microsoft.OpenApi.Readers
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using Microsoft.OpenApi.Exceptions;
10+
using Microsoft.OpenApi.Models;
11+
using SharpYaml;
12+
13+
namespace Microsoft.OpenApi.Readers
14+
{
15+
/// <summary>
16+
/// Error detected during the reading of some input and converting to an OpenApiDocument
17+
/// </summary>
18+
public class OpenApiReaderError : OpenApiError
19+
{
20+
21+
/// <summary>
22+
/// Creates error object from thrown exception
23+
/// </summary>
24+
/// <param name="exception"></param>
25+
public OpenApiReaderError(OpenApiException exception) : base(exception)
26+
{
27+
28+
}
29+
30+
/// <summary>
31+
/// Create error object from YAML SyntaxErrorException
32+
/// </summary>
33+
/// <param name="exception"></param>
34+
public OpenApiReaderError(SyntaxErrorException exception) : base(String.Empty, exception.Message)
35+
{
36+
37+
}
38+
}
39+
}

src/Microsoft.OpenApi.Readers/OpenApiStreamReader.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ private OpenApiDocument ParseStream(Stream input, OpenApiDiagnostic diagnostic)
133133
}
134134
catch (SyntaxErrorException ex)
135135
{
136-
diagnostic.Errors.Add(new OpenApiError(string.Empty, ex.Message));
136+
diagnostic.Errors.Add(new OpenApiReaderError(ex));
137137
return new OpenApiDocument();
138138
}
139139

@@ -152,8 +152,8 @@ private void ValidateDocument(OpenApiDiagnostic diagnostic, OpenApiDocument docu
152152
var errors = document.Validate(_settings.RuleSet);
153153
foreach (var item in errors)
154154
{
155-
diagnostic.Errors.Add(new OpenApiError(item.ErrorPath, item.ErrorMessage));
156-
}
155+
diagnostic.Errors.Add(item);
156+
}
157157
}
158158

159159

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ protected ParseNode(ParsingContext parsingContext, OpenApiDiagnostic diagnostic)
2424

2525
public OpenApiDiagnostic Diagnostic { get; }
2626

27-
public string DomainType { get; internal set; }
28-
2927
public MapNode CheckMapNode(string nodeName)
3028
{
3129
var mapNode = this as MapNode;
@@ -37,17 +35,6 @@ public MapNode CheckMapNode(string nodeName)
3735
return mapNode;
3836
}
3937

40-
internal string CheckRegex(string value, Regex versionRegex, string defaultValue)
41-
{
42-
if (!versionRegex.IsMatch(value))
43-
{
44-
Diagnostic.Errors.Add(new OpenApiError("", "Value does not match regex: " + versionRegex));
45-
return defaultValue;
46-
}
47-
48-
return value;
49-
}
50-
5138
public static ParseNode Create(ParsingContext context, OpenApiDiagnostic diagnostic, YamlNode node)
5239
{
5340
var listNode = node as YamlSequenceNode;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Linq;
77
using Microsoft.OpenApi.Any;
88
using Microsoft.OpenApi.Exceptions;
9+
using Microsoft.OpenApi.Models;
910
using SharpYaml.Serialization;
1011

1112
namespace Microsoft.OpenApi.Readers.ParseNodes
@@ -42,7 +43,7 @@ public void ParseField<T>(
4243
catch (OpenApiException ex)
4344
{
4445
ex.Pointer = Context.GetLocation();
45-
Diagnostic.Errors.Add(new OpenApiError(ex));
46+
Diagnostic.Errors.Add(new OpenApiReaderError(ex));
4647
}
4748
finally
4849
{
@@ -62,7 +63,7 @@ public void ParseField<T>(
6263
catch (OpenApiException ex)
6364
{
6465
ex.Pointer = Context.GetLocation();
65-
Diagnostic.Errors.Add(new OpenApiError(ex));
66+
Diagnostic.Errors.Add(new OpenApiReaderError(ex));
6667
}
6768
finally
6869
{

src/Microsoft.OpenApi.Readers/V2/OpenApiExternalDocsDeserializer.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@ internal static partial class OpenApiV2Deserializer
1616
private static readonly FixedFieldMap<OpenApiExternalDocs> _externalDocsFixedFields =
1717
new FixedFieldMap<OpenApiExternalDocs>
1818
{
19-
// $ref
2019
{
21-
"description", (o, n) =>
20+
OpenApiConstants.Description, (o, n) =>
2221
{
2322
o.Description = n.GetScalarValue();
2423
}
2524
},
2625
{
27-
"url", (o, n) =>
26+
OpenApiConstants.Url, (o, n) =>
2827
{
2928
o.Url = new Uri(n.GetScalarValue(), UriKind.RelativeOrAbsolute);
3029
}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,15 @@ private static void LoadStyle(OpenApiParameter p, string v)
154154
{
155155
switch (v)
156156
{
157-
// TODO: Handle "csv" for query / form parameter. The style should be Form, not Simple.
158157
case "csv":
159-
p.Style = ParameterStyle.Simple;
158+
if (p.In == ParameterLocation.Query)
159+
{
160+
p.Style = ParameterStyle.Form;
161+
}
162+
else
163+
{
164+
p.Style = ParameterStyle.Simple;
165+
}
160166
return;
161167
case "ssv":
162168
p.Style = ParameterStyle.SpaceDelimited;

src/Microsoft.OpenApi.Readers/V2/OpenApiResponseDeserializer.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,17 @@ internal static partial class OpenApiV2Deserializer
5151
private static void ProcessProduces(OpenApiResponse response, ParsingContext context)
5252
{
5353
var produces = context.GetFromTempStorage<List<string>>(TempStorageKeys.OperationProduces) ??
54-
context.GetFromTempStorage<List<string>>(TempStorageKeys.GlobalProduces) ?? new List<string> {"application/json"};
54+
context.GetFromTempStorage<List<string>>(TempStorageKeys.GlobalProduces) ?? new List<string>();
5555

5656
response.Content = new Dictionary<string, OpenApiMediaType>();
5757
foreach (var produce in produces)
5858
{
59-
var responseSchema = context.GetFromTempStorage<OpenApiSchema>(TempStorageKeys.ResponseSchema);
60-
if (responseSchema != null)
59+
var mediaType = new OpenApiMediaType
6160
{
62-
var mediaType = new OpenApiMediaType
63-
{
64-
Schema = responseSchema
65-
};
61+
Schema = context.GetFromTempStorage<OpenApiSchema>(TempStorageKeys.ResponseSchema)
62+
};
6663

67-
response.Content.Add(produce, mediaType);
68-
}
64+
response.Content.Add(produce, mediaType);
6965
}
7066
}
7167

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ internal static partial class OpenApiV2Deserializer
165165
{
166166
"default", (o, n) =>
167167
{
168-
o.Default = new OpenApiString(n.GetScalarValue());
168+
o.Default = n.CreateAny();
169169
}
170170
},
171171
{
Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

4+
using Microsoft.OpenApi.Extensions;
45
using Microsoft.OpenApi.Models;
56
using Microsoft.OpenApi.Readers.ParseNodes;
67

@@ -12,27 +13,45 @@ namespace Microsoft.OpenApi.Readers.V2
1213
/// </summary>
1314
internal static partial class OpenApiV2Deserializer
1415
{
16+
private static readonly FixedFieldMap<OpenApiTag> _tagFixedFields = new FixedFieldMap<OpenApiTag>
17+
{
18+
{
19+
OpenApiConstants.Name, (o, n) =>
20+
{
21+
o.Name = n.GetScalarValue();
22+
}
23+
},
24+
{
25+
OpenApiConstants.Description, (o, n) =>
26+
{
27+
o.Description = n.GetScalarValue();
28+
}
29+
},
30+
{
31+
OpenApiConstants.ExternalDocs, (o, n) =>
32+
{
33+
o.ExternalDocs = LoadExternalDocs(n);
34+
}
35+
}
36+
};
37+
38+
private static readonly PatternFieldMap<OpenApiTag> _tagPatternFields = new PatternFieldMap<OpenApiTag>
39+
{
40+
{s => s.StartsWith("x-"), (o, p, n) => o.AddExtension(p, n.CreateAny())}
41+
};
42+
1543
public static OpenApiTag LoadTag(ParseNode n)
1644
{
1745
var mapNode = n.CheckMapNode("tag");
1846

19-
var obj = new OpenApiTag();
47+
var domainObject = new OpenApiTag();
2048

21-
foreach (var node in mapNode)
49+
foreach (var propertyNode in mapNode)
2250
{
23-
var key = node.Name;
24-
switch (key)
25-
{
26-
case "description":
27-
obj.Description = node.Value.GetScalarValue();
28-
break;
29-
case "name":
30-
obj.Name = node.Value.GetScalarValue();
31-
break;
32-
}
51+
propertyNode.ParseField(domainObject, _tagFixedFields, _tagPatternFields);
3352
}
3453

35-
return obj;
54+
return domainObject;
3655
}
3756
}
3857
}

0 commit comments

Comments
 (0)