From 4436ed7bf6fc9166568930b60698884d220e90d7 Mon Sep 17 00:00:00 2001 From: Lovisa Berggren Date: Thu, 14 Aug 2025 11:26:54 +0100 Subject: [PATCH 1/8] feat(ipa): new IPA rule xgen-IPA-125-oneOf-must-accompany-oneOf-anyOf-allOf --- ...inatorMustAccompanyOneOfAnyOfAllOf.test.js | 128 ++++++++++++++++++ tools/spectral/ipa/rulesets/IPA-125.yaml | 13 ++ tools/spectral/ipa/rulesets/README.md | 20 ++- ...scriminatorMustAccompanyOneOfAnyOfAllOf.js | 23 ++++ 4 files changed, 178 insertions(+), 6 deletions(-) create mode 100644 tools/spectral/ipa/__tests__/IPA125DiscriminatorMustAccompanyOneOfAnyOfAllOf.test.js create mode 100644 tools/spectral/ipa/rulesets/functions/IPA125DiscriminatorMustAccompanyOneOfAnyOfAllOf.js diff --git a/tools/spectral/ipa/__tests__/IPA125DiscriminatorMustAccompanyOneOfAnyOfAllOf.test.js b/tools/spectral/ipa/__tests__/IPA125DiscriminatorMustAccompanyOneOfAnyOfAllOf.test.js new file mode 100644 index 0000000000..4a83854caa --- /dev/null +++ b/tools/spectral/ipa/__tests__/IPA125DiscriminatorMustAccompanyOneOfAnyOfAllOf.test.js @@ -0,0 +1,128 @@ +import testRule from './__helpers__/testRule.js'; +import { DiagnosticSeverity } from '@stoplight/types'; + +testRule('xgen-IPA-125-oneOf-must-accompany-oneOf-anyOf-allOf', [ + { + name: 'valid schemas', + document: { + components: { + schemas: { + SchemaOneOf: { + discriminator: { + propertyName: 'type', + }, + oneOf: [{}], + }, + SchemaAnuOf: { + discriminator: { + propertyName: 'type', + }, + anyOf: [{}], + }, + SchemaAllOf: { + discriminator: { + propertyName: 'type', + }, + allOf: [{}], + }, + }, + }, + }, + errors: [], + }, + { + name: 'invalid schemas', + document: { + components: { + schemas: { + Schema: { + discriminator: { + propertyName: 'type', + }, + properties: { + type: { + type: 'string', + }, + }, + }, + NestedSchema: { + properties: { + name: { + type: 'object', + discriminator: { + propertyName: 'first', + }, + properties: { + first: { + type: 'string', + }, + }, + }, + address: { + type: 'string', + }, + }, + }, + }, + }, + }, + errors: [ + { + code: 'xgen-IPA-125-oneOf-must-accompany-oneOf-anyOf-allOf', + message: "Each discriminator property must be accompanied by a 'oneOf', 'anyOf' or 'allOf' property.", + path: ['components', 'schemas', 'Schema', 'discriminator'], + severity: DiagnosticSeverity.Warning, + }, + { + code: 'xgen-IPA-125-oneOf-must-accompany-oneOf-anyOf-allOf', + message: "Each discriminator property must be accompanied by a 'oneOf', 'anyOf' or 'allOf' property.", + path: ['components', 'schemas', 'NestedSchema', 'properties', 'name', 'discriminator'], + severity: DiagnosticSeverity.Warning, + }, + ], + }, + { + name: 'invalid schemas with exceptions', + document: { + components: { + schemas: { + Schema: { + discriminator: { + propertyName: 'type', + 'x-xgen-IPA-exception': { + 'xgen-IPA-125-oneOf-must-accompany-oneOf-anyOf-allOf': 'reason', + }, + }, + properties: { + type: { + type: 'string', + }, + }, + }, + NestedSchema: { + properties: { + name: { + type: 'object', + discriminator: { + propertyName: 'first', + 'x-xgen-IPA-exception': { + 'xgen-IPA-125-oneOf-must-accompany-oneOf-anyOf-allOf': 'reason', + }, + }, + properties: { + first: { + type: 'string', + }, + }, + }, + address: { + type: 'string', + }, + }, + }, + }, + }, + }, + errors: [], + }, +]); diff --git a/tools/spectral/ipa/rulesets/IPA-125.yaml b/tools/spectral/ipa/rulesets/IPA-125.yaml index 21ef3be6e5..d79f563bb0 100644 --- a/tools/spectral/ipa/rulesets/IPA-125.yaml +++ b/tools/spectral/ipa/rulesets/IPA-125.yaml @@ -4,6 +4,7 @@ functions: - IPA125OneOfMustHaveDiscriminator - IPA125OneOfNoBaseTypes + - IPA125DiscriminatorMustAccompanyOneOfAnyOfAllOf rules: xgen-IPA-125-oneOf-must-have-discriminator: @@ -63,3 +64,15 @@ rules: given: '$.components.schemas[*]' then: function: 'IPA125OneOfNoBaseTypes' + + xgen-IPA-125-oneOf-must-accompany-oneOf-anyOf-allOf: + description: | + Each discriminator property must be accompanied by a `oneOf`, `anyOf` or `allOf` property + + ##### Implementation details + - Rule checks that a `discriminator` property has a `oneOf`, `anyOf` or `allOf` sibling + message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-125-oneOf-must-accompany-oneOf-anyOf-allOf' + severity: warn + given: '$..discriminator' + then: + function: 'IPA125DiscriminatorMustAccompanyOneOfAnyOfAllOf' diff --git a/tools/spectral/ipa/rulesets/README.md b/tools/spectral/ipa/rulesets/README.md index af80e9a52a..5a0d09e4cd 100644 --- a/tools/spectral/ipa/rulesets/README.md +++ b/tools/spectral/ipa/rulesets/README.md @@ -141,7 +141,7 @@ Rule checks for the following conditions: #### xgen-IPA-104-valid-operation-id - ![warn](https://img.shields.io/badge/warning-yellow) + `off` The Operation ID must start with the verb “get” and should be followed by a noun or compound noun. The noun(s) in the Operation ID should be the collection identifiers from the resource identifier in singular form. If the resource is a singleton resource, the last noun may be the plural form of the collection identifier. @@ -207,7 +207,7 @@ The response body of the List method should consist of the same resource object - Paths with `x-xgen-IPA-exception` for this rule are excluded from validation #### xgen-IPA-105-valid-operation-id - ![warn](https://img.shields.io/badge/warning-yellow) + `off` The Operation ID must start with the verb “list” and should be followed by a noun or compound noun. The noun(s) in the Operation ID should be the collection identifiers from the resource identifier in singular form, where the last noun is in plural form. @@ -299,7 +299,7 @@ Rule checks for the following conditions: #### xgen-IPA-106-valid-operation-id - ![warn](https://img.shields.io/badge/warning-yellow) + `off` The Operation ID must start with the verb “create” and should be followed by a noun or compound noun. The noun(s) in the Operation ID should be the collection identifiers from the resource identifier in singular form. @@ -381,7 +381,7 @@ Rule checks for the following conditions: #### xgen-IPA-107-valid-operation-id - ![warn](https://img.shields.io/badge/warning-yellow) + `off` The Operation ID must start with the verb “update” and should be followed by a noun or compound noun. The noun(s) in the Operation ID should be the collection identifiers from the resource identifier in singular form. If the resource is a singleton resource, the last noun may be the plural form of the collection identifier. @@ -437,7 +437,7 @@ Rule checks for the following conditions: #### xgen-IPA-108-valid-operation-id - ![warn](https://img.shields.io/badge/warning-yellow) + `off` The Operation ID must start with the verb “delete” and should be followed by a noun or compound noun. The noun(s) in the Operation ID should be the collection identifiers from the resource identifier in singular form. @@ -493,7 +493,7 @@ Rule checks for the following conditions: #### xgen-IPA-109-valid-operation-id - ![warn](https://img.shields.io/badge/warning-yellow) + `off` The Operation ID must start with the custom method verb (the custom method path section delimited by the colon (:) character) and should be followed by a noun or compound noun. If the custom Operation ID has a verb + noun, the Operation ID should end with the noun. The noun(s) in the Operation ID should be the collection identifiers from the resource identifier. @@ -989,6 +989,14 @@ Using oneOf with multiple primitive types can lead to ambiguity and validation p be able to properly determine which type to use in which context. Instead, use more specific object types with clear discriminators. +#### xgen-IPA-125-oneOf-must-accompany-oneOf-anyOf-allOf + + ![warn](https://img.shields.io/badge/warning-yellow) +Each discriminator property must be accompanied by a `oneOf`, `anyOf` or `allOf` property + +##### Implementation details +- Rule checks that a `discriminator` property has a `oneOf`, `anyOf` or `allOf` sibling + ### IPA-126 diff --git a/tools/spectral/ipa/rulesets/functions/IPA125DiscriminatorMustAccompanyOneOfAnyOfAllOf.js b/tools/spectral/ipa/rulesets/functions/IPA125DiscriminatorMustAccompanyOneOfAnyOfAllOf.js new file mode 100644 index 0000000000..09dd594423 --- /dev/null +++ b/tools/spectral/ipa/rulesets/functions/IPA125DiscriminatorMustAccompanyOneOfAnyOfAllOf.js @@ -0,0 +1,23 @@ +import { evaluateAndCollectAdoptionStatus } from './utils/collectionUtils.js'; +import { resolveObject } from './utils/componentUtils.js'; + +const ERROR_MESSAGE = "Each discriminator property must be accompanied by a 'oneOf', 'anyOf' or 'allOf' property."; + +export default (input, _, { path, documentInventory, rule }) => { + const errors = checkViolationsAndReturnErrors(input, path, documentInventory.resolved); + return evaluateAndCollectAdoptionStatus(errors, rule.name, input, path); +}; + +function checkViolationsAndReturnErrors(input, path, oas) { + const siblings = Object.keys(resolveObject(oas, path.slice(0, path.length - 1))); + + if (!siblings.includes('oneOf') && !siblings.includes('anyOf') && !siblings.includes('allOf')) { + return [ + { + path, + message: ERROR_MESSAGE, + }, + ]; + } + return []; +} From e72e2d5e6e911d8084df4338f8b5c847fae08b5e Mon Sep 17 00:00:00 2001 From: Lovisa Berggren Date: Thu, 14 Aug 2025 11:29:41 +0100 Subject: [PATCH 2/8] fix: README --- tools/spectral/ipa/rulesets/README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/spectral/ipa/rulesets/README.md b/tools/spectral/ipa/rulesets/README.md index 5a0d09e4cd..091fbf43e3 100644 --- a/tools/spectral/ipa/rulesets/README.md +++ b/tools/spectral/ipa/rulesets/README.md @@ -141,7 +141,7 @@ Rule checks for the following conditions: #### xgen-IPA-104-valid-operation-id - `off` + ![warn](https://img.shields.io/badge/warning-yellow) The Operation ID must start with the verb “get” and should be followed by a noun or compound noun. The noun(s) in the Operation ID should be the collection identifiers from the resource identifier in singular form. If the resource is a singleton resource, the last noun may be the plural form of the collection identifier. @@ -207,7 +207,7 @@ The response body of the List method should consist of the same resource object - Paths with `x-xgen-IPA-exception` for this rule are excluded from validation #### xgen-IPA-105-valid-operation-id - `off` + ![warn](https://img.shields.io/badge/warning-yellow) The Operation ID must start with the verb “list” and should be followed by a noun or compound noun. The noun(s) in the Operation ID should be the collection identifiers from the resource identifier in singular form, where the last noun is in plural form. @@ -299,7 +299,7 @@ Rule checks for the following conditions: #### xgen-IPA-106-valid-operation-id - `off` + ![warn](https://img.shields.io/badge/warning-yellow) The Operation ID must start with the verb “create” and should be followed by a noun or compound noun. The noun(s) in the Operation ID should be the collection identifiers from the resource identifier in singular form. @@ -381,7 +381,7 @@ Rule checks for the following conditions: #### xgen-IPA-107-valid-operation-id - `off` + ![warn](https://img.shields.io/badge/warning-yellow) The Operation ID must start with the verb “update” and should be followed by a noun or compound noun. The noun(s) in the Operation ID should be the collection identifiers from the resource identifier in singular form. If the resource is a singleton resource, the last noun may be the plural form of the collection identifier. @@ -437,7 +437,7 @@ Rule checks for the following conditions: #### xgen-IPA-108-valid-operation-id - `off` + ![warn](https://img.shields.io/badge/warning-yellow) The Operation ID must start with the verb “delete” and should be followed by a noun or compound noun. The noun(s) in the Operation ID should be the collection identifiers from the resource identifier in singular form. @@ -493,7 +493,7 @@ Rule checks for the following conditions: #### xgen-IPA-109-valid-operation-id - `off` + ![warn](https://img.shields.io/badge/warning-yellow) The Operation ID must start with the custom method verb (the custom method path section delimited by the colon (:) character) and should be followed by a noun or compound noun. If the custom Operation ID has a verb + noun, the Operation ID should end with the noun. The noun(s) in the Operation ID should be the collection identifiers from the resource identifier. From fcf03ca64228b177415211122b91ee0a2c82ecb1 Mon Sep 17 00:00:00 2001 From: Lovisa Berggren Date: Thu, 14 Aug 2025 11:44:14 +0100 Subject: [PATCH 3/8] fix: exception level --- ...DiscriminatorMustAccompanyOneOfAnyOfAllOf.test.js | 12 ++++++------ ...PA125DiscriminatorMustAccompanyOneOfAnyOfAllOf.js | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tools/spectral/ipa/__tests__/IPA125DiscriminatorMustAccompanyOneOfAnyOfAllOf.test.js b/tools/spectral/ipa/__tests__/IPA125DiscriminatorMustAccompanyOneOfAnyOfAllOf.test.js index 4a83854caa..eac639b258 100644 --- a/tools/spectral/ipa/__tests__/IPA125DiscriminatorMustAccompanyOneOfAnyOfAllOf.test.js +++ b/tools/spectral/ipa/__tests__/IPA125DiscriminatorMustAccompanyOneOfAnyOfAllOf.test.js @@ -89,15 +89,15 @@ testRule('xgen-IPA-125-oneOf-must-accompany-oneOf-anyOf-allOf', [ Schema: { discriminator: { propertyName: 'type', - 'x-xgen-IPA-exception': { - 'xgen-IPA-125-oneOf-must-accompany-oneOf-anyOf-allOf': 'reason', - }, }, properties: { type: { type: 'string', }, }, + 'x-xgen-IPA-exception': { + 'xgen-IPA-125-oneOf-must-accompany-oneOf-anyOf-allOf': 'reason', + }, }, NestedSchema: { properties: { @@ -105,15 +105,15 @@ testRule('xgen-IPA-125-oneOf-must-accompany-oneOf-anyOf-allOf', [ type: 'object', discriminator: { propertyName: 'first', - 'x-xgen-IPA-exception': { - 'xgen-IPA-125-oneOf-must-accompany-oneOf-anyOf-allOf': 'reason', - }, }, properties: { first: { type: 'string', }, }, + 'x-xgen-IPA-exception': { + 'xgen-IPA-125-oneOf-must-accompany-oneOf-anyOf-allOf': 'reason', + }, }, address: { type: 'string', diff --git a/tools/spectral/ipa/rulesets/functions/IPA125DiscriminatorMustAccompanyOneOfAnyOfAllOf.js b/tools/spectral/ipa/rulesets/functions/IPA125DiscriminatorMustAccompanyOneOfAnyOfAllOf.js index 09dd594423..3be74c3955 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA125DiscriminatorMustAccompanyOneOfAnyOfAllOf.js +++ b/tools/spectral/ipa/rulesets/functions/IPA125DiscriminatorMustAccompanyOneOfAnyOfAllOf.js @@ -4,14 +4,14 @@ import { resolveObject } from './utils/componentUtils.js'; const ERROR_MESSAGE = "Each discriminator property must be accompanied by a 'oneOf', 'anyOf' or 'allOf' property."; export default (input, _, { path, documentInventory, rule }) => { - const errors = checkViolationsAndReturnErrors(input, path, documentInventory.resolved); - return evaluateAndCollectAdoptionStatus(errors, rule.name, input, path); -}; + const siblings = resolveObject(documentInventory.resolved, path.slice(0, path.length - 1)); -function checkViolationsAndReturnErrors(input, path, oas) { - const siblings = Object.keys(resolveObject(oas, path.slice(0, path.length - 1))); + const errors = checkViolationsAndReturnErrors(input, path, Object.keys(siblings)); + return evaluateAndCollectAdoptionStatus(errors, rule.name, siblings, path); +}; - if (!siblings.includes('oneOf') && !siblings.includes('anyOf') && !siblings.includes('allOf')) { +function checkViolationsAndReturnErrors(input, path, siblingKeys) { + if (!siblingKeys.includes('oneOf') && !siblingKeys.includes('anyOf') && !siblingKeys.includes('allOf')) { return [ { path, From 2851d73ea8fdd265e71ecaef7026c9d79f7a647e Mon Sep 17 00:00:00 2001 From: Lovisa Berggren Date: Fri, 15 Aug 2025 10:50:19 +0100 Subject: [PATCH 4/8] fix: naming --- ...25DiscriminatorMustAccompanyOneOfAnyOfAllOf.test.js | 10 +++++----- tools/spectral/ipa/rulesets/IPA-125.yaml | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/spectral/ipa/__tests__/IPA125DiscriminatorMustAccompanyOneOfAnyOfAllOf.test.js b/tools/spectral/ipa/__tests__/IPA125DiscriminatorMustAccompanyOneOfAnyOfAllOf.test.js index eac639b258..fdbb0f39df 100644 --- a/tools/spectral/ipa/__tests__/IPA125DiscriminatorMustAccompanyOneOfAnyOfAllOf.test.js +++ b/tools/spectral/ipa/__tests__/IPA125DiscriminatorMustAccompanyOneOfAnyOfAllOf.test.js @@ -1,7 +1,7 @@ import testRule from './__helpers__/testRule.js'; import { DiagnosticSeverity } from '@stoplight/types'; -testRule('xgen-IPA-125-oneOf-must-accompany-oneOf-anyOf-allOf', [ +testRule('xgen-IPA-125-discriminator-must-accompany-oneOf-anyOf-allOf', [ { name: 'valid schemas', document: { @@ -68,13 +68,13 @@ testRule('xgen-IPA-125-oneOf-must-accompany-oneOf-anyOf-allOf', [ }, errors: [ { - code: 'xgen-IPA-125-oneOf-must-accompany-oneOf-anyOf-allOf', + code: 'xgen-IPA-125-discriminator-must-accompany-oneOf-anyOf-allOf', message: "Each discriminator property must be accompanied by a 'oneOf', 'anyOf' or 'allOf' property.", path: ['components', 'schemas', 'Schema', 'discriminator'], severity: DiagnosticSeverity.Warning, }, { - code: 'xgen-IPA-125-oneOf-must-accompany-oneOf-anyOf-allOf', + code: 'xgen-IPA-125-discriminator-must-accompany-oneOf-anyOf-allOf', message: "Each discriminator property must be accompanied by a 'oneOf', 'anyOf' or 'allOf' property.", path: ['components', 'schemas', 'NestedSchema', 'properties', 'name', 'discriminator'], severity: DiagnosticSeverity.Warning, @@ -96,7 +96,7 @@ testRule('xgen-IPA-125-oneOf-must-accompany-oneOf-anyOf-allOf', [ }, }, 'x-xgen-IPA-exception': { - 'xgen-IPA-125-oneOf-must-accompany-oneOf-anyOf-allOf': 'reason', + 'xgen-IPA-125-discriminator-must-accompany-oneOf-anyOf-allOf': 'reason', }, }, NestedSchema: { @@ -112,7 +112,7 @@ testRule('xgen-IPA-125-oneOf-must-accompany-oneOf-anyOf-allOf', [ }, }, 'x-xgen-IPA-exception': { - 'xgen-IPA-125-oneOf-must-accompany-oneOf-anyOf-allOf': 'reason', + 'xgen-IPA-125-discriminator-must-accompany-oneOf-anyOf-allOf': 'reason', }, }, address: { diff --git a/tools/spectral/ipa/rulesets/IPA-125.yaml b/tools/spectral/ipa/rulesets/IPA-125.yaml index d79f563bb0..889d13477c 100644 --- a/tools/spectral/ipa/rulesets/IPA-125.yaml +++ b/tools/spectral/ipa/rulesets/IPA-125.yaml @@ -65,13 +65,13 @@ rules: then: function: 'IPA125OneOfNoBaseTypes' - xgen-IPA-125-oneOf-must-accompany-oneOf-anyOf-allOf: + xgen-IPA-125-discriminator-must-accompany-oneOf-anyOf-allOf: description: | Each discriminator property must be accompanied by a `oneOf`, `anyOf` or `allOf` property ##### Implementation details - Rule checks that a `discriminator` property has a `oneOf`, `anyOf` or `allOf` sibling - message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-125-oneOf-must-accompany-oneOf-anyOf-allOf' + message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-125-discriminator-must-accompany-oneOf-anyOf-allOf' severity: warn given: '$..discriminator' then: From 0bc337f0c1ec7e2479e3be05d67cc3361bb35e2b Mon Sep 17 00:00:00 2001 From: Lovisa Berggren Date: Fri, 15 Aug 2025 10:50:42 +0100 Subject: [PATCH 5/8] fix: ipa docs --- tools/spectral/ipa/rulesets/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/spectral/ipa/rulesets/README.md b/tools/spectral/ipa/rulesets/README.md index 091fbf43e3..56aec092a6 100644 --- a/tools/spectral/ipa/rulesets/README.md +++ b/tools/spectral/ipa/rulesets/README.md @@ -989,7 +989,7 @@ Using oneOf with multiple primitive types can lead to ambiguity and validation p be able to properly determine which type to use in which context. Instead, use more specific object types with clear discriminators. -#### xgen-IPA-125-oneOf-must-accompany-oneOf-anyOf-allOf +#### xgen-IPA-125-discriminator-must-accompany-oneOf-anyOf-allOf ![warn](https://img.shields.io/badge/warning-yellow) Each discriminator property must be accompanied by a `oneOf`, `anyOf` or `allOf` property From 6c473ea092b77397ba48fe895484bdef2ad65472 Mon Sep 17 00:00:00 2001 From: Lovisa Berggren Date: Fri, 15 Aug 2025 10:55:17 +0100 Subject: [PATCH 6/8] fix: format --- tools/spectral/ipa/rulesets/IPA-125.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/spectral/ipa/rulesets/IPA-125.yaml b/tools/spectral/ipa/rulesets/IPA-125.yaml index 4662b91c2e..a4d82eb851 100644 --- a/tools/spectral/ipa/rulesets/IPA-125.yaml +++ b/tools/spectral/ipa/rulesets/IPA-125.yaml @@ -91,4 +91,4 @@ rules: severity: warn given: '$..discriminator' then: - function: 'IPA125DiscriminatorMustAccompanyOneOfAnyOfAllOf' \ No newline at end of file + function: 'IPA125DiscriminatorMustAccompanyOneOfAnyOfAllOf' From e048cf32103698ca0838b59d81ec968d68419f77 Mon Sep 17 00:00:00 2001 From: Lovisa Berggren Date: Fri, 15 Aug 2025 11:15:11 +0100 Subject: [PATCH 7/8] fix --- .../IPA125DiscriminatorMustAccompanyOneOfAnyOfAllOf.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/spectral/ipa/__tests__/IPA125DiscriminatorMustAccompanyOneOfAnyOfAllOf.test.js b/tools/spectral/ipa/__tests__/IPA125DiscriminatorMustAccompanyOneOfAnyOfAllOf.test.js index fdbb0f39df..e7dd43f552 100644 --- a/tools/spectral/ipa/__tests__/IPA125DiscriminatorMustAccompanyOneOfAnyOfAllOf.test.js +++ b/tools/spectral/ipa/__tests__/IPA125DiscriminatorMustAccompanyOneOfAnyOfAllOf.test.js @@ -13,7 +13,7 @@ testRule('xgen-IPA-125-discriminator-must-accompany-oneOf-anyOf-allOf', [ }, oneOf: [{}], }, - SchemaAnuOf: { + SchemaAnyOf: { discriminator: { propertyName: 'type', }, From d23d11c0d6bc8bd1bbccf0c1250bd37ceea35e83 Mon Sep 17 00:00:00 2001 From: Lovisa Berggren Date: Fri, 15 Aug 2025 11:34:34 +0100 Subject: [PATCH 8/8] fix: metric path --- ...IPA125DiscriminatorMustAccompanyOneOfAnyOfAllOf.test.js | 4 ++-- .../IPA125DiscriminatorMustAccompanyOneOfAnyOfAllOf.js | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/tools/spectral/ipa/__tests__/IPA125DiscriminatorMustAccompanyOneOfAnyOfAllOf.test.js b/tools/spectral/ipa/__tests__/IPA125DiscriminatorMustAccompanyOneOfAnyOfAllOf.test.js index e7dd43f552..b4859bd16d 100644 --- a/tools/spectral/ipa/__tests__/IPA125DiscriminatorMustAccompanyOneOfAnyOfAllOf.test.js +++ b/tools/spectral/ipa/__tests__/IPA125DiscriminatorMustAccompanyOneOfAnyOfAllOf.test.js @@ -70,13 +70,13 @@ testRule('xgen-IPA-125-discriminator-must-accompany-oneOf-anyOf-allOf', [ { code: 'xgen-IPA-125-discriminator-must-accompany-oneOf-anyOf-allOf', message: "Each discriminator property must be accompanied by a 'oneOf', 'anyOf' or 'allOf' property.", - path: ['components', 'schemas', 'Schema', 'discriminator'], + path: ['components', 'schemas', 'Schema'], severity: DiagnosticSeverity.Warning, }, { code: 'xgen-IPA-125-discriminator-must-accompany-oneOf-anyOf-allOf', message: "Each discriminator property must be accompanied by a 'oneOf', 'anyOf' or 'allOf' property.", - path: ['components', 'schemas', 'NestedSchema', 'properties', 'name', 'discriminator'], + path: ['components', 'schemas', 'NestedSchema', 'properties', 'name'], severity: DiagnosticSeverity.Warning, }, ], diff --git a/tools/spectral/ipa/rulesets/functions/IPA125DiscriminatorMustAccompanyOneOfAnyOfAllOf.js b/tools/spectral/ipa/rulesets/functions/IPA125DiscriminatorMustAccompanyOneOfAnyOfAllOf.js index 3be74c3955..7d456a7b63 100644 --- a/tools/spectral/ipa/rulesets/functions/IPA125DiscriminatorMustAccompanyOneOfAnyOfAllOf.js +++ b/tools/spectral/ipa/rulesets/functions/IPA125DiscriminatorMustAccompanyOneOfAnyOfAllOf.js @@ -4,10 +4,11 @@ import { resolveObject } from './utils/componentUtils.js'; const ERROR_MESSAGE = "Each discriminator property must be accompanied by a 'oneOf', 'anyOf' or 'allOf' property."; export default (input, _, { path, documentInventory, rule }) => { - const siblings = resolveObject(documentInventory.resolved, path.slice(0, path.length - 1)); + const siblingPath = path.slice(0, path.length - 1); + const siblings = resolveObject(documentInventory.resolved, siblingPath); - const errors = checkViolationsAndReturnErrors(input, path, Object.keys(siblings)); - return evaluateAndCollectAdoptionStatus(errors, rule.name, siblings, path); + const errors = checkViolationsAndReturnErrors(input, siblingPath, Object.keys(siblings)); + return evaluateAndCollectAdoptionStatus(errors, rule.name, siblings, siblingPath); }; function checkViolationsAndReturnErrors(input, path, siblingKeys) {