Skip to content

Commit ffc87ca

Browse files
committed
Use keyword examples instead of example
1 parent 99a038c commit ffc87ca

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

src/Microsoft.OpenApi/Validations/Rules/JsonSchemaRules.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,18 @@ public static class JsonSchemaRules
3434

3535
context.Exit();
3636

37-
// example
38-
context.Enter("example");
37+
// examples
38+
context.Enter("examples");
3939

40-
if (jsonSchema.GetExample() != null)
40+
if (jsonSchema.GetExamples() != null)
4141
{
42-
RuleHelpers.ValidateDataTypeMismatch(context, nameof(SchemaMismatchedDataType), jsonSchema.GetExample(), jsonSchema);
42+
for (int i = 0; i < jsonSchema.GetExamples().Count(); i++)
43+
{
44+
context.Enter(i.ToString());
45+
RuleHelpers.ValidateDataTypeMismatch(context, nameof(SchemaMismatchedDataType), jsonSchema.GetExamples().ElementAt(i), jsonSchema);
46+
context.Exit();
47+
}
48+
4349
}
4450

4551
context.Exit();

src/Microsoft.OpenApi/Writers/OpenApiWriterBase.cs

Lines changed: 4 additions & 4 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;
@@ -574,9 +574,9 @@ public void WriteJsonSchemaWithoutReference(IOpenApiWriter writer, JsonSchema sc
574574

575575
// externalDocs
576576
writer.WriteOptionalObject(OpenApiConstants.ExternalDocs, schema.GetExternalDocs(), (w, s) => JsonSerializer.Serialize(s));
577-
578-
// example
579-
writer.WriteOptionalObject(OpenApiConstants.Example, schema.GetExample(), (w, e) => w.WriteAny(new OpenApiAny(e)));
577+
578+
// examples
579+
writer.WriteOptionalCollection(OpenApiConstants.Examples, schema.GetExamples(), (n, e) => n.WriteAny(new OpenApiAny(e)));
580580

581581
// deprecated
582582
writer.WriteProperty(OpenApiConstants.Deprecated, schema.GetDeprecated(), false);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ paths: # The available paths and operations for the API
6161
properties:
6262
message: # A property for the confirmation message
6363
type: string
64-
example: File uploaded successfully
64+
examples:
65+
- The file was uploaded successfully
6566
components: # Reusable components for the API
6667
schemas: # JSON Schema definitions for the API
6768
User: # A schema for a user object

0 commit comments

Comments
 (0)