Skip to content

Commit 65f8d7e

Browse files
committed
Fixing nits
1 parent 7ac6245 commit 65f8d7e

File tree

2 files changed

+61
-55
lines changed

2 files changed

+61
-55
lines changed

src/Microsoft.OpenApi/Services/OpenApiWalker.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ internal void Walk(OpenApiComponents components)
112112
{
113113
foreach (var item in components.Schemas)
114114
{
115-
Walk(item.Key, () => Walk(item.Value, true));
115+
Walk(item.Key, () => Walk(item.Value, isComponent: true));
116116
}
117117
}
118118
});
@@ -123,7 +123,7 @@ internal void Walk(OpenApiComponents components)
123123
{
124124
foreach (var item in components.Callbacks)
125125
{
126-
Walk(item.Key, () => Walk(item.Value, true));
126+
Walk(item.Key, () => Walk(item.Value, isComponent: true));
127127
}
128128
}
129129
});
@@ -134,7 +134,7 @@ internal void Walk(OpenApiComponents components)
134134
{
135135
foreach (var item in components.Parameters)
136136
{
137-
Walk(item.Key, () => Walk(item.Value, true));
137+
Walk(item.Key, () => Walk(item.Value, isComponent: true));
138138
}
139139
}
140140
});
@@ -145,7 +145,7 @@ internal void Walk(OpenApiComponents components)
145145
{
146146
foreach (var item in components.Examples)
147147
{
148-
Walk(item.Key, () => Walk(item.Value, true));
148+
Walk(item.Key, () => Walk(item.Value, isComponent: true));
149149
}
150150
}
151151
});
@@ -156,7 +156,7 @@ internal void Walk(OpenApiComponents components)
156156
{
157157
foreach (var item in components.Headers)
158158
{
159-
Walk(item.Key, () => Walk(item.Value, true));
159+
Walk(item.Key, () => Walk(item.Value, isComponent: true));
160160
}
161161
}
162162
});
@@ -167,7 +167,7 @@ internal void Walk(OpenApiComponents components)
167167
{
168168
foreach (var item in components.Links)
169169
{
170-
Walk(item.Key, () => Walk(item.Value, true));
170+
Walk(item.Key, () => Walk(item.Value, isComponent: true));
171171
}
172172
}
173173
});
@@ -178,7 +178,7 @@ internal void Walk(OpenApiComponents components)
178178
{
179179
foreach (var item in components.RequestBodies)
180180
{
181-
Walk(item.Key, () => Walk(item.Value, true));
181+
Walk(item.Key, () => Walk(item.Value, isComponent: true));
182182
}
183183
}
184184
});
@@ -189,7 +189,7 @@ internal void Walk(OpenApiComponents components)
189189
{
190190
foreach (var item in components.Responses)
191191
{
192-
Walk(item.Key, () => Walk(item.Value, true));
192+
Walk(item.Key, () => Walk(item.Value, isComponent: true));
193193
}
194194
}
195195
});

test/Microsoft.OpenApi.Tests/Walkers/WalkerLocationTests.cs

