@redocly/openapi-core 1.0.0-beta.78 → 1.0.0-beta.82

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.
Files changed (99) hide show
  1. package/__tests__/utils.ts +11 -1
  2. package/lib/bundle.js +18 -7
  3. package/lib/config/builtIn.js +18 -4
  4. package/lib/{rules → decorators}/common/info-description-override.d.ts +0 -0
  5. package/lib/{rules → decorators}/common/info-description-override.js +0 -0
  6. package/lib/{rules → decorators}/common/operation-description-override.d.ts +0 -0
  7. package/lib/{rules → decorators}/common/operation-description-override.js +0 -0
  8. package/lib/{rules → decorators}/common/registry-dependencies.d.ts +0 -0
  9. package/lib/{rules → decorators}/common/registry-dependencies.js +0 -0
  10. package/lib/{rules → decorators}/common/remove-x-internal.d.ts +0 -0
  11. package/lib/{rules → decorators}/common/remove-x-internal.js +20 -2
  12. package/lib/{rules → decorators}/common/tag-description-override.d.ts +0 -0
  13. package/lib/{rules → decorators}/common/tag-description-override.js +0 -0
  14. package/lib/decorators/oas2/index.d.ts +8 -0
  15. package/lib/decorators/oas2/index.js +15 -0
  16. package/lib/decorators/oas3/index.d.ts +8 -0
  17. package/lib/decorators/oas3/index.js +15 -0
  18. package/lib/js-yaml/index.js +1 -1
  19. package/lib/resolve.d.ts +1 -0
  20. package/lib/resolve.js +7 -3
  21. package/lib/rules/common/operation-security-defined.js +1 -4
  22. package/lib/rules/common/spec.js +18 -3
  23. package/lib/rules/oas2/index.d.ts +1 -8
  24. package/lib/rules/oas2/index.js +1 -13
  25. package/lib/rules/oas2/remove-unused-components.js +11 -9
  26. package/lib/rules/oas3/index.d.ts +0 -8
  27. package/lib/rules/oas3/index.js +1 -13
  28. package/lib/rules/oas3/no-invalid-media-type-examples.js +12 -11
  29. package/lib/rules/oas3/remove-unused-components.js +11 -9
  30. package/lib/types/index.d.ts +4 -0
  31. package/lib/types/oas2.js +42 -35
  32. package/lib/types/oas3.js +68 -139
  33. package/lib/types/oas3_1.js +52 -49
  34. package/lib/utils.js +1 -1
  35. package/lib/walk.js +1 -1
  36. package/package.json +1 -1
  37. package/src/__tests__/js-yaml.test.ts +29 -5
  38. package/src/__tests__/lint.test.ts +1 -3
  39. package/src/bundle.ts +21 -8
  40. package/src/config/builtIn.ts +20 -7
  41. package/src/{rules/__tests__/hide-internals.test.ts → decorators/__tests__/remove-x-internal.test.ts} +124 -42
  42. package/src/{rules → decorators}/common/info-description-override.ts +0 -0
  43. package/src/{rules → decorators}/common/operation-description-override.ts +0 -0
  44. package/src/{rules → decorators}/common/registry-dependencies.ts +0 -0
  45. package/src/{rules → decorators}/common/remove-x-internal.ts +20 -3
  46. package/src/{rules → decorators}/common/tag-description-override.ts +0 -0
  47. package/src/decorators/oas2/index.ts +14 -0
  48. package/src/decorators/oas3/index.ts +14 -0
  49. package/src/js-yaml/index.ts +1 -2
  50. package/src/redocly/registry-api.ts +4 -1
  51. package/src/resolve.ts +6 -6
  52. package/src/rules/__tests__/no-unresolved-refs.test.ts +1 -4
  53. package/src/rules/common/__tests__/info-description.test.ts +1 -3
  54. package/src/rules/common/__tests__/info-license.test.ts +1 -2
  55. package/src/rules/common/__tests__/license-url.test.ts +1 -2
  56. package/src/rules/common/__tests__/no-ambiguous-paths.test.ts +1 -2
  57. package/src/rules/common/__tests__/no-enum-type-mismatch.test.ts +1 -2
  58. package/src/rules/common/__tests__/no-identical-paths.test.ts +1 -2
  59. package/src/rules/common/__tests__/no-path-trailing-slash.test.ts +1 -2
  60. package/src/rules/common/__tests__/operation-2xx-response.test.ts +1 -2
  61. package/src/rules/common/__tests__/operation-4xx-response.test.ts +1 -2
  62. package/src/rules/common/__tests__/operation-operationId-unique.test.ts +1 -2
  63. package/src/rules/common/__tests__/operation-operationId-url-safe.test.ts +1 -2
  64. package/src/rules/common/__tests__/operation-parameters-unique.test.ts +1 -2
  65. package/src/rules/common/__tests__/operation-security-defined.test.ts +1 -2
  66. package/src/rules/common/__tests__/operation-singular-tag.test.ts +1 -2
  67. package/src/rules/common/__tests__/path-http-verbs-order.test.ts +1 -2
  68. package/src/rules/common/__tests__/path-not-include-query.test.ts +1 -2
  69. package/src/rules/common/__tests__/path-params-defined.test.ts +1 -2
  70. package/src/rules/common/__tests__/paths-kebab-case.test.ts +1 -2
  71. package/src/rules/common/__tests__/tag-description.test.ts +1 -2
  72. package/src/rules/common/__tests__/tags-alphabetical.test.ts +1 -2
  73. package/src/rules/common/operation-security-defined.ts +4 -5
  74. package/src/rules/common/spec.ts +18 -0
  75. package/src/rules/oas2/__tests__/boolean-parameter-prefixes.test.ts +1 -2
  76. package/src/rules/oas2/__tests__/spec/referenceableScalars.test.ts +1 -2
  77. package/src/rules/oas2/index.ts +1 -13
  78. package/src/rules/oas2/remove-unused-components.ts +12 -10
  79. package/src/rules/oas3/__tests__/boolean-parameter-prefixes.test.ts +1 -2
  80. package/src/rules/oas3/__tests__/no-empty-enum-servers.com.test.ts +1 -2
  81. package/src/rules/oas3/__tests__/no-example-value-and-externalValue.test.ts +1 -2
  82. package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +1 -2
  83. package/src/rules/oas3/__tests__/no-server-example.com.test.ts +1 -2
  84. package/src/rules/oas3/__tests__/no-server-trailing-slash.test.ts +1 -2
  85. package/src/rules/oas3/__tests__/no-unused-components.test.ts +1 -2
  86. package/src/rules/oas3/index.ts +0 -14
  87. package/src/rules/oas3/no-invalid-media-type-examples.ts +17 -21
  88. package/src/rules/oas3/remove-unused-components.ts +12 -10
  89. package/src/types/index.ts +4 -0
  90. package/src/types/oas2.ts +42 -40
  91. package/src/types/oas3.ts +68 -141
  92. package/src/types/oas3_1.ts +51 -50
  93. package/src/utils.ts +1 -1
  94. package/src/walk.ts +2 -4
  95. package/tsconfig.tsbuildinfo +1 -1
  96. package/lib/rules/builtin.d.ts +0 -22
  97. package/lib/rules/builtin.js +0 -17
  98. package/src/rules/__tests__/config.ts +0 -11
  99. package/src/rules/builtin.ts +0 -18
