Skip to content

Commit 8f883b1

Browse files
Header test improved
1 parent ff85802 commit 8f883b1

File tree

2 files changed

+73
-17
lines changed

2 files changed

+73
-17
lines changed

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

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Linq;
99
using System.Threading;
1010
using FluentAssertions;
11+
using Microsoft.OpenApi.Any;
1112
using Microsoft.OpenApi.Models;
1213
using Microsoft.OpenApi.Validations;
1314
using Microsoft.OpenApi.Validations.Rules;
@@ -1211,7 +1212,68 @@ public void HeaderParameterShouldAllowExample()
12111212
using (var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "apiWithFullHeaderComponent.yaml")))
12121213
{
12131214
var openApiDoc = new OpenApiStreamReader().Read(stream, out var diagnostic);
1214-
Assert.Equal(0, diagnostic.Errors.Count);
1215+
1216+
var exampleHeader = openApiDoc.Components?.Headers?["example-header"];
1217+
Assert.NotNull(exampleHeader);
1218+
exampleHeader.ShouldBeEquivalentTo(
1219+
new OpenApiHeader()
1220+
{
1221+
Description = "Test header with example",
1222+
Required = true,
1223+
Deprecated = true,
1224+
AllowEmptyValue = true,
1225+
AllowReserved = true,
1226+
Style = ParameterStyle.Simple,
1227+
Explode = true,
1228+
Example = new OpenApiString("99391c7e-ad88-49ec-a2ad-99ddcb1f7721"),
1229+
Schema = new OpenApiSchema()
1230+
{
1231+
Type = "string",
1232+
Format = "uuid"
1233+
},
1234+
Reference = new OpenApiReference()
1235+
{
1236+
Type = ReferenceType.Header,
1237+
Id = "example-header"
1238+
}
1239+
});
1240+
1241+
var examplesHeader = openApiDoc.Components?.Headers?["examples-header"];
1242+
Assert.NotNull(examplesHeader);
1243+
examplesHeader.ShouldBeEquivalentTo(
1244+
new OpenApiHeader()
1245+
{
1246+
Description = "Test header with example",
1247+
Required = true,
1248+
Deprecated = true,
1249+
AllowEmptyValue = true,
1250+
AllowReserved = true,
1251+
Style = ParameterStyle.Simple,
1252+
Explode = true,
1253+
Examples = new Dictionary<string, OpenApiExample>()
1254+
{
1255+
{ "uuid1", new OpenApiExample()
1256+
{
1257+
Value = new OpenApiString("99391c7e-ad88-49ec-a2ad-99ddcb1f7721")
1258+
}
1259+
},
1260+
{ "uuid2", new OpenApiExample()
1261+
{
1262+
Value = new OpenApiString("99391c7e-ad88-49ec-a2ad-99ddcb1f7721")
1263+
}
1264+
}
1265+
},
1266+
Schema = new OpenApiSchema()
1267+
{
1268+
Type = "string",
1269+
Format = "uuid"
1270+
},
1271+
Reference = new OpenApiReference()
1272+
{
1273+
Type = ReferenceType.Header,
1274+
Id = "examples-header"
1275+
}
1276+
});
12151277
}
12161278
}
12171279
}

test/Microsoft.OpenApi.Readers.Tests/V3Tests/Samples/OpenApiDocument/apiWithFullHeaderComponent.yaml

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,33 @@ openapi: '3.0.0'
22
info:
33
version: '1.0.0'
44
title: Header components
5-
paths:
6-
/:
7-
get:
8-
responses:
9-
'200':
10-
description: sample response
11-
headers:
12-
$ref: "#/components/headers/X-Request-ID"
135
components:
146
headers:
157
example-header:
168
description: Test header with example
179
required: true
18-
deprecated: false
19-
allowEmptyValue: false
10+
deprecated: true
11+
allowEmptyValue: true
2012
allowReserved: true
2113
style: simple
22-
explode: false
14+
explode: true
2315
example: "99391c7e-ad88-49ec-a2ad-99ddcb1f7721"
2416
schema:
2517
type: string
2618
format: uuid
2719
examples-header:
2820
description: Test header with example
2921
required: true
30-
deprecated: false
31-
allowEmptyValue: false
22+
deprecated: true
23+
allowEmptyValue: true
3224
allowReserved: true
3325
style: simple
34-
explode: false
26+
explode: true
3527
examples:
36-
uuid1: "99391c7e-ad88-49ec-a2ad-99ddcb1f7721"
37-
uuid2: "99391c7e-ad88-49ec-a2ad-99ddcb1f7721"
28+
uuid1:
29+
value: "99391c7e-ad88-49ec-a2ad-99ddcb1f7721"
30+
uuid2:
31+
value: "99391c7e-ad88-49ec-a2ad-99ddcb1f7721"
3832
schema:
3933
type: string
4034
format: uuid

0 commit comments

Comments
 (0)