Lines changed: 53 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -62,32 +62,33 @@ public void LocateTopLevelArrayItems()
6262
[Fact]
6363
public void LocatePathOperationContentSchema()
6464
{
65-
var doc = new OpenApiDocument();
66-
doc.Paths = new OpenApiPaths();
65+
var doc = new OpenApiDocument
66+
{
67+
Paths = new OpenApiPaths()
68+
};
6769
doc.Paths.Add("/test", new OpenApiPathItem()
6870
{
6971
Operations = new Dictionary<OperationType, OpenApiOperation>()
7072
{
71-
{ OperationType.Get, new OpenApiOperation()
73+
[OperationType.Get] = new OpenApiOperation()
7274
{
7375
Responses = new OpenApiResponses()
7476
{
75-
{ "200", new OpenApiResponse() {
76-
Content = new Dictionary<string,OpenApiMediaType>
77+
["200"] = new OpenApiResponse()
78+
{
79+
Content = new Dictionary<string, OpenApiMediaType>
80+
{
81+
["application/json"] = new OpenApiMediaType
7782
{
78-
{ "application/json", new OpenApiMediaType {
79-
Schema = new OpenApiSchema
80-
{
81-
Type = "string"
82-
}
83-
}
83+
Schema = new OpenApiSchema
84+
{
85+
Type = "string"
8486
}
8587
}
8688
}
8789
}
8890
}
8991
}
90-
}
9192
}
9293
});
9394

@@ -160,8 +161,10 @@ public void WalkDOMWithCycles()
160161
public void LocateReferences()
161162
{
162163

163-
var baseSchema = new OpenApiSchema() {
164-
Reference = new OpenApiReference() {
164+
var baseSchema = new OpenApiSchema()
165+
{
166+
Reference = new OpenApiReference()
167+
{
165168
Id = "base",
166169
Type = ReferenceType.Schema
167170
},
@@ -172,46 +175,50 @@ public void LocateReferences()
172175
{
173176
AnyOf = new List<OpenApiSchema>() { baseSchema },
174177
Reference = new OpenApiReference()
175-
{
176-
Id = "derived",
177-
Type = ReferenceType.Schema
178-
},
178+
{
179+
Id = "derived",
180+
Type = ReferenceType.Schema
181+
},
179182
UnresolvedReference = false
180183
};
181184

182-
var testHeader = new OpenApiHeader() {
183-
Schema = derivedSchema,
184-
Reference = new OpenApiReference()
185-
{
186-
Id = "test-header",
187-
Type = ReferenceType.Header
188-
},
189-
UnresolvedReference = false
185+
var testHeader = new OpenApiHeader()
186+
{
187+
Schema = derivedSchema,
188+
Reference = new OpenApiReference()
189+
{
190+
Id = "test-header",
191+
Type = ReferenceType.Header
192+
},
193+
UnresolvedReference = false
190194
};
191195

192196
var doc = new OpenApiDocument
193197
{
194-
Paths = new OpenApiPaths() {
195-
{ "/", new OpenApiPathItem() {
196-
Operations = new Dictionary<OperationType, OpenApiOperation>() {
197-
{ OperationType.Get, new OpenApiOperation() {
198-
Responses = new OpenApiResponses()
198+
Paths = new OpenApiPaths()
199+
{
200+
["/"] = new OpenApiPathItem()
201+
{
202+
Operations = new Dictionary<OperationType, OpenApiOperation>()
203+
{
204+
[OperationType.Get] = new OpenApiOperation()
205+
{
206+
Responses = new OpenApiResponses()
207+
{
208+
["200"] = new OpenApiResponse()
199209
{
200-
{ "200",new OpenApiResponse() {
201-
Content = new Dictionary<string, OpenApiMediaType>(){
202-
{ "application/json", new OpenApiMediaType() {
210+
Content = new Dictionary<string, OpenApiMediaType>()
211+
{
212+
["application/json"] = new OpenApiMediaType()
213+
{
203214
Schema = derivedSchema
204-
}
205-
}
206-
},
215+
}
216+
},
207217
Headers = new Dictionary<string, OpenApiHeader>()
208218
{
209-
{ "test-header",testHeader}
210-
}
219+
["test-header"] = testHeader
211220
}
212-
}
213221
}
214-
}
215222
}
216223
}
217224
}
@@ -220,22 +227,21 @@ public void LocateReferences()
220227
Components = new OpenApiComponents()
221228
{
222229
Schemas = new Dictionary<string, OpenApiSchema>() {
223-
{ "derived", derivedSchema },
224-
{ "base", baseSchema },
230+
["derived"] = derivedSchema,
231+
["base"] = baseSchema,
225232
},
226233
Headers = new Dictionary<string, OpenApiHeader>()
227234
{
228-
{ "test-header", testHeader }
235+
["test-header"] = testHeader
229236
}
230-
231237
}
232238
};
233239

234240
var locator = new LocatorVisitor();
235241
var walker = new OpenApiWalker(locator);
236242
walker.Walk(doc);
237243

238-
locator.Locations.Where(l=>l.StartsWith("referenceAt:")).ShouldBeEquivalentTo(new List<string> {
244+
locator.Locations.Where(l => l.StartsWith("referenceAt:")).ShouldBeEquivalentTo(new List<string> {
239245
"referenceAt: #/paths/~1/get/responses/200/content/application~1json/schema",
240246
"referenceAt: #/paths/~1/get/responses/200/headers/test-header",
241247
"referenceAt: #/components/schemas/derived/anyOf/0",
@@ -295,7 +301,7 @@ public override void Visit(IOpenApiReferenceable referenceable)
295301
{
296302
Locations.Add("referenceAt: " + this.PathString);
297303
}
298-
public override void Visit(IDictionary<string,OpenApiMediaType> content)
304+
public override void Visit(IDictionary<string, OpenApiMediaType> content)
299305
{
300306
Locations.Add(this.PathString);
301307
}

0 commit comments

Comments
 (0)