Skip to content

Commit 1e735f4

Browse files
committed
Fixed merge conflict
2 parents 8b95987 + b94c307 commit 1e735f4

File tree

50 files changed

+790
-246
lines changed

Some content is hidden

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

50 files changed

+790
-246
lines changed

Microsoft.OpenApi.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{E546B92F-20A
2323
EndProject
2424
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{6357D7FD-2DE4-4900-ADB9-ABC37052040A}"
2525
EndProject
26-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.OpenApi.SmokeTests", "test\Microsoft.OpenApi.SmokeTests\Microsoft.OpenApi.SmokeTests.csproj", "{AD79B61D-88CF-497C-9ED5-41AE3867C5AC}"
26+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.OpenApi.SmokeTests", "test\Microsoft.OpenApi.SmokeTests\Microsoft.OpenApi.SmokeTests.csproj", "{AD79B61D-88CF-497C-9ED5-41AE3867C5AC}"
2727
EndProject
2828
Global
2929
GlobalSection(SolutionConfigurationPlatforms) = preSolution

README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
![Category overview screenshot](docs/images/oainet.png "Microsoft + OpenAPI = Love")
22

3-
# OpenAPI.NET [Preview]
4-
[Disclaimer: This repository is in a preview state. Expect to see some iterating as we work towards the final release candidate slated for early 2018. Feedback is welcome!]
3+
# OpenAPI.NET
54

65
The **OpenAPI.NET** SDK contains a useful object model for OpenAPI documents in .NET along with common serializers to extract raw OpenAPI JSON and YAML documents from the model.
76

@@ -14,12 +13,12 @@ Project Objectives
1413
- Provide OpenAPI description writers for both V2 and V3 specification formats.
1514
- Enable developers to create Readers that translate different data formats into OpenAPI descriptions.
1615

17-
# Readers
18-
The OpenAPI.NET project holds the base object model for representing OpenAPI descriptions as .NET objects. Translation for different data types into this object model is handled by reading raw JSON/YAML or from individual "Readers", a number of which are in the works.
16+
# Processors
17+
The OpenAPI.NET project holds the base object model for representing OpenAPI documents as .NET objects. Some developers have found the need to write processors that convert other data formats into this OpenAPI.NET object model. We'd like to curate that list of processors in this section of the readme.
1918

20-
The base JSON and YAML Readers are built into this project. Below is the list of supported "reader" projects.
19+
The base JSON and YAML processors are built into this project. Below is the list of the other supported processor projects.
2120

22-
- .NET Comment Reader: [Coming Soon]
21+
- [**C# Comment / Annotation Processor**](https://github.com/Microsoft/OpenAPI.NET.CSharpAnnotations) : Converts standard .NET annotations ( /// comments ) emitted from your build (MSBuild.exe) into OpenAPI.NET document object.
2322

2423
# Example Usage
2524

src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
<PropertyGroup>
33
<TargetFrameworks>net46; netstandard2.0</TargetFrameworks>
44
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
5-
5+
<PackageIconUrl>http://go.microsoft.com/fwlink/?LinkID=288890</PackageIconUrl>
66
<PackageProjectUrl>https://github.com/Microsoft/OpenAPI.NET</PackageProjectUrl>
77
<PackageLicenseUrl>https://raw.githubusercontent.com/Microsoft/OpenAPI.NET/master/LICENSE</PackageLicenseUrl>
88
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
99
<Authors>Microsoft</Authors>
1010
<Company>Microsoft</Company>
1111
<Title>Microsoft.OpenApi.Readers</Title>
1212
<PackageId>Microsoft.OpenApi.Readers</PackageId>
13-
<Version>1.0.0-beta016</Version>
13+
<Version>1.0.0</Version>
1414
<Description>OpenAPI.NET Readers for JSON and YAML documents</Description>
1515
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
1616
<PackageTags>OpenAPI .NET</PackageTags>

src/Microsoft.OpenApi.Readers/OpenApiReaderSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class OpenApiReaderSettings
4747
/// <summary>
4848
/// Rules to use for validating OpenAPI specification. If none are provided a default set of rules are applied.
4949
/// </summary>
50-
public ValidationRuleSet RuleSet { get; set; }
50+
public ValidationRuleSet RuleSet { get; set; } = ValidationRuleSet.GetDefaultRuleSet();
5151

5252
}
5353
}

