Skip to content

Commit e88f0d3

Browse files
authored
Merge pull request #2248 from microsoft/chore/example-validation-works
chore: no validation warnings from examples with date-time format
2 parents 843e9b9 + e6f1e2f commit e88f0d3

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiCompoentsTests.cs renamed to test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiComponentsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace Microsoft.OpenApi.Readers.Tests.V31Tests
1010
{
11-
public class OpenApiCompoentsTests
11+
public class OpenApiComponentsTests
1212
{
1313
[Theory]
1414
[InlineData("./FirstLevel/SecondLevel/ThridLevel/File.json#/components/schemas/ExternalRelativePathModel", "ExternalRelativePathModel", "./FirstLevel/SecondLevel/ThridLevel/File.json")]

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,5 +574,20 @@ public void ParseEmptyMemoryStreamThrowsAnArgumentException()
574574
{
575575
Assert.Throws<ArgumentException>(() => OpenApiDocument.Load(new MemoryStream()));
576576
}
577+
578+
[Fact]
579+
public async Task ValidateReferencedExampleInSchemaWorks()
580+
{
581+
// Arrange && Act
582+
var path = Path.Combine(SampleFolderPath, "docWithReferencedExampleInSchemaWorks.yaml");
583+
var result = await OpenApiDocument.LoadAsync(path, SettingsFixture.ReaderSettings);
584+
var actualSchemaExample = result.Document.Components.Schemas["DiffCreatedEvent"].Properties["updatedAt"].Example;
585+
var targetSchemaExample = result.Document.Components.Schemas["Timestamp"].Example;
586+
587+
// Assert
588+
Assert.Equal(targetSchemaExample, actualSchemaExample);
589+
Assert.Empty(result.Diagnostic.Errors);
590+
Assert.Empty(result.Diagnostic.Warnings);
591+
}
577592
}
578593
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
openapi: 3.1.1
2+
info:
3+
title: ReferenceById
4+
version: 1.0.0
5+
paths:
6+
/resource:
7+
get:
8+
responses:
9+
'200':
10+
description: OK
11+
content:
12+
application/json:
13+
schema:
14+
$ref: '#/components/schemas/DiffCreatedEvent'
15+
components:
16+
schemas:
17+
DiffCreatedEvent:
18+
description: 'diff index created'
19+
type: object
20+
additionalProperties: false
21+
properties:
22+
updatedAt:
23+
$ref: '#/components/schemas/Timestamp'
24+
example:
25+
"updatedAt": '2020-06-30T06:43:51.391Z'
26+
Timestamp:
27+
type: string
28+
format: date-time
29+
description: 'timestamp'
30+
example: '2020-06-30T06:43:51.391Z'

0 commit comments

Comments
 (0)