@redocly/openapi-core 1.0.0-beta.79 → 1.0.0-beta.83
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.
- package/__tests__/utils.ts +11 -1
- package/lib/config/builtIn.js +18 -4
- package/lib/{rules → decorators}/common/info-description-override.d.ts +0 -0
- package/lib/{rules → decorators}/common/info-description-override.js +0 -0
- package/lib/{rules → decorators}/common/operation-description-override.d.ts +0 -0
- package/lib/{rules → decorators}/common/operation-description-override.js +0 -0
- package/lib/{rules → decorators}/common/registry-dependencies.d.ts +0 -0
- package/lib/{rules → decorators}/common/registry-dependencies.js +0 -0
- package/lib/{rules → decorators}/common/remove-x-internal.d.ts +0 -0
- package/lib/{rules → decorators}/common/remove-x-internal.js +0 -0
- package/lib/{rules → decorators}/common/tag-description-override.d.ts +0 -0
- package/lib/{rules → decorators}/common/tag-description-override.js +0 -0
- package/lib/decorators/oas2/index.d.ts +8 -0
- package/lib/decorators/oas2/index.js +15 -0
- package/lib/decorators/oas3/index.d.ts +8 -0
- package/lib/decorators/oas3/index.js +15 -0
- package/lib/index.d.ts +2 -2
- package/lib/index.js +2 -1
- package/lib/js-yaml/index.js +1 -1
- package/lib/rules/common/operation-security-defined.js +1 -4
- package/lib/rules/common/spec.js +18 -3
- package/lib/rules/oas2/index.d.ts +1 -8
- package/lib/rules/oas2/index.js +1 -13
- package/lib/rules/oas3/index.d.ts +0 -8
- package/lib/rules/oas3/index.js +1 -13
- package/lib/rules/oas3/no-invalid-media-type-examples.js +12 -11
- package/lib/types/index.d.ts +4 -0
- package/lib/types/oas2.js +42 -35
- package/lib/types/oas3.js +68 -139
- package/lib/types/oas3_1.js +52 -49
- package/lib/typings/openapi.d.ts +7 -0
- package/lib/utils.js +1 -1
- package/package.json +1 -1
- package/src/__tests__/js-yaml.test.ts +29 -5
- package/src/__tests__/lint.test.ts +1 -3
- package/src/config/builtIn.ts +20 -7
- package/src/{rules/__tests__/hide-internals.test.ts → decorators/__tests__/remove-x-internal.test.ts} +1 -2
- package/src/{rules → decorators}/common/info-description-override.ts +0 -0
- package/src/{rules → decorators}/common/operation-description-override.ts +0 -0
- package/src/{rules → decorators}/common/registry-dependencies.ts +0 -0
- package/src/{rules → decorators}/common/remove-x-internal.ts +0 -0
- package/src/{rules → decorators}/common/tag-description-override.ts +0 -0
- package/src/decorators/oas2/index.ts +14 -0
- package/src/decorators/oas3/index.ts +14 -0
- package/src/index.ts +5 -1
- package/src/js-yaml/index.ts +1 -2
- package/src/redocly/registry-api.ts +4 -1
- package/src/rules/__tests__/no-unresolved-refs.test.ts +1 -4
- package/src/rules/common/__tests__/info-description.test.ts +1 -3
- package/src/rules/common/__tests__/info-license.test.ts +1 -2
- package/src/rules/common/__tests__/license-url.test.ts +1 -2
- package/src/rules/common/__tests__/no-ambiguous-paths.test.ts +1 -2
- package/src/rules/common/__tests__/no-enum-type-mismatch.test.ts +1 -2
- package/src/rules/common/__tests__/no-identical-paths.test.ts +1 -2
- package/src/rules/common/__tests__/no-path-trailing-slash.test.ts +1 -2
- package/src/rules/common/__tests__/operation-2xx-response.test.ts +1 -2
- package/src/rules/common/__tests__/operation-4xx-response.test.ts +1 -2
- package/src/rules/common/__tests__/operation-operationId-unique.test.ts +1 -2
- package/src/rules/common/__tests__/operation-operationId-url-safe.test.ts +1 -2
- package/src/rules/common/__tests__/operation-parameters-unique.test.ts +1 -2
- package/src/rules/common/__tests__/operation-security-defined.test.ts +1 -2
- package/src/rules/common/__tests__/operation-singular-tag.test.ts +1 -2
- package/src/rules/common/__tests__/path-http-verbs-order.test.ts +1 -2
- package/src/rules/common/__tests__/path-not-include-query.test.ts +1 -2
- package/src/rules/common/__tests__/path-params-defined.test.ts +1 -2
- package/src/rules/common/__tests__/paths-kebab-case.test.ts +1 -2
- package/src/rules/common/__tests__/tag-description.test.ts +1 -2
- package/src/rules/common/__tests__/tags-alphabetical.test.ts +1 -2
- package/src/rules/common/operation-security-defined.ts +4 -5
- package/src/rules/common/spec.ts +18 -0
- package/src/rules/oas2/__tests__/boolean-parameter-prefixes.test.ts +1 -2
- package/src/rules/oas2/__tests__/spec/referenceableScalars.test.ts +1 -2
- package/src/rules/oas2/index.ts +1 -13
- package/src/rules/oas3/__tests__/boolean-parameter-prefixes.test.ts +1 -2
- package/src/rules/oas3/__tests__/no-empty-enum-servers.com.test.ts +1 -2
- package/src/rules/oas3/__tests__/no-example-value-and-externalValue.test.ts +1 -2
- package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +1 -2
- package/src/rules/oas3/__tests__/no-server-example.com.test.ts +1 -2
- package/src/rules/oas3/__tests__/no-server-trailing-slash.test.ts +1 -2
- package/src/rules/oas3/__tests__/no-unused-components.test.ts +1 -2
- package/src/rules/oas3/index.ts +0 -14
- package/src/rules/oas3/no-invalid-media-type-examples.ts +17 -21
- package/src/types/index.ts +4 -0
- package/src/types/oas2.ts +42 -40
- package/src/types/oas3.ts +68 -141
- package/src/types/oas3_1.ts +51 -50
- package/src/typings/openapi.ts +9 -0
- package/src/utils.ts +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/lib/rules/builtin.d.ts +0 -22
- package/lib/rules/builtin.js +0 -17
- package/src/rules/__tests__/config.ts +0 -11
- package/src/rules/builtin.ts +0 -18
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Oas2Decorator } from '../../visitors';
|
|
2
|
+
import { RegistryDependencies } from '../common/registry-dependencies';
|
|
3
|
+
import { OperationDescriptionOverride } from '../common/operation-description-override';
|
|
4
|
+
import { TagDescriptionOverride } from '../common/tag-description-override';
|
|
5
|
+
import { InfoDescriptionOverride } from '../common/info-description-override';
|
|
6
|
+
import { RemoveXInternal } from '../common/remove-x-internal';
|
|
7
|
+
|
|
8
|
+
export const decorators = {
|
|
9
|
+
'registry-dependencies': RegistryDependencies as Oas2Decorator,
|
|
10
|
+
'operation-description-override': OperationDescriptionOverride as Oas2Decorator,
|
|
11
|
+
'tag-description-override': TagDescriptionOverride as Oas2Decorator,
|
|
12
|
+
'info-description-override': InfoDescriptionOverride as Oas2Decorator,
|
|
13
|
+
'remove-x-internal': RemoveXInternal as Oas2Decorator
|
|
14
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Oas3Decorator } from '../../visitors';
|
|
2
|
+
import { RegistryDependencies } from '../common/registry-dependencies';
|
|
3
|
+
import { OperationDescriptionOverride } from '../common/operation-description-override';
|
|
4
|
+
import { TagDescriptionOverride } from '../common/tag-description-override';
|
|
5
|
+
import { InfoDescriptionOverride } from '../common/info-description-override';
|
|
6
|
+
import { RemoveXInternal } from '../common/remove-x-internal';
|
|
7
|
+
|
|
8
|
+
export const decorators = {
|
|
9
|
+
'registry-dependencies': RegistryDependencies as Oas3Decorator,
|
|
10
|
+
'operation-description-override': OperationDescriptionOverride as Oas3Decorator,
|
|
11
|
+
'tag-description-override': TagDescriptionOverride as Oas3Decorator,
|
|
12
|
+
'info-description-override': InfoDescriptionOverride as Oas3Decorator,
|
|
13
|
+
'remove-x-internal': RemoveXInternal as Oas3Decorator
|
|
14
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -5,12 +5,16 @@ export { Oas2Types } from './types/oas2';
|
|
|
5
5
|
export { ConfigTypes } from './types/redocly-yaml';
|
|
6
6
|
export {
|
|
7
7
|
Oas3Definition,
|
|
8
|
+
Oas3_1Definition,
|
|
8
9
|
Oas3Components,
|
|
9
10
|
Oas3PathItem,
|
|
10
11
|
Oas3Paths,
|
|
11
12
|
Oas3ComponentName,
|
|
12
13
|
Oas3Schema,
|
|
14
|
+
Oas3_1Schema,
|
|
13
15
|
Oas3Tag,
|
|
16
|
+
Oas3_1Webhooks,
|
|
17
|
+
Referenced
|
|
14
18
|
} from './typings/openapi';
|
|
15
19
|
export { Oas2Definition } from './typings/swagger';
|
|
16
20
|
export { StatsAccumulator, StatsName } from './typings/common';
|
|
@@ -30,7 +34,7 @@ export {
|
|
|
30
34
|
makeDocumentFromString,
|
|
31
35
|
} from './resolve';
|
|
32
36
|
export { parseYaml, stringifyYaml } from './js-yaml';
|
|
33
|
-
export { unescapePointer } from './ref-utils';
|
|
37
|
+
export { unescapePointer, isRef } from './ref-utils';
|
|
34
38
|
export { detectOpenAPI, OasMajorVersion, openAPIMajor, OasVersion } from './oas-types';
|
|
35
39
|
export { normalizeVisitors } from './visitors';
|
|
36
40
|
|
package/src/js-yaml/index.ts
CHANGED
|
@@ -15,5 +15,4 @@ const DEFAULT_SCHEMA_WITHOUT_TIMESTAMP = JSON_SCHEMA.extend({
|
|
|
15
15
|
export const parseYaml = (str: string, opts?: LoadOptions): unknown =>
|
|
16
16
|
load(str, {schema: DEFAULT_SCHEMA_WITHOUT_TIMESTAMP, ...opts});
|
|
17
17
|
|
|
18
|
-
export const stringifyYaml = (obj: any, opts?: DumpOptions): string =>
|
|
19
|
-
dump(obj, {schema: DEFAULT_SCHEMA_WITHOUT_TIMESTAMP, ...opts});
|
|
18
|
+
export const stringifyYaml = (obj: any, opts?: DumpOptions): string => dump(obj, opts);
|
|
@@ -23,7 +23,10 @@ export class RegistryApi {
|
|
|
23
23
|
private async request(path = '', options: RequestInit = {}, region?: Region) {
|
|
24
24
|
const headers = Object.assign({}, options.headers || {}, { 'x-redocly-cli-version': version });
|
|
25
25
|
if (!headers.hasOwnProperty('authorization')) { throw new Error('Unauthorized'); }
|
|
26
|
-
const response = await fetch(
|
|
26
|
+
const response = await fetch(
|
|
27
|
+
`${this.getBaseUrl(region)}${path}`,
|
|
28
|
+
Object.assign({}, options, { headers }),
|
|
29
|
+
);
|
|
27
30
|
if (response.status === 401) { throw new Error('Unauthorized'); }
|
|
28
31
|
if (response.status === 404) {
|
|
29
32
|
const body: RegistryApiTypes.NotFoundProblemResponse = await response.json();
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import path = require('path');
|
|
2
2
|
import { outdent } from 'outdent';
|
|
3
|
-
|
|
4
3
|
import { lintDocument } from '../../lint';
|
|
5
4
|
import { BaseResolver } from '../../resolve';
|
|
6
|
-
|
|
7
|
-
import { parseYamlToDocument, replaceSourceWithRef } from '../../../__tests__/utils';
|
|
8
|
-
import { makeConfig } from './config';
|
|
5
|
+
import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../../__tests__/utils';
|
|
9
6
|
|
|
10
7
|
describe('oas3 boolean-parameter-prefixes', () => {
|
|
11
8
|
it('should report on unresolved $ref', async () => {
|
|
@@ -1,10 +1,8 @@
|
|
|
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
5
|
|
|
6
|
-
import { makeConfig } from '../../__tests__/config';
|
|
7
|
-
|
|
8
6
|
describe('Oas3 info-description', () => {
|
|
9
7
|
it('should report on info with no description', async () => {
|
|
10
8
|
const document = parseYamlToDocument(
|
|
@@ -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 info-license', () => {
|
|
@@ -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 license-url', () => {
|
|
@@ -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-ambiguous-paths', () => {
|
|
@@ -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 typed enum', () => {
|
|
@@ -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-identical-paths', () => {
|
|
@@ -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-path-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 operation-2xx-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-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:
|
|
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)) {
|
package/src/rules/common/spec.ts
CHANGED
|
@@ -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 () => {
|
package/src/rules/oas2/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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
|
-
};
|
|
@@ -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', () => {
|
package/src/rules/oas3/index.ts
CHANGED
|
@@ -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
|
-
|
|
18
|
-
mediaType.schema
|
|
19
|
-
location
|
|
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
|
},
|
package/src/types/index.ts
CHANGED
|
@@ -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;
|