src/Microsoft.OpenApi.Readers/OpenApiStreamReader.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,12 @@ private OpenApiDocument ParseStream(Stream input, OpenApiDiagnostic diagnostic)
149149
private void ValidateDocument(OpenApiDiagnostic diagnostic, OpenApiDocument document)
150150
{
151151
// Validate the document
152-
var errors = document.Validate(_settings.RuleSet);
153-
foreach (var item in errors)
152+
if (_settings.RuleSet != null && _settings.RuleSet.Rules.Count > 0)
154153
{
155-
diagnostic.Errors.Add(item);
156-
}
154+
var errors = document.Validate(_settings.RuleSet);
155+
diagnostic.Errors.Add(errors);
156+
}
157+
return document;
157158
}
158159

159160
/// <summary>

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public override string GetScalarValue()
2929
}
3030

3131
return scalarNode.Value;
32-
}
32+
}
3333

3434
/// <summary>
3535
/// Create a <see cref="IOpenApiPrimitive"/>
@@ -59,11 +59,18 @@ public override IOpenApiAny CreateAny()
5959
return new OpenApiInteger(intValue);
6060
}
6161

62+
if (long.TryParse(value, out var longValue))
63+
{
64+
return
65+
new OpenApiLong(
66+
longValue);
67+
}
68+
6269
if (double.TryParse(value, out var dblValue))
6370
{
6471
return
6572
new OpenApiDouble(
66-
dblValue); // Note(darrmi): This may be better as decimal. Further investigation required.
73+
dblValue); // Note(darrmi): This may be better as decimal. Further investigation required.
6774
}
6875

6976
if (DateTimeOffset.TryParse(value, out var datetimeValue))
@@ -75,4 +82,4 @@ public override IOpenApiAny CreateAny()
7582
return new OpenApiString(value);
7683
}
7784
}
78-
}
85+
}

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

Lines changed: 101 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

4+
using System;
5+
using Microsoft.OpenApi.Any;
46
using Microsoft.OpenApi.Extensions;
57
using Microsoft.OpenApi.Models;
8+
using Microsoft.OpenApi.Readers.Exceptions;
69
using Microsoft.OpenApi.Readers.ParseNodes;
710

811
namespace Microsoft.OpenApi.Readers.V2
@@ -22,41 +25,107 @@ internal static partial class OpenApiV2Deserializer
2225
}
2326
},
2427
{
25-
"required", (o, n) =>
28+
"type", (o, n) =>
2629
{
27-
o.Required = bool.Parse(n.GetScalarValue());
30+
GetOrCreateSchema(o).Type = n.GetScalarValue();
2831
}
2932
},
3033
{
31-
"deprecated", (o, n) =>
34+
"format", (o, n) =>
3235
{
33-
o.Deprecated = bool.Parse(n.GetScalarValue());
36+
GetOrCreateSchema(o).Format = n.GetScalarValue();
3437
}
3538
},
3639
{
37-
"allowReserved", (o, n) =>
40+
"items", (o, n) =>
3841
{
39-
o.AllowReserved = bool.Parse(n.GetScalarValue());
42+
GetOrCreateSchema(o).Items = LoadSchema(n);
4043
}
4144
},
4245
{
43-
"style", (o, n) =>
46+
"collectionFormat", (o, n) =>
4447
{
45-
o.Style = n.GetScalarValue().GetEnumFromDisplayName<ParameterStyle>();
48+
LoadStyle(o, n.GetScalarValue());
4649
}
4750
},
4851
{
49-
"type", (o, n) =>
52+
"default", (o, n) =>
5053
{
51-
GetOrCreateSchema(o).Type = n.GetScalarValue();
54+
GetOrCreateSchema(o).Default = n.CreateAny();
55+
}
56+
},
57+
{
58+
"maximum", (o, n) =>
59+
{
60+
GetOrCreateSchema(o).Maximum = decimal.Parse(n.GetScalarValue());
5261
}
5362
},
5463
{
55-
"format", (o, n) =>
64+
"exclusiveMaximum", (o, n) =>
5665
{
57-
GetOrCreateSchema(o).Format = n.GetScalarValue();
66+
GetOrCreateSchema(o).ExclusiveMaximum = bool.Parse(n.GetScalarValue());
67+
}
68+
},
69+
{
70+
"minimum", (o, n) =>
71+
{
72+
GetOrCreateSchema(o).Minimum = decimal.Parse(n.GetScalarValue());
73+
}
74+
},
75+
{
76+
"exclusiveMinimum", (o, n) =>
77+
{
78+
GetOrCreateSchema(o).ExclusiveMinimum = bool.Parse(n.GetScalarValue());
79+
}
80+
},
81+
{
82+
"maxLength", (o, n) =>
83+
{
84+
GetOrCreateSchema(o).MaxLength = int.Parse(n.GetScalarValue());
85+
}
86+
},
87+
{
88+
"minLength", (o, n) =>
89+
{
90+
GetOrCreateSchema(o).MinLength = int.Parse(n.GetScalarValue());
91+
}
92+
},
93+
{
94+
"pattern", (o, n) =>
95+
{
96+
GetOrCreateSchema(o).Pattern = n.GetScalarValue();
97+
}
98+
},
99+
{
100+
"maxItems", (o, n) =>
101+
{
102+
GetOrCreateSchema(o).MaxItems = int.Parse(n.GetScalarValue());
103+
}
104+
},
105+
{
106+
"minItems", (o, n) =>
107+
{
108+
GetOrCreateSchema(o).MinItems = int.Parse(n.GetScalarValue());
109+
}
110+
},
111+
{
112+
"uniqueItems", (o, n) =>
113+
{
114+
GetOrCreateSchema(o).UniqueItems = bool.Parse(n.GetScalarValue());
58115
}
59116
},
117+
{
118+
"multipleOf", (o, n) =>
119+
{
120+
GetOrCreateSchema(o).MultipleOf = decimal.Parse(n.GetScalarValue());
121+
}
122+
},
123+
{
124+
"enum", (o, n) =>
125+
{
126+
GetOrCreateSchema(o).Enum = n.CreateListOfAny();
127+
}
128+
}
60129
};
61130

