@redocly/openapi-core 0.0.0-snapshot.1775468574 → 0.0.0-snapshot.1775489865

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"no-required-schema-properties-undefined.d.ts","sourceRoot":"","sources":["../../../src/rules/common/no-required-schema-properties-undefined.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAKjG,eAAO,MAAM,mCAAmC,EAC5C,QAAQ,GACR,QAAQ,GACR,UAAU,GACV,UAAU,GACV,WAkGH,CAAC"}
1
+ {"version":3,"file":"no-required-schema-properties-undefined.d.ts","sourceRoot":"","sources":["../../../src/rules/common/no-required-schema-properties-undefined.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AASjG,eAAO,MAAM,mCAAmC,EAC5C,QAAQ,GACR,QAAQ,GACR,UAAU,GACV,UAAU,GACV,WA+EH,CAAC"}
@@ -1,5 +1,6 @@
1
- import { isRef } from '../../ref-utils.js';
2
1
  import { getOwn } from '../../utils/get-own.js';
2
+ import { isNotEmptyArray } from '../../utils/is-not-empty-array.js';
3
+ import { resolveSchema } from '../utils.js';
3
4
  export const NoRequiredSchemaPropertiesUndefined = () => {
4
5
  const parents = [];
5
6
  return {
@@ -7,67 +8,52 @@ export const NoRequiredSchemaPropertiesUndefined = () => {
7
8
  leave(_) {
8
9
  parents.pop();
9
10
  },
10
- enter(schema, { location, report, resolve }) {
11
- parents.push(schema);
12
- if (!schema.required)
11
+ enter(currentSchema, ctx) {
12
+ parents.push(currentSchema);
13
+ if (!currentSchema.required)
13
14
  return;
14
- const visitedSchemas = new Set();
15
- const elevateProperties = (schema, from, includeFirstLevelExclusiveSchemas = true) => {
16
- // Check if the schema has been visited before processing it
17
- if (visitedSchemas.has(schema)) {
18
- return {};
15
+ const hasProperty = (schemaOrRef, propertyName, visited, resolveFrom) => {
16
+ const { schema, location } = resolveSchema(schemaOrRef, ctx, resolveFrom);
17
+ if (!schema || visited.has(schema))
18
+ return false;
19
+ visited.add(schema);
20
+ if (schema.properties && getOwn(schema.properties, propertyName) !== undefined) {
21
+ return true;
19
22
  }
20
- visitedSchemas.add(schema);
21
- if (isRef(schema)) {
22
- const resolved = resolve(schema, from);
23
- if (!resolved.node) {
24
- return {};
25
- }
26
- return elevateProperties(resolved.node, resolved.location?.source.absoluteRef);
23
+ if (schema.allOf?.some((s) => hasProperty(s, propertyName, visited, location))) {
24
+ return true;
27
25
  }
28
- return Object.assign({}, schema.properties, ...(schema.allOf?.map((s) => elevateProperties(s, from)) ?? []), ...(('anyOf' in schema && includeFirstLevelExclusiveSchemas
29
- ? schema.anyOf?.map((s) => elevateProperties(s, from))
30
- : undefined) ?? []), ...(('oneOf' in schema && includeFirstLevelExclusiveSchemas
31
- ? schema.oneOf?.map((s) => elevateProperties(s, from))
32
- : undefined) ?? []));
26
+ if (isNotEmptyArray(schema.anyOf) &&
27
+ schema.anyOf.every((s) => hasProperty(s, propertyName, new Set(visited), location))) {
28
+ return true;
29
+ }
30
+ if (isNotEmptyArray(schema.oneOf) &&
31
+ schema.oneOf.every((s) => hasProperty(s, propertyName, new Set(visited), location))) {
32
+ return true;
33
+ }
34
+ return false;
33
35
  };
34
- /**
35
- * The index to use to lookup grand parent schemas when dealing with composed schemas.
36
- * @summary The current schema should always end up with under ../anyOf/1, if we get multiple ancestors, they should always be a multiple.
37
- */
38
- const locationLookupIndex = 2;
39
- const getParentSchema = (lookupIndex) => {
40
- lookupIndex++;
41
- if (!parents || parents.length < lookupIndex)
42
- return undefined;
43
- const parent = parents[parents.length - lookupIndex];
44
- return parent;
36
+ const isCompositionChild = (parent, child) => {
37
+ const matchesChild = (s) => resolveSchema(s, ctx).schema === child;
38
+ return !!(parent.allOf?.some(matchesChild) ||
39
+ parent.anyOf?.some(matchesChild) ||
40
+ parent.oneOf?.some(matchesChild));
45
41
  };
46
- const recursivelyGetParentProperties = (splitLocation, parentLookupIndex = 0) => {
47
- const isMemberOfComposedType = splitLocation.length > locationLookupIndex &&
48
- !isNaN(parseInt(splitLocation[splitLocation.length - 1])) &&
49
- !!/(allOf|oneOf|anyOf)/.exec(splitLocation[splitLocation.length - locationLookupIndex]);
50
- const parentSchema = isMemberOfComposedType
51
- ? getParentSchema(++parentLookupIndex)
52
- : undefined;
53
- const grandParentProperties = splitLocation.length >= locationLookupIndex + locationLookupIndex
54
- ? recursivelyGetParentProperties(splitLocation.slice(0, -locationLookupIndex), parentLookupIndex)
55
- : {};
56
- return parentSchema
57
- ? {
58
- ...elevateProperties(parentSchema, undefined, false),
59
- ...grandParentProperties,
60
- }
42
+ const findCompositionRoot = (i, child) => {
43
+ if (i < 0)
44
+ return undefined;
45
+ const parent = parents[i];
46
+ return isCompositionChild(parent, child)
47
+ ? (findCompositionRoot(i - 1, parent) ?? parent)
61
48
  : undefined;
62
49
  };
63
- const allProperties = elevateProperties(schema);
64
- const parentProperties = recursivelyGetParentProperties(location.pointer.split('/'));
65
- for (const [i, requiredProperty] of schema.required.entries()) {
66
- if ((!allProperties || getOwn(allProperties, requiredProperty) === undefined) &&
67
- (!parentProperties || getOwn(parentProperties, requiredProperty) === undefined)) {
68
- report({
69
- message: `Required property '${requiredProperty}' is undefined.`,
70
- location: location.child(['required', i]),
50
+ const compositionRoot = findCompositionRoot(parents.length - 2, currentSchema);
51
+ for (const [i, requiredProperty] of currentSchema.required.entries()) {
52
+ if (!hasProperty(currentSchema, requiredProperty, new Set()) &&
53
+ !hasProperty(compositionRoot, requiredProperty, new Set())) {
54
+ ctx.report({
55
+ message: `Required property '${requiredProperty}' is not defined.`,
56
+ location: ctx.location.child(['required', i]),
71
57
  });
72
58
  }
73
59
  }
@@ -1 +1 @@
1
- {"version":3,"file":"no-required-schema-properties-undefined.js","sourceRoot":"","sources":["../../../src/rules/common/no-required-schema-properties-undefined.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAG3C,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAMhD,MAAM,CAAC,MAAM,mCAAmC,GAK9B,GAAG,EAAE;IACrB,MAAM,OAAO,GAAgB,EAAE,CAAC;IAChC,OAAO;QACL,MAAM,EAAE;YACN,KAAK,CAAC,CAAY;gBAChB,OAAO,CAAC,GAAG,EAAE,CAAC;YAChB,CAAC;YACD,KAAK,CAAC,MAAiB,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAe;gBACjE,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;gBACrB,IAAI,CAAC,MAAM,CAAC,QAAQ;oBAAE,OAAO;gBAC7B,MAAM,cAAc,GAAmB,IAAI,GAAG,EAAE,CAAC;gBAEjD,MAAM,iBAAiB,GAAG,CACxB,MAAiB,EACjB,IAAa,EACb,oCAA6C,IAAI,EACtB,EAAE;oBAC7B,4DAA4D;oBAC5D,IAAI,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;wBAC/B,OAAO,EAAE,CAAC;oBACZ,CAAC;oBACD,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;oBAE3B,IAAI,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;wBAClB,MAAM,QAAQ,GAAG,OAAO,CAAY,MAAM,EAAE,IAAI,CAAC,CAAC;wBAClD,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;4BACnB,OAAO,EAAE,CAAC;wBACZ,CAAC;wBACD,OAAO,iBAAiB,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;oBACjF,CAAC;oBAED,OAAO,MAAM,CAAC,MAAM,CAClB,EAA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AE,CAAC,CAAC,CAAC;yBAC1C,CAAC,CAAC;oBACL,CAAC;gBACH,CAAC;YACH,CAAC;SACF;KACF,CAAC;AACJ,CAAC,CAAC"}
1
+ {"version":3,"file":"no-required-schema-properties-undefined.js","sourceRoot":"","sources":["../../../src/rules/common/no-required-schema-properties-undefined.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AAGpE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAO5C,MAAM,CAAC,MAAM,mCAAmC,GAK9B,GAAG,EAAE;IACrB,MAAM,OAAO,GAAgB,EAAE,CAAC;IAChC,OAAO;QACL,MAAM,EAAE;YACN,KAAK,CAAC,CAAY;gBAChB,OAAO,CAAC,GAAG,EAAE,CAAC;YAChB,CAAC;YACD,KAAK,CAAC,aAAwB,EAAE,GAAgB;gBAC9C,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;gBAC5B,IAAI,CAAC,aAAa,CAAC,QAAQ;oBAAE,OAAO;gBAEpC,MAAM,WAAW,GAAG,CAClB,WAAkC,EAClC,YAAoB,EACpB,OAAuB,EACvB,WAAoB,EACX,EAAE;oBACX,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,aAAa,CAAC,WAAW,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC;oBAC1E,IAAI,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC;wBAAE,OAAO,KAAK,CAAC;oBACjD,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;oBAEpB,IAAI,MAAM,CAAC,UAAU,IAAI,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,YAAY,CAAC,KAAK,SAAS,EAAE,CAAC;wBAC/E,OAAO,IAAI,CAAC;oBACd,CAAC;oBAED,IAAI,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,CAA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,CAAC;oBAC5B,MAAM,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;oBAC1B,OAAO,kBAAkB,CAAC,MAAM,EAAE,KAAK,CAAC;wBACtC,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC;wBAChD,CAAC,CAAC,SAAS,CAAC;gBAChB,CAAC,CAAC;gBAEF,MAAM,eAAe,GAAG,mBAAmB,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,aAAa,CAAC,CAAC;gBAE/E,KAAK,MAAM,CAAC,CAAC,EAAE,gBAAgB,CAAC,IAAI,aAAa,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC;oBACrE,IACE,CAAC,WAAW,CAAC,aAAa,EAAE,gBAAgB,EAAE,IAAI,GAAG,EAAE,CAAC;wBACxD,CAAC,WAAW,CAAC,eAAe,EAAE,gBAAgB,EAAE,IAAI,GAAG,EAAE,CAAC,EAC1D,CAAC;wBACD,GAAG,CAAC,MAAM,CAAC;4BACT,OAAO,EAAE,sBAAsB,gBAAgB,mBAAmB;4BAClE,QAAQ,EAAE,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;yBAC9C,CAAC,CAAC;oBACL,CAAC;gBACH,CAAC;YACH,CAAC;SACF;KACF,CAAC;AACJ,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redocly/openapi-core",
3
- "version": "0.0.0-snapshot.1775468574",
3
+ "version": "0.0.0-snapshot.1775489865",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "types": "lib/index.d.ts",