From fec88507d8c2e28784b65b4b4d9b1a94ef420631 Mon Sep 17 00:00:00 2001 From: Dustin Popp Date: Thu, 23 Jan 2025 16:33:12 -0600 Subject: [PATCH] fix(ibm-schema-keywords): include 'examples' in allowlist The OpenAPI 3.1 specification states: > The example property has been deprecated in favor of the JSON Schema examples > keyword. Use of example is discouraged, and later versions of this > specification may remove it. We had previously excluded the use of 'examples' but as the specification is moving away from 'example' completely, we need to support it to allow proper authorship of OpenAPI 3.1.x documents. Signed-off-by: Dustin Popp --- packages/ruleset/src/rules/schema-keywords.js | 3 ++- .../test/rules/schema-keywords.test.js | 20 ++----------------- 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/packages/ruleset/src/rules/schema-keywords.js b/packages/ruleset/src/rules/schema-keywords.js index 6f8ac0069..e74f6b0e0 100644 --- a/packages/ruleset/src/rules/schema-keywords.js +++ b/packages/ruleset/src/rules/schema-keywords.js @@ -1,5 +1,5 @@ /** - * Copyright 2023 IBM Corporation. + * Copyright 2023-2025 IBM Corporation. * SPDX-License-Identifier: Apache2.0 */ @@ -30,6 +30,7 @@ module.exports = { 'discriminator', 'enum', 'example', + 'examples', 'exclusiveMaximum', 'exclusiveMinimum', 'format', diff --git a/packages/ruleset/test/rules/schema-keywords.test.js b/packages/ruleset/test/rules/schema-keywords.test.js index f96738c22..3d8effb92 100644 --- a/packages/ruleset/test/rules/schema-keywords.test.js +++ b/packages/ruleset/test/rules/schema-keywords.test.js @@ -1,5 +1,5 @@ /** - * Copyright 2023 - 2024 IBM Corporation. + * Copyright 2023 - 2025 IBM Corporation. * SPDX-License-Identifier: Apache2.0 */ @@ -52,6 +52,7 @@ describe(`Spectral rule: ${ruleId}`, () => { title: 'options_package', uniqueItems: 33, unevaluatedProperties: false, + examples: [], }; const results = await testRule(ruleId, rule, testDocument); @@ -112,23 +113,6 @@ describe(`Spectral rule: ${ruleId}`, () => { expect(results[i].path.join('.')).toBe(expectedPaths[i]); } }); - it('allOf element schema contains "examples"', async () => { - const testDocument = makeCopy(rootDocument); - - testDocument.components.schemas.DrinkCollection.allOf[1].examples = {}; - - const results = await testRule(ruleId, rule, testDocument); - expect(results).toHaveLength(1); - const expectedPaths = [ - 'paths./v1/drinks.get.responses.200.content.application/json.schema.allOf.1.examples', - ]; - for (let i = 0; i < results.length; i++) { - expect(results[i].code).toBe(ruleId); - expect(results[i].message).toBe(`${expectedMsgPrefix} examples`); - expect(results[i].severity).toBe(expectedSeverity); - expect(results[i].path.join('.')).toBe(expectedPaths[i]); - } - }); it('"not" schema contains "additionalItems"', async () => { const testDocument = makeCopy(rootDocument);