Skip to content

Commit 62b089a

Browse files
committed
Refactor failing test
1 parent c0f878f commit 62b089a

File tree

4 files changed

+17
-19
lines changed

4 files changed

+17
-19
lines changed

test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiDocumentTests.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Microsoft.OpenApi.Models;
88
using Microsoft.OpenApi.Writers;
99
using Xunit;
10+
using static System.Net.Mime.MediaTypeNames;
1011

1112
namespace Microsoft.OpenApi.Readers.Tests.V31Tests
1213
{
@@ -69,7 +70,7 @@ public void ParseDocumentWithWebhooksShouldSucceed()
6970
{
7071
Schemas =
7172
{
72-
["pet"] = petSchema,
73+
["pet1"] = petSchema,
7374
["newPet"] = newPetSchema
7475
}
7576
};
@@ -175,6 +176,7 @@ public void ParseDocumentWithWebhooksShouldSucceed()
175176
};
176177

177178
// Assert
179+
var schema = actual.Webhooks["/pets"].Operations[OperationType.Get].Responses["200"].Content["application/json"].Schema;
178180
diagnostic.Should().BeEquivalentTo(new OpenApiDiagnostic() { SpecificationVersion = OpenApiSpecVersion.OpenApi3_1 });
179181
actual.Should().BeEquivalentTo(expected);
180182
}
@@ -190,7 +192,7 @@ public void ParseDocumentsWithReusablePathItemInWebhooksSucceeds()
190192
{
191193
Schemas = new Dictionary<string, JsonSchema>
192194
{
193-
["pet"] = new JsonSchemaBuilder()
195+
["petSchema"] = new JsonSchemaBuilder()
194196
.Type(SchemaValueType.Object)
195197
.Required("id", "name")
196198
.Properties(
@@ -208,7 +210,7 @@ public void ParseDocumentsWithReusablePathItemInWebhooksSucceeds()
208210
};
209211

210212
// Create a clone of the schema to avoid modifying things in components.
211-
var petSchema = components.Schemas["pet"];
213+
var petSchema = components.Schemas["petSchema"];
212214
var newPetSchema = components.Schemas["newPet"];
213215

214216
components.PathItems = new Dictionary<string, OpenApiPathItem>
@@ -321,7 +323,6 @@ public void ParseDocumentsWithReusablePathItemInWebhooksSucceeds()
321323
actual.Should().BeEquivalentTo(expected);
322324
context.Should().BeEquivalentTo(
323325
new OpenApiDiagnostic() { SpecificationVersion = OpenApiSpecVersion.OpenApi3_1 });
324-
325326
}
326327

327328
[Fact]

test/Microsoft.OpenApi.Readers.Tests/V31Tests/Samples/OpenApiDocument/documentWithReusablePaths.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ webhooks:
88
"$ref": '#/components/pathItems/pets'
99
components:
1010
schemas:
11-
pet:
11+
petSchema:
1212
type: object
1313
required:
1414
- id
@@ -62,12 +62,12 @@ components:
6262
schema:
6363
type: array
6464
items:
65-
"$ref": '#/components/schemas/pet'
65+
"$ref": '#/components/schemas/petSchema'
6666
application/xml:
6767
schema:
6868
type: array
6969
items:
70-
"$ref": '#/components/schemas/pet'
70+
"$ref": '#/components/schemas/petSchema'
7171
post:
7272
requestBody:
7373
description: Information about a new pet in the system
@@ -82,4 +82,4 @@ components:
8282
content:
8383
application/json:
8484
schema:
85-
$ref: '#/components/schemas/pet'
85+
$ref: '#/components/schemas/petSchema'

test/Microsoft.OpenApi.Readers.Tests/V31Tests/Samples/OpenApiDocument/documentWithWebhooks.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ webhooks:
3131
schema:
3232
type: array
3333
items:
34-
"$ref": '#/components/schemas/pet'
34+
"$ref": '#/components/schemas/pet1'
3535
application/xml:
3636
schema:
3737
type: array
3838
items:
39-
"$ref": '#/components/schemas/pet'
39+
"$ref": '#/components/schemas/pet1'
4040
post:
4141
requestBody:
4242
description: Information about a new pet in the system
@@ -51,10 +51,10 @@ webhooks:
5151
content:
5252
application/json:
5353
schema:
54-
$ref: '#/components/schemas/pet'
54+
$ref: '#/components/schemas/pet1'
5555
components:
5656
schemas:
57-
pet:
57+
pet1:
5858
type: object
5959
required:
6060
- id

test/Microsoft.OpenApi.Tests/Workspaces/OpenApiWorkspaceTests.cs

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

44
using System;
@@ -77,7 +77,7 @@ public void OpenApiWorkspacesCanResolveExternalReferences()
7777
var workspace = new OpenApiWorkspace();
7878
var doc = CreateCommonDocument();
7979
var location = "common";
80-
80+
8181
workspace.AddDocument(location, doc);
8282

8383
var schema = workspace.ResolveJsonSchemaReference(new Uri("http://everything.json/common#/components/schemas/test"));
@@ -144,13 +144,10 @@ public void OpenApiWorkspacesCanResolveReferencesToDocumentFragments()
144144
// Arrange
145145
var workspace = new OpenApiWorkspace();
146146
var schemaFragment = new JsonSchemaBuilder().Type(SchemaValueType.String).Description("Schema from a fragment").Build();
147-
//workspace.AddFragment("fragment", schemaFragment);
147+
workspace.AddSchemaFragment("fragment", schemaFragment);
148148

149149
// Act
150-
var schema = workspace.ResolveReference(new OpenApiReference()
151-
{
152-
ExternalResource = "fragment"
153-
}) as JsonSchema;
150+
var schema = workspace.ResolveJsonSchemaReference(new Uri("http://everything.json/common#/components/schemas/test"));
154151

155152
// Assert
156153
Assert.NotNull(schema);

0 commit comments

Comments
 (0)