Skip to content

Commit 4ca2f87

Browse files
committed
Clean up tests
1 parent ae52035 commit 4ca2f87

File tree

5 files changed

+26
-21
lines changed

5 files changed

+26
-21
lines changed

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Collections.Generic;
1+
using System.Collections.Generic;
22
using System.Globalization;
33
using System.IO;
44
using FluentAssertions;
@@ -7,7 +7,6 @@
77
using Microsoft.OpenApi.Models;
88
using Microsoft.OpenApi.Writers;
99
using Xunit;
10-
using static System.Net.Mime.MediaTypeNames;
1110

1211
namespace Microsoft.OpenApi.Readers.Tests.V31Tests
1312
{
@@ -71,7 +70,7 @@ public void ParseDocumentWithWebhooksShouldSucceed()
7170
Schemas =
7271
{
7372
["pet1"] = petSchema,
74-
["newPet"] = newPetSchema
73+
["newPet1"] = newPetSchema
7574
}
7675
};
7776

@@ -199,7 +198,7 @@ public void ParseDocumentsWithReusablePathItemInWebhooksSucceeds()
199198
("id", new JsonSchemaBuilder().Type(SchemaValueType.Integer).Format("int64")),
200199
("name", new JsonSchemaBuilder().Type(SchemaValueType.String)),
201200
("tag", new JsonSchemaBuilder().Type(SchemaValueType.String))),
202-
["newPet"] = new JsonSchemaBuilder()
201+
["newPetSchema"] = new JsonSchemaBuilder()
203202
.Type(SchemaValueType.Object)
204203
.Required("name")
205204
.Properties(
@@ -211,7 +210,7 @@ public void ParseDocumentsWithReusablePathItemInWebhooksSucceeds()
211210

212211
// Create a clone of the schema to avoid modifying things in components.
213212
var petSchema = components.Schemas["petSchema"];
214-
var newPetSchema = components.Schemas["newPet"];
213+
var newPetSchema = components.Schemas["newPetSchema"];
215214

216215
components.PathItems = new Dictionary<string, OpenApiPathItem>
217216
{
@@ -333,14 +332,10 @@ public void ParseDocumentWithDescriptionInDollarRefsShouldSucceed()
333332

334333
// Act
335334
var actual = new OpenApiStreamReader().Read(stream, out var diagnostic);
336-
var schema = actual.Paths["/pets"].Operations[OperationType.Get].Responses["200"].Content["application/json"].Schema;
337335
var header = actual.Components.Responses["Test"].Headers["X-Test"];
338336

339337
// Assert
340338
Assert.True(header.Description == "A referenced X-Test header"); /*response header #ref's description overrides the header's description*/
341-
Assert.Null(schema.GetRef());
342-
Assert.Equal(SchemaValueType.Object, schema.GetJsonType());
343-
Assert.Equal("A pet in a petstore", schema.GetDescription()); /*The reference object's description overrides that of the referenced component*/
344339
}
345340

346341
[Fact]

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ components:
2121
type: string
2222
tag:
2323
type: string
24-
newPet:
24+
newPetSchema:
2525
type: object
2626
required:
2727
- name
@@ -75,7 +75,7 @@ components:
7575
content:
7676
'application/json':
7777
schema:
78-
"$ref": '#/components/schemas/newPet'
78+
"$ref": '#/components/schemas/newPetSchema'
7979
responses:
8080
"200":
8181
description: Return a 200 status to indicate that the data was received successfully

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ webhooks:
4444
content:
4545
'application/json':
4646
schema:
47-
"$ref": '#/components/schemas/newPet'
47+
"$ref": '#/components/schemas/newPet1'
4848
responses:
4949
"200":
5050
description: Return a 200 status to indicate that the data was received successfully
@@ -67,7 +67,7 @@ components:
6767
type: string
6868
tag:
6969
type: string
70-
newPet:
70+
newPet1:
7171
type: object
7272
required:
7373
- name

test/Microsoft.OpenApi.Readers.Tests/V3Tests/JsonSchemaTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ public void ParseBasicSchemaWithReferenceShouldSucceed()
249249
new JsonSchemaBuilder()
250250
.Type(SchemaValueType.Object)
251251
.Required("rootCause")
252-
.Properties(("rootCause", new JsonSchemaBuilder().Type(SchemaValueType.String))))
252+
.Properties(("rootCause", new JsonSchemaBuilder().Type(SchemaValueType.String))))
253253
}
254254
},
255255
options => options.Excluding(m => m.Name == "HostDocument")

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

Lines changed: 17 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;
@@ -72,13 +72,14 @@ public void OpenApiWorkspacesAllowDocumentsToReferenceEachOther()
7272
[Fact]
7373
public void OpenApiWorkspacesCanResolveExternalReferences()
7474
{
75+
var refUri = new Uri("https://everything.json/common#/components/schemas/test");
7576
var workspace = new OpenApiWorkspace();
76-
var doc = CreateCommonDocument();
77+
var doc = CreateCommonDocument(refUri);
7778
var location = "common";
7879

7980
workspace.AddDocument(location, doc);
8081

81-
var schema = workspace.ResolveJsonSchemaReference(new Uri("https://everything.json/common#/components/schemas/test"));
82+
var schema = workspace.ResolveJsonSchemaReference(refUri);
8283

8384
Assert.NotNull(schema);
8485
Assert.Equal("The referenced one", schema.GetDescription());
@@ -90,6 +91,7 @@ public void OpenApiWorkspacesAllowDocumentsToReferenceEachOther_short()
9091
var workspace = new OpenApiWorkspace();
9192

9293
var doc = new OpenApiDocument();
94+
var reference = "#/components/schemas/test";
9395
doc.CreatePathItem("/", p =>
9496
{
9597
p.Description = "Consumer";
@@ -98,14 +100,15 @@ public void OpenApiWorkspacesAllowDocumentsToReferenceEachOther_short()
98100
{
99101
re.Description = "Success";
100102
re.CreateContent("application/json", co =>
101-
co.Schema = new JsonSchemaBuilder().Ref("test").Build()
103+
co.Schema = new JsonSchemaBuilder().Ref(reference).Build()
102104
);
103105
})
104106
);
105107
});
106108

109+
var refUri = new Uri("https://registry" + reference.Split('#').LastOrDefault());
107110
workspace.AddDocument("root", doc);
108-
workspace.AddDocument("common", CreateCommonDocument());
111+
workspace.AddDocument("common", CreateCommonDocument(refUri));
109112
var errors = doc.ResolveReferences();
110113
Assert.Empty(errors);
111114

@@ -178,9 +181,9 @@ public void OpenApiWorkspacesCanResolveReferencesToDocumentFragmentsWithJsonPoin
178181
}
179182

180183
// Test artifacts
181-
private static OpenApiDocument CreateCommonDocument()
184+
private static OpenApiDocument CreateCommonDocument(Uri refUri)
182185
{
183-
return new()
186+
var doc = new OpenApiDocument()
184187
{
185188
Components = new()
186189
{
@@ -189,6 +192,13 @@ private static OpenApiDocument CreateCommonDocument()
189192
}
190193
}
191194
};
195+
196+
foreach(var schema in doc.Components.Schemas)
197+
{
198+
SchemaRegistry.Global.Register(refUri, schema.Value);
199+
}
200+
201+
return doc;
192202
}
193203
}
194204

0 commit comments

Comments
 (0)