62131
private static readonly PatternFieldMap<OpenApiHeader> _headerPatternFields = new PatternFieldMap<OpenApiHeader>
@@ -82,5 +151,25 @@ public static OpenApiHeader LoadHeader(ParseNode node)
82151

83152
return header;
84153
}
154+
155+
private static void LoadStyle(OpenApiHeader header, string style)
156+
{
157+
switch (style)
158+
{
159+
case "csv":
160+
header.Style = ParameterStyle.Simple;
161+
return;
162+
case "ssv":
163+
header.Style = ParameterStyle.SpaceDelimited;
164+
return;
165+
case "pipes":
166+
header.Style = ParameterStyle.PipeDelimited;
167+
return;
168+
case "tsv":
169+
throw new NotSupportedException();
170+
default:
171+
throw new OpenApiReaderException("Unrecognized header style: " + style);
172+
}
173+
}
85174
}
86175
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ private static OpenApiRequestBody CreateFormBody(ParsingContext context, List<Op
160160
schema.Description = v.Description;
161161
return schema;
162162
}),
163-
Required = formParameters.Where(p => p.Required).Select(p => p.Name).ToList()
163+
Required = new HashSet<string>(formParameters.Where(p => p.Required).Select(p => p.Name))
164164
}
165165
};
166166

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ internal static partial class OpenApiV2Deserializer
120120
{
121121
"default", (o, n) =>
122122
{
123-
GetOrCreateSchema(o).Default = new OpenApiString(n.GetScalarValue());
123+
GetOrCreateSchema(o).Default = n.CreateAny();
124124
}
125125
},
126126
{
@@ -132,8 +132,7 @@ internal static partial class OpenApiV2Deserializer
132132
{
133133
"enum", (o, n) =>
134134
{
135-
GetOrCreateSchema(o).Enum =
136-
n.CreateSimpleList<IOpenApiAny>(l => new OpenApiString(l.GetScalarValue()));
135+
GetOrCreateSchema(o).Enum = n.CreateListOfAny();
137136
}
138137
},
139138
{

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Microsoft.OpenApi.Extensions;
66
using Microsoft.OpenApi.Models;
77
using Microsoft.OpenApi.Readers.ParseNodes;
8+
using System.Collections.Generic;
89

910
namespace Microsoft.OpenApi.Readers.V2
1011
{
@@ -103,7 +104,7 @@ internal static partial class OpenApiV2Deserializer
103104
{
104105
"required", (o, n) =>
105106
{
106-
o.Required = n.CreateSimpleList(n2 => n2.GetScalarValue()).ToArray();
107+
o.Required = new HashSet<string>(n.CreateSimpleList(n2 => n2.GetScalarValue()));
107108
}
108109
},
109110
{

0 commit comments

Comments
 (0)