@@ -1,7 +1,6 @@
1
1
  import { outdent } from 'outdent';
2
2
  import { lintDocument } from '../../../lint';
3
- import { parseYamlToDocument, replaceSourceWithRef } from '../../../../__tests__/utils';
4
- import { makeConfig } from '../../__tests__/config';
3
+ import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../../../__tests__/utils';
5
4
  import { BaseResolver } from '../../../resolve';
6
5
 
7
6
  describe('Oas3 operation-4xx-response', () => {
@@ -1,7 +1,6 @@
1
1
  import { outdent } from 'outdent';
2
2
  import { lintDocument } from '../../../lint';
3
- import { parseYamlToDocument, replaceSourceWithRef } from '../../../../__tests__/utils';
4
- import { makeConfig } from '../../__tests__/config';
3
+ import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../../../__tests__/utils';
5
4
  import { BaseResolver } from '../../../resolve';
6
5
 
7
6
  describe('Oas3 operation-operationId-unique', () => {
@@ -1,7 +1,6 @@
1
1
  import { outdent } from 'outdent';
2
2
  import { lintDocument } from '../../../lint';
3
- import { parseYamlToDocument, replaceSourceWithRef } from '../../../../__tests__/utils';
4
- import { makeConfig } from '../../__tests__/config';
3
+ import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../../../__tests__/utils';
5
4
  import { BaseResolver } from '../../../resolve';
6
5
 
7
6
  describe('Oas3 operation-operationId-url-safe', () => {
@@ -1,7 +1,6 @@
1
1
  import { outdent } from 'outdent';
2
2
  import { lintDocument } from '../../../lint';
3
- import { parseYamlToDocument, replaceSourceWithRef } from '../../../../__tests__/utils';
4
- import { makeConfig } from '../../__tests__/config';
3
+ import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../../../__tests__/utils';
5
4
  import { BaseResolver } from '../../../resolve';
6
5
 
7
6
  describe('Oas3 operation-parameters-unique', () => {
@@ -1,7 +1,6 @@
1
1
  import { outdent } from 'outdent';
2
2
  import { lintDocument } from '../../../lint';
3
- import { parseYamlToDocument, replaceSourceWithRef } from '../../../../__tests__/utils';
4
- import { makeConfig } from '../../__tests__/config';
3
+ import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../../../__tests__/utils';
5
4
  import { BaseResolver } from '../../../resolve';
6
5
 
7
6
  describe('Oas3 operation-security-defined', () => {
@@ -1,7 +1,6 @@
1
1
  import { outdent } from 'outdent';
2
2
  import { lintDocument } from '../../../lint';
3
- import { parseYamlToDocument, replaceSourceWithRef } from '../../../../__tests__/utils';
4
- import { makeConfig } from '../../__tests__/config';
3
+ import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../../../__tests__/utils';
5
4
  import { BaseResolver } from '../../../resolve';
6
5
 
7
6
  describe('Oas3 operation-singular-tag', () => {
@@ -1,7 +1,6 @@
1
1
  import { outdent } from 'outdent';
2
2
  import { lintDocument } from '../../../lint';
3
- import { parseYamlToDocument, replaceSourceWithRef } from '../../../../__tests__/utils';
4
- import { makeConfig } from '../../__tests__/config';
3
+ import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../../../__tests__/utils';
5
4
  import { BaseResolver } from '../../../resolve';
6
5
 
7
6
  describe('Common path-http-verbs-order', () => {
@@ -1,7 +1,6 @@
1
1
  import { outdent } from 'outdent';
2
2
  import { lintDocument } from '../../../lint';
3
- import { parseYamlToDocument, replaceSourceWithRef } from '../../../../__tests__/utils';
4
- import { makeConfig } from '../../__tests__/config';
3
+ import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../../../__tests__/utils';
5
4
  import { BaseResolver } from '../../../resolve';
6
5
 
7
6
  describe('Oas3 path-not-include-query', () => {
@@ -1,7 +1,6 @@
1
1
  import { outdent } from 'outdent';
2
2
  import { lintDocument } from '../../../lint';
3
- import { parseYamlToDocument, replaceSourceWithRef } from '../../../../__tests__/utils';
4
- import { makeConfig } from '../../__tests__/config';
3
+ import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../../../__tests__/utils';
5
4
  import { BaseResolver } from '../../../resolve';
6
5
 
7
6
  describe('Oas3 path-params-defined', () => {
@@ -1,7 +1,6 @@
1
1
  import { outdent } from 'outdent';
2
2
  import { lintDocument } from '../../../lint';
3
- import { parseYamlToDocument, replaceSourceWithRef } from '../../../../__tests__/utils';
4
- import { makeConfig } from '../../__tests__/config';
3
+ import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../../../__tests__/utils';
5
4
  import { BaseResolver } from '../../../resolve';
6
5
 
7
6
  describe('Oas3 paths-kebab-case', () => {
@@ -1,7 +1,6 @@
1
1
  import { outdent } from 'outdent';
2
2
  import { lintDocument } from '../../../lint';
3
- import { parseYamlToDocument, replaceSourceWithRef } from '../../../../__tests__/utils';
4
- import { makeConfig } from '../../__tests__/config';
3
+ import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../../../__tests__/utils';
5
4
  import { BaseResolver } from '../../../resolve';
6
5
 
7
6
  describe('Oas3 tag-description', () => {
@@ -1,7 +1,6 @@
1
1
  import { outdent } from 'outdent';
2
2
  import { lintDocument } from '../../../lint';
3
- import { parseYamlToDocument, replaceSourceWithRef } from '../../../../__tests__/utils';
4
- import { makeConfig } from '../../__tests__/config';
3
+ import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../../../__tests__/utils';
5
4
  import { BaseResolver } from '../../../resolve';
6
5
 
7
6
  describe('Oas3 tags-alphabetical', () => {
@@ -1,6 +1,8 @@
1
1
  import { Oas3Rule, Oas2Rule } from '../../visitors';
2
2
  import { Location } from '../../ref-utils';
3
3
  import { UserContext } from '../../walk';
4
+ import { Oas2SecurityScheme } from '../../typings/swagger';
5
+ import { Oas3SecurityScheme } from '../../typings/openapi';
4
6
 
5
7
  export const OperationSecurityDefined: Oas3Rule | Oas2Rule = () => {
6
8
  let referencedSchemes = new Map<
@@ -25,11 +27,8 @@ export const OperationSecurityDefined: Oas3Rule | Oas2Rule = () => {
25
27
  }
26
28
  },
27
29
  },
28
- SecurityScheme(_securityScheme: object, { key }: UserContext) {
29
- referencedSchemes.set(key.toString(), {
30
- defined: true,
31
- from: [],
32
- });
30
+ SecurityScheme(_securityScheme: Oas2SecurityScheme | Oas3SecurityScheme, { key }: UserContext) {
31
+ referencedSchemes.set(key.toString(), { defined: true, from: [] });
33
32
  },
34
33
  SecurityRequirement(requirements, { location }) {
35
34
  for (const requirement of Object.keys(requirements)) {
@@ -2,6 +2,7 @@ import type { Oas3Rule, Oas2Rule } from '../../visitors';
2
2
  import { isNamedType } from '../../types';
3
3
  import { oasTypeOf, matchesJsonSchemaType, getSuggest } from '../utils';
4
4
  import { isRef } from '../../ref-utils';
5
+ import { isPlainObject } from '../../utils';
5
6
 
6
7
  export const OasSpec: Oas3Rule | Oas2Rule = () => {
7
8
  return {
@@ -26,6 +27,7 @@ export const OasSpec: Oas3Rule | Oas2Rule = () => {
26
27
 
27
28
  const required =
28
29
  typeof type.required === 'function' ? type.required(node, key) : type.required;
30
+
29
31
  for (let propName of required || []) {
30
32
  if (!(node as object).hasOwnProperty(propName)) {
31
33
  report({
@@ -35,6 +37,22 @@ export const OasSpec: Oas3Rule | Oas2Rule = () => {
35
37
  }
36
38
  }
37
39
 
40
+ const allowed = type.allowed?.(node);
41
+ if (allowed && isPlainObject(node)) {
42
+ for (const propName in node) {
43
+ if (allowed.includes(propName) ||
44
+ (type.extensionsPrefix && propName.startsWith(type.extensionsPrefix)) ||
45
+ !Object.keys(type.properties).includes(propName)
46
+ ) {
47
+ continue;
48
+ }
49
+ report({
50
+ message: `The field \`${propName}\` is not allowed here.`,
51
+ location: location.child([propName]).key()
52
+ });
53
+ }
54
+ }
55
+
38
56
  const requiredOneOf = type.requiredOneOf || null;
39
57
  if (requiredOneOf) {
40
58
  let hasProperty = false;
@@ -1,6 +1,5 @@
1
1
  import { outdent } from 'outdent';
2
- import { parseYamlToDocument, replaceSourceWithRef } from '../../../../__tests__/utils';
3
- import { makeConfig } from '../../__tests__/config';
2
+ import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../../../__tests__/utils';
4
3
  import { lintDocument } from '../../../lint';
5
4
  import { BaseResolver } from '../../../resolve';
6
5
 
@@ -1,8 +1,7 @@
1
1
  import { outdent } from 'outdent';
2
- import { parseYamlToDocument, replaceSourceWithRef } from '../../../../../__tests__/utils';
2
+ import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../../../../__tests__/utils';
3
3
  import { lintDocument } from '../../../../lint';
4
4
  import { BaseResolver } from '../../../../resolve';
5
- import { makeConfig } from '../../../__tests__/config';
6
5
 
7
6
  describe('Referenceable scalars', () => {
8
7
  it('should not report $ref description', async () => {
@@ -1,4 +1,4 @@
1
- import { Oas2Decorator, Oas2Rule } from '../../visitors';
1
+ import { Oas2Rule } from '../../visitors';
2
2
  import { OasSpec } from '../common/spec';
3
3
  import { NoInvalidSchemaExamples } from '../common/no-invalid-schema-examples';
4
4
  import { NoInvalidParameterExamples } from '../common/no-invalid-parameter-examples';
@@ -27,7 +27,6 @@ import { OperationSingularTag } from '../common/operation-singular-tag';
27
27
  import { OperationSecurityDefined } from '../common/operation-security-defined';
28
28
  import { NoUnresolvedRefs } from '../no-unresolved-refs';
29
29
  import { PathHttpVerbsOrder } from '../common/path-http-verbs-order';
30
- import { RegistryDependencies } from '../common/registry-dependencies';
31
30
  import { NoIdenticalPaths } from '../common/no-identical-paths';
32
31
  import { OperationOperationId } from '../common/operation-operationId';
33
32
  import { OperationSummary } from '../common/operation-summary';
@@ -37,10 +36,6 @@ import { PathExcludesPatterns } from '../common/path-excludes-patterns';
37
36
  import { RequestMimeType } from './request-mime-type';
38
37
  import { ResponseMimeType } from './response-mime-type';
39
38
  import { PathSegmentPlural } from '../common/path-segment-plural';
40
- import { OperationDescriptionOverride } from '../common/operation-description-override';
41
- import { TagDescriptionOverride } from '../common/tag-description-override';
42
- import { InfoDescriptionOverride } from '../common/info-description-override';
43
- import { RemoveXInternal } from '../common/remove-x-internal';
44
39
 
45
40
  export const rules = {
46
41
  spec: OasSpec as Oas2Rule,
@@ -84,10 +79,3 @@ export const rules = {
84
79
  };
85
80
 
86
81
  export const preprocessors = {};
87
- export const decorators = {
88
- 'registry-dependencies': RegistryDependencies as Oas2Decorator,
89
- 'operation-description-override': OperationDescriptionOverride as Oas2Decorator,
90
- 'tag-description-override': TagDescriptionOverride as Oas2Decorator,
91
- 'info-description-override': InfoDescriptionOverride as Oas2Decorator,
92
- 'remove-x-internal': RemoveXInternal as Oas2Decorator
93
- };
@@ -15,16 +15,18 @@ export const RemoveUnusedComponents: Oas2Rule = () => {
15
15
  }
16
16
 
17
17
  return {
18
- ref(ref, { type, resolve, key }) {
19
- if (
20
- ['Schema', 'Parameter', 'Response', 'SecurityScheme'].includes(type.name)
21
- ) {
22
- const resolvedRef = resolve(ref);
23
- if (!resolvedRef.location) return;
24
- components.set(resolvedRef.location.absolutePointer, {
25
- used: true,
26
- name: key.toString(),
27
- });
18
+ ref: {
19
+ leave(ref, { type, resolve, key }) {
20
+ if (
21
+ ['Schema', 'Parameter', 'Response', 'SecurityScheme'].includes(type.name)
22
+ ) {
23
+ const resolvedRef = resolve(ref);
24
+ if (!resolvedRef.location) return;
25
+ components.set(resolvedRef.location.absolutePointer, {
26
+ used: true,
27
+ name: key.toString(),
28
+ });
29
+ }
28
30
  }
29
31
  },
30
32
  DefinitionRoot: {
@@ -1,6 +1,5 @@
1
1
  import { outdent } from 'outdent';
2
- import { parseYamlToDocument, replaceSourceWithRef } from '../../../../__tests__/utils';
3
- import { makeConfig } from '../../__tests__/config';
2
+ import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../../../__tests__/utils';
4
3
  import { lintDocument } from '../../../lint';
5
4
  import { BaseResolver } from '../../../resolve';
6
5
 
@@ -1,8 +1,7 @@
1
1
  import { outdent } from 'outdent';
2
2
  import { lintDocument } from '../../../lint';
3
- import { parseYamlToDocument, replaceSourceWithRef } from '../../../../__tests__/utils';
3
+ import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../../../__tests__/utils';
4
4
  import { BaseResolver } from '../../../resolve';
5
- import { makeConfig } from '../../__tests__/config';
6
5
 
7
6
  describe('Oas3 as3-no-servers-empty-enum', () => {
8
7
  it('oas3-no-servers-empty-enum: should report on server object with empty enum and unknown enum value', async () => {
@@ -1,8 +1,7 @@
1
1
  import { outdent } from 'outdent';
2
2
  import { lintDocument } from '../../../lint';
3
- import { parseYamlToDocument, replaceSourceWithRef } from '../../../../__tests__/utils';
3
+ import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../../../__tests__/utils';
4
4
  import { BaseResolver } from '../../../resolve';
5
- import { makeConfig } from '../../__tests__/config';
6
5
 
7
6
  describe('Oas3 oas3-no-example-value-and-externalValue', () => {
8
7
  it('oas3-no-example-value-and-externalValue: should report on example object with both value and external value', async () => {
@@ -1,7 +1,6 @@
1
1
  import { outdent } from 'outdent';
2
2
  import { lintDocument } from '../../../lint';
3
- import { parseYamlToDocument, replaceSourceWithRef } from '../../../../__tests__/utils';
4
- import { makeConfig } from '../../__tests__/config';
3
+ import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../../../__tests__/utils';
5
4
  import { BaseResolver } from '../../../resolve';
6
5
 
7
6
  describe('no-invalid-media-type-examples', () => {
@@ -1,7 +1,6 @@
1
1
  import { outdent } from 'outdent';
2
2
  import { lintDocument } from '../../../lint';
3
- import { parseYamlToDocument, replaceSourceWithRef } from '../../../../__tests__/utils';
4
- import { makeConfig } from '../../__tests__/config';
3
+ import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../../../__tests__/utils';
5
4
  import { BaseResolver } from '../../../resolve';
6
5
 
7
6
  describe('Oas3 oas3-no-server-example.com', () => {
@@ -1,7 +1,6 @@
1
1
  import { outdent } from 'outdent';
2
2
  import { lintDocument } from '../../../lint';
3
- import { parseYamlToDocument, replaceSourceWithRef } from '../../../../__tests__/utils';
4
- import { makeConfig } from '../../__tests__/config';
3
+ import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../../../__tests__/utils';
5
4
  import { BaseResolver } from '../../../resolve';
6
5
 
7
6
  describe('Oas3 oas3-no-server-trailing-slash', () => {
@@ -1,7 +1,6 @@
1
1
  import { outdent } from 'outdent';
2
2
  import { lintDocument } from '../../../lint';
3
- import { parseYamlToDocument, replaceSourceWithRef } from '../../../../__tests__/utils';
4
- import { makeConfig } from '../../__tests__/config';
3
+ import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../../../__tests__/utils';
5
4
  import { BaseResolver } from '../../../resolve';
6
5
 
7
6
  describe('Oas3 no-unused-components', () => {
@@ -1,5 +1,4 @@
1
1
  import { Oas3RuleSet } from '../../oas-types';
2
- import { Oas3Decorator } from '../../visitors';
3
2
  import { OasSpec } from '../common/spec';
4
3
  import { Operation2xxResponse } from '../common/operation-2xx-response';
5
4
  import { Operation4xxResponse } from '../common/operation-4xx-response';
@@ -32,7 +31,6 @@ import { PathsKebabCase } from '../common/paths-kebab-case';
32
31
  import { PathHttpVerbsOrder } from '../common/path-http-verbs-order';
33
32
  import { NoEmptyServers } from './no-empty-servers';
34
33
  import { ValidContentExamples } from './no-invalid-media-type-examples';
35
- import { RegistryDependencies } from '../common/registry-dependencies';
36
34
  import { NoIdenticalPaths } from '../common/no-identical-paths';
37
35
  import { NoUndefinedServerVariable } from './no-undefined-server-variable';
38
36
  import { OperationOperationId } from '../common/operation-operationId';
@@ -43,13 +41,9 @@ import { NoHttpVerbsInPaths } from '../common/no-http-verbs-in-paths';
43
41
  import { RequestMimeType } from './request-mime-type';
44
42
  import { ResponseMimeType } from './response-mime-type';
45
43
  import { PathSegmentPlural } from '../common/path-segment-plural';
46
- import { OperationDescriptionOverride } from '../common/operation-description-override';
47
- import { TagDescriptionOverride } from '../common/tag-description-override';
48
- import { InfoDescriptionOverride } from '../common/info-description-override';
49
44
  import { PathExcludesPatterns } from '../common/path-excludes-patterns';
50
45
  import { NoInvalidSchemaExamples } from '../common/no-invalid-schema-examples';
51
46
  import { NoInvalidParameterExamples } from '../common/no-invalid-parameter-examples';
52
- import { RemoveXInternal } from '../common/remove-x-internal';
53
47
 
54
48
  export const rules = {
55
49
  spec: OasSpec,
@@ -101,11 +95,3 @@ export const rules = {
101
95
  } as Oas3RuleSet;
102
96
 
103
97
  export const preprocessors = {};
104
-
105
- export const decorators = {
106
- 'registry-dependencies': RegistryDependencies as Oas3Decorator,
107
- 'operation-description-override': OperationDescriptionOverride as Oas3Decorator,
108
- 'tag-description-override': TagDescriptionOverride as Oas3Decorator,
109
- 'info-description-override': InfoDescriptionOverride as Oas3Decorator,
110
- 'remove-x-internal': RemoveXInternal as Oas3Decorator
111
- };
@@ -13,31 +13,27 @@ export const ValidContentExamples: Oas3Rule = (opts) => {
13
13
  const { location, resolve } = ctx;
14
14
  if (!mediaType.schema) return;
15
15
  if (mediaType.example) {
16
+ resolveAndValidateExample(mediaType.example, location.child('example'));
17
+ } else if (mediaType.examples) {
18
+ for (const exampleName of Object.keys(mediaType.examples)) {
19
+ resolveAndValidateExample(mediaType.examples[exampleName], location.child(['examples', exampleName, 'value']), true);
20
+ }
21
+ }
22
+
23
+ function resolveAndValidateExample(example: Oas3Example | any, location: Location, isMultiple?: boolean) {
24
+ if (isRef(example)) {
25
+ const resolved = resolve<Oas3Example>(example);
26
+ if (!resolved.location) return;
27
+ location = isMultiple ? resolved.location.child('value') : resolved.location;
28
+ example = resolved.node;
29
+ }
16
30
  validateExample(
17
- mediaType.example,
18
- mediaType.schema,
19
- location.child('example'),
31
+ isMultiple ? example.value : example,
32
+ mediaType.schema!,
33
+ location,
20
34
  ctx,
21
35
  disallowAdditionalProperties,
22
36
  );
23
- } else if (mediaType.examples) {
24
- for (const exampleName of Object.keys(mediaType.examples)) {
25
- let example = mediaType.examples[exampleName];
26
- let dataLoc: Location = location.child(['examples', exampleName, 'value']);
27
- if (isRef(example)) {
28
- const resolved = resolve<Oas3Example>(example);
29
- if (!resolved.location) continue;
30
- dataLoc = resolved.location.child('value');
31
- example = resolved.node;
32
- }
33
- validateExample(
34
- example.value,
35
- mediaType.schema,
36
- dataLoc,
37
- ctx,
38
- disallowAdditionalProperties,
39
- );
40
- }
41
37
  }
42
38
  },
43
39
  },
@@ -15,16 +15,18 @@ export const RemoveUnusedComponents: Oas3Rule = () => {
15
15
  }
16
16
 
17
17
  return {
18
- ref(ref, { type, resolve, key }) {
19
- if (
20
- ['Schema', 'Header', 'Parameter', 'Response', 'Example', 'RequestBody'].includes(type.name)
21
- ) {
22
- const resolvedRef = resolve(ref);
23
- if (!resolvedRef.location) return;
24
- components.set(resolvedRef.location.absolutePointer, {
25
- used: true,
26
- name: key.toString(),
27
- });
18
+ ref: {
19
+ leave(ref, { type, resolve, key }) {
20
+ if (
21
+ ['Schema', 'Header', 'Parameter', 'Response', 'Example', 'RequestBody'].includes(type.name)
22
+ ) {
23
+ const resolvedRef = resolve(ref);
24
+ if (!resolvedRef.location) return;
25
+ components.set(resolvedRef.location.absolutePointer, {
26
+ used: true,
27
+ name: key.toString(),
28
+ });
29
+ }
28
30
  }
29
31
  },
30
32
  DefinitionRoot: {
@@ -24,6 +24,8 @@ export type NodeType = {
24
24
  items?: string;
25
25
  required?: string[] | ((value: any, key: string | number | undefined) => string[]);
26
26
  requiredOneOf?: string[];
27
+ allowed?: ((value: any) => string[] | undefined);
28
+ extensionsPrefix?: string;
27
29
  };
28
30
  type PropType = string | NodeType | ScalarSchema | undefined | null;
29
31
  type ResolveTypeFn = (value: any, key: string) => string | PropType;
@@ -35,6 +37,8 @@ export type NormalizedNodeType = {
35
37
  items?: NormalizedNodeType;
36
38
  required?: string[] | ((value: any, key: string | number | undefined) => string[]);
37
39
  requiredOneOf?: string[];
40
+ allowed?: ((value: any) => string[] | undefined);
41
+ extensionsPrefix?: string;
38
42
  };
39
43
 
40
44
  type NormalizedPropType = NormalizedNodeType | NormalizedScalarSchema | undefined | null;