@redocly/openapi-core 1.21.1 → 1.22.1
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/CHANGELOG.md +17 -0
- package/lib/config/all.js +14 -1
- package/lib/config/config-resolvers.js +5 -6
- package/lib/config/minimal.js +11 -1
- package/lib/config/recommended-strict.js +11 -1
- package/lib/config/recommended.js +11 -1
- package/lib/oas-types.js +2 -1
- package/lib/rules/arazzo/index.js +22 -2
- package/lib/rules/arazzo/parameters-unique.d.ts +2 -0
- package/lib/rules/arazzo/parameters-unique.js +32 -0
- package/lib/rules/arazzo/requestBody-replacements-unique.d.ts +2 -0
- package/lib/rules/arazzo/requestBody-replacements-unique.js +28 -0
- package/lib/rules/arazzo/source-description-type.d.ts +2 -0
- package/lib/rules/arazzo/source-description-type.js +20 -0
- package/lib/rules/arazzo/sourceDescriptions-name-unique.d.ts +2 -0
- package/lib/rules/arazzo/sourceDescriptions-name-unique.js +24 -0
- package/lib/rules/arazzo/step-onFailure-unique.d.ts +2 -0
- package/lib/rules/arazzo/step-onFailure-unique.js +32 -0
- package/lib/rules/arazzo/step-onSuccess-unique.d.ts +2 -0
- package/lib/rules/arazzo/step-onSuccess-unique.js +32 -0
- package/lib/rules/arazzo/stepId-unique.d.ts +2 -0
- package/lib/rules/arazzo/stepId-unique.js +26 -0
- package/lib/rules/arazzo/workflow-dependsOn.d.ts +2 -0
- package/lib/rules/arazzo/workflow-dependsOn.js +56 -0
- package/lib/rules/arazzo/workflowId-unique.d.ts +2 -0
- package/lib/rules/arazzo/workflowId-unique.js +22 -0
- package/lib/rules/spot/parameters-not-in-body.d.ts +2 -0
- package/lib/rules/spot/{parameters-no-body-inside-in.js → parameters-not-in-body.js} +3 -3
- package/lib/rules/spot/version-enum.d.ts +2 -0
- package/lib/rules/spot/version-enum.js +21 -0
- package/lib/types/arazzo.js +8 -10
- package/lib/types/redocly-yaml.d.ts +1 -1
- package/lib/types/redocly-yaml.js +14 -1
- package/lib/typings/arazzo.d.ts +2 -0
- package/lib/typings/arazzo.js +3 -0
- package/lib/utils.d.ts +1 -0
- package/lib/utils.js +8 -0
- package/package.json +2 -2
- package/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +22 -2
- package/src/config/all.ts +14 -1
- package/src/config/config-resolvers.ts +7 -10
- package/src/config/minimal.ts +11 -1
- package/src/config/recommended-strict.ts +11 -1
- package/src/config/recommended.ts +11 -1
- package/src/oas-types.ts +2 -1
- package/src/rules/arazzo/__tests__/{parameters-no-body-inside-in.test.ts → parameters-not-in-body.test.ts} +3 -5
- package/src/rules/arazzo/__tests__/parameters-unique.test.ts +114 -0
- package/src/rules/arazzo/__tests__/requestBody-replacements-unique.test.ts +109 -0
- package/src/rules/arazzo/__tests__/source-description-type.test.ts +80 -0
- package/src/rules/arazzo/__tests__/sourceDescription-name-unique.test.ts +79 -0
- package/src/rules/arazzo/__tests__/step-onFailure-unique.test.ts +111 -0
- package/src/rules/arazzo/__tests__/step-onSuccess-unique.test.ts +111 -0
- package/src/rules/arazzo/__tests__/stepId-unique.test.ts +95 -0
- package/src/rules/arazzo/__tests__/version-enum.test.ts +76 -0
- package/src/rules/arazzo/__tests__/workflow-dependsOn.test.ts +212 -0
- package/src/rules/arazzo/__tests__/workflowId-unique.test.ts +90 -0
- package/src/rules/arazzo/index.ts +22 -2
- package/src/rules/arazzo/parameters-unique.ts +33 -0
- package/src/rules/arazzo/requestBody-replacements-unique.ts +28 -0
- package/src/rules/arazzo/source-description-type.ts +20 -0
- package/src/rules/arazzo/sourceDescriptions-name-unique.ts +23 -0
- package/src/rules/arazzo/step-onFailure-unique.ts +33 -0
- package/src/rules/arazzo/step-onSuccess-unique.ts +33 -0
- package/src/rules/arazzo/stepId-unique.ts +24 -0
- package/src/rules/arazzo/workflow-dependsOn.ts +56 -0
- package/src/rules/arazzo/workflowId-unique.ts +21 -0
- package/src/rules/spot/{parameters-no-body-inside-in.ts → parameters-not-in-body.ts} +1 -1
- package/src/rules/spot/version-enum.ts +24 -0
- package/src/types/arazzo.ts +8 -10
- package/src/types/redocly-yaml.ts +14 -1
- package/src/typings/arazzo.ts +4 -0
- package/src/utils.ts +8 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/lib/rules/spot/parameters-no-body-inside-in.d.ts +0 -2
|
@@ -93,7 +93,20 @@ const builtInAsync3Rules = [
|
|
|
93
93
|
'channels-kebab-case',
|
|
94
94
|
'no-channel-trailing-slash',
|
|
95
95
|
];
|
|
96
|
-
const builtInArazzoRules = [
|
|
96
|
+
const builtInArazzoRules = [
|
|
97
|
+
'spec',
|
|
98
|
+
'parameters-not-in-body',
|
|
99
|
+
'sourceDescription-type',
|
|
100
|
+
'version-enum',
|
|
101
|
+
'workflowId-unique',
|
|
102
|
+
'stepId-unique',
|
|
103
|
+
'sourceDescription-name-unique',
|
|
104
|
+
'workflow-dependsOn',
|
|
105
|
+
'parameters-unique',
|
|
106
|
+
'step-onSuccess-unique',
|
|
107
|
+
'step-onFailure-unique',
|
|
108
|
+
'requestBody-replacements-unique',
|
|
109
|
+
];
|
|
97
110
|
const builtInRules = [
|
|
98
111
|
...builtInCommonOASRules,
|
|
99
112
|
...builtInOAS2Rules,
|
package/lib/typings/arazzo.d.ts
CHANGED
package/lib/typings/arazzo.js
CHANGED
package/lib/utils.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export declare function pushStack<T, P extends Stack<T> = Stack<T>>(head: P, val
|
|
|
12
12
|
prev: P;
|
|
13
13
|
value: T;
|
|
14
14
|
};
|
|
15
|
+
export declare function pluralize(sentence: string, count?: number, inclusive?: boolean): string;
|
|
15
16
|
export declare function popStack<T, P extends Stack<T>>(head: P): StackFrame<T> | null;
|
|
16
17
|
export type BundleOutputFormat = 'json' | 'yml' | 'yaml';
|
|
17
18
|
export declare function loadYaml<T>(filename: string): Promise<T>;
|
package/lib/utils.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.stringifyYaml = exports.parseYaml = void 0;
|
|
4
4
|
exports.pushStack = pushStack;
|
|
5
|
+
exports.pluralize = pluralize;
|
|
5
6
|
exports.popStack = popStack;
|
|
6
7
|
exports.loadYaml = loadYaml;
|
|
7
8
|
exports.isDefined = isDefined;
|
|
@@ -43,12 +44,19 @@ const js_yaml_1 = require("./js-yaml");
|
|
|
43
44
|
const env_1 = require("./env");
|
|
44
45
|
const logger_1 = require("./logger");
|
|
45
46
|
const https_proxy_agent_1 = require("https-proxy-agent");
|
|
47
|
+
const pluralizeOne = require("pluralize");
|
|
46
48
|
var js_yaml_2 = require("./js-yaml");
|
|
47
49
|
Object.defineProperty(exports, "parseYaml", { enumerable: true, get: function () { return js_yaml_2.parseYaml; } });
|
|
48
50
|
Object.defineProperty(exports, "stringifyYaml", { enumerable: true, get: function () { return js_yaml_2.stringifyYaml; } });
|
|
49
51
|
function pushStack(head, value) {
|
|
50
52
|
return { prev: head, value };
|
|
51
53
|
}
|
|
54
|
+
function pluralize(sentence, count, inclusive) {
|
|
55
|
+
return sentence
|
|
56
|
+
.split(' ')
|
|
57
|
+
.map((word) => pluralizeOne(word, count, inclusive))
|
|
58
|
+
.join(' ');
|
|
59
|
+
}
|
|
52
60
|
function popStack(head) {
|
|
53
61
|
return head?.prev ?? null;
|
|
54
62
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@redocly/openapi-core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.22.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"engines": {
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@redocly/ajv": "^8.11.0",
|
|
39
|
-
"@redocly/config": "^0.10.
|
|
39
|
+
"@redocly/config": "^0.10.1",
|
|
40
40
|
"colorette": "^1.2.0",
|
|
41
41
|
"https-proxy-agent": "^7.0.4",
|
|
42
42
|
"js-levenshtein": "^1.1.6",
|
|
@@ -5,8 +5,18 @@ exports[`resolveConfig should ignore minimal from the root and read local file 1
|
|
|
5
5
|
"arazzoDecorators": {},
|
|
6
6
|
"arazzoPreprocessors": {},
|
|
7
7
|
"arazzoRules": {
|
|
8
|
-
"parameters-
|
|
8
|
+
"parameters-not-in-body": "warn",
|
|
9
|
+
"parameters-unique": "error",
|
|
10
|
+
"requestBody-replacements-unique": "warn",
|
|
11
|
+
"sourceDescription-name-unique": "error",
|
|
12
|
+
"sourceDescription-type": "error",
|
|
9
13
|
"spec": "error",
|
|
14
|
+
"step-onFailure-unique": "warn",
|
|
15
|
+
"step-onSuccess-unique": "warn",
|
|
16
|
+
"stepId-unique": "error",
|
|
17
|
+
"version-enum": "warn",
|
|
18
|
+
"workflow-dependsOn": "error",
|
|
19
|
+
"workflowId-unique": "error",
|
|
10
20
|
},
|
|
11
21
|
"async2Decorators": {},
|
|
12
22
|
"async2Preprocessors": {},
|
|
@@ -137,8 +147,18 @@ exports[`resolveStyleguideConfig should resolve extends with local file config w
|
|
|
137
147
|
"arazzoDecorators": {},
|
|
138
148
|
"arazzoPreprocessors": {},
|
|
139
149
|
"arazzoRules": {
|
|
140
|
-
"parameters-
|
|
150
|
+
"parameters-not-in-body": "warn",
|
|
151
|
+
"parameters-unique": "error",
|
|
152
|
+
"requestBody-replacements-unique": "warn",
|
|
153
|
+
"sourceDescription-name-unique": "error",
|
|
154
|
+
"sourceDescription-type": "error",
|
|
141
155
|
"spec": "error",
|
|
156
|
+
"step-onFailure-unique": "warn",
|
|
157
|
+
"step-onSuccess-unique": "warn",
|
|
158
|
+
"stepId-unique": "error",
|
|
159
|
+
"version-enum": "warn",
|
|
160
|
+
"workflow-dependsOn": "error",
|
|
161
|
+
"workflowId-unique": "error",
|
|
142
162
|
},
|
|
143
163
|
"async2Decorators": {},
|
|
144
164
|
"async2Preprocessors": {},
|
package/src/config/all.ts
CHANGED
|
@@ -126,7 +126,20 @@ const all: PluginStyleguideConfig<'built-in'> = {
|
|
|
126
126
|
'channels-kebab-case': 'error',
|
|
127
127
|
'no-channel-trailing-slash': 'error',
|
|
128
128
|
},
|
|
129
|
-
arazzoRules: {
|
|
129
|
+
arazzoRules: {
|
|
130
|
+
spec: 'error',
|
|
131
|
+
'parameters-not-in-body': 'error',
|
|
132
|
+
'sourceDescription-type': 'error',
|
|
133
|
+
'version-enum': 'error',
|
|
134
|
+
'workflowId-unique': 'error',
|
|
135
|
+
'stepId-unique': 'error',
|
|
136
|
+
'sourceDescription-name-unique': 'error',
|
|
137
|
+
'workflow-dependsOn': 'error',
|
|
138
|
+
'parameters-unique': 'error',
|
|
139
|
+
'step-onSuccess-unique': 'error',
|
|
140
|
+
'step-onFailure-unique': 'error',
|
|
141
|
+
'requestBody-replacements-unique': 'error',
|
|
142
|
+
},
|
|
130
143
|
};
|
|
131
144
|
|
|
132
145
|
export default all;
|
|
@@ -117,7 +117,7 @@ function getDefaultPluginPath(configPath: string): string | undefined {
|
|
|
117
117
|
return pluginPath;
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
|
-
return
|
|
120
|
+
return;
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
export async function resolvePlugins(
|
|
@@ -128,12 +128,6 @@ export async function resolvePlugins(
|
|
|
128
128
|
|
|
129
129
|
// TODO: implement or reuse Resolver approach so it will work in node and browser envs
|
|
130
130
|
const requireFunc = async (plugin: string | Plugin): Promise<ImportedPlugin | undefined> => {
|
|
131
|
-
if (isBrowser && isString(plugin)) {
|
|
132
|
-
logger.error(`Cannot load ${plugin}. Plugins aren't supported in browser yet.`);
|
|
133
|
-
|
|
134
|
-
return undefined;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
131
|
if (isString(plugin)) {
|
|
138
132
|
try {
|
|
139
133
|
const maybeAbsolutePluginPath = path.resolve(path.dirname(configPath), plugin);
|
|
@@ -372,9 +366,12 @@ async function resolveAndMergeNestedStyleguideConfig(
|
|
|
372
366
|
if (parentConfigPaths.includes(configPath)) {
|
|
373
367
|
throw new Error(`Circular dependency in config file: "${configPath}"`);
|
|
374
368
|
}
|
|
375
|
-
const plugins =
|
|
376
|
-
|
|
377
|
-
|
|
369
|
+
const plugins = isBrowser
|
|
370
|
+
? // In browser, we don't support plugins from config file yet
|
|
371
|
+
[defaultPlugin]
|
|
372
|
+
: getUniquePlugins(
|
|
373
|
+
await resolvePlugins([...(styleguideConfig?.plugins || []), defaultPlugin], configPath)
|
|
374
|
+
);
|
|
378
375
|
const pluginPaths = styleguideConfig?.plugins
|
|
379
376
|
?.filter(isString)
|
|
380
377
|
.map((p) => path.resolve(path.dirname(configPath), p));
|
package/src/config/minimal.ts
CHANGED
|
@@ -110,7 +110,17 @@ const minimal: PluginStyleguideConfig<'built-in'> = {
|
|
|
110
110
|
},
|
|
111
111
|
arazzoRules: {
|
|
112
112
|
spec: 'error',
|
|
113
|
-
'parameters-
|
|
113
|
+
'parameters-not-in-body': 'off',
|
|
114
|
+
'sourceDescription-type': 'off',
|
|
115
|
+
'version-enum': 'warn',
|
|
116
|
+
'workflowId-unique': 'error',
|
|
117
|
+
'stepId-unique': 'error',
|
|
118
|
+
'sourceDescription-name-unique': 'off',
|
|
119
|
+
'workflow-dependsOn': 'off',
|
|
120
|
+
'parameters-unique': 'off',
|
|
121
|
+
'step-onSuccess-unique': 'off',
|
|
122
|
+
'step-onFailure-unique': 'off',
|
|
123
|
+
'requestBody-replacements-unique': 'off',
|
|
114
124
|
},
|
|
115
125
|
};
|
|
116
126
|
|
|
@@ -110,7 +110,17 @@ const recommendedStrict: PluginStyleguideConfig<'built-in'> = {
|
|
|
110
110
|
},
|
|
111
111
|
arazzoRules: {
|
|
112
112
|
spec: 'error',
|
|
113
|
-
'parameters-
|
|
113
|
+
'parameters-not-in-body': 'error',
|
|
114
|
+
'sourceDescription-type': 'error',
|
|
115
|
+
'version-enum': 'error',
|
|
116
|
+
'workflowId-unique': 'error',
|
|
117
|
+
'stepId-unique': 'error',
|
|
118
|
+
'sourceDescription-name-unique': 'error',
|
|
119
|
+
'workflow-dependsOn': 'error',
|
|
120
|
+
'parameters-unique': 'error',
|
|
121
|
+
'step-onSuccess-unique': 'error',
|
|
122
|
+
'step-onFailure-unique': 'error',
|
|
123
|
+
'requestBody-replacements-unique': 'error',
|
|
114
124
|
},
|
|
115
125
|
};
|
|
116
126
|
|
|
@@ -110,7 +110,17 @@ const recommended: PluginStyleguideConfig<'built-in'> = {
|
|
|
110
110
|
},
|
|
111
111
|
arazzoRules: {
|
|
112
112
|
spec: 'error',
|
|
113
|
-
'parameters-
|
|
113
|
+
'parameters-not-in-body': 'warn',
|
|
114
|
+
'sourceDescription-type': 'error',
|
|
115
|
+
'version-enum': 'warn',
|
|
116
|
+
'workflowId-unique': 'error',
|
|
117
|
+
'stepId-unique': 'error',
|
|
118
|
+
'sourceDescription-name-unique': 'error',
|
|
119
|
+
'workflow-dependsOn': 'error',
|
|
120
|
+
'parameters-unique': 'error',
|
|
121
|
+
'step-onSuccess-unique': 'warn',
|
|
122
|
+
'step-onFailure-unique': 'warn',
|
|
123
|
+
'requestBody-replacements-unique': 'warn',
|
|
114
124
|
},
|
|
115
125
|
};
|
|
116
126
|
|
package/src/oas-types.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { AsyncApi2Types } from './types/asyncapi2';
|
|
|
5
5
|
import { AsyncApi3Types } from './types/asyncapi3';
|
|
6
6
|
import { ArazzoTypes } from './types/arazzo';
|
|
7
7
|
import { isPlainObject } from './utils';
|
|
8
|
+
import { VERSION_PATTERN } from './typings/arazzo';
|
|
8
9
|
|
|
9
10
|
import type {
|
|
10
11
|
BuiltInAsync2RuleId,
|
|
@@ -132,7 +133,7 @@ export function detectSpec(root: unknown): SpecVersion {
|
|
|
132
133
|
throw new Error(`Unsupported AsyncAPI version: ${root.asyncapi}`);
|
|
133
134
|
}
|
|
134
135
|
|
|
135
|
-
if (typeof root.arazzo === 'string' && root.arazzo
|
|
136
|
+
if (typeof root.arazzo === 'string' && VERSION_PATTERN.test(root.arazzo)) {
|
|
136
137
|
return SpecVersion.Arazzo;
|
|
137
138
|
}
|
|
138
139
|
|
|
@@ -2,10 +2,8 @@ import { outdent } from 'outdent';
|
|
|
2
2
|
import { lintDocument } from '../../../lint';
|
|
3
3
|
import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../../../__tests__/utils';
|
|
4
4
|
import { BaseResolver } from '../../../resolve';
|
|
5
|
-
import { StyleguideConfig } from '../../../config';
|
|
6
|
-
import { ArazzoRule } from '../../../visitors';
|
|
7
5
|
|
|
8
|
-
describe('
|
|
6
|
+
describe('Spot parameters-not-in-body', () => {
|
|
9
7
|
const document = parseYamlToDocument(
|
|
10
8
|
outdent`
|
|
11
9
|
arazzo: '1.0.0'
|
|
@@ -51,7 +49,7 @@ describe('Arazzo parameters-no-body-inside-in', () => {
|
|
|
51
49
|
document,
|
|
52
50
|
config: await makeConfig({
|
|
53
51
|
rules: {},
|
|
54
|
-
arazzoRules: { 'parameters-
|
|
52
|
+
arazzoRules: { 'parameters-not-in-body': 'error' },
|
|
55
53
|
}),
|
|
56
54
|
});
|
|
57
55
|
|
|
@@ -66,7 +64,7 @@ describe('Arazzo parameters-no-body-inside-in', () => {
|
|
|
66
64
|
},
|
|
67
65
|
],
|
|
68
66
|
"message": "The \`body\` value of the \`in\` property is not supported by Spot.",
|
|
69
|
-
"ruleId": "parameters-
|
|
67
|
+
"ruleId": "parameters-not-in-body",
|
|
70
68
|
"severity": "error",
|
|
71
69
|
"suggest": [],
|
|
72
70
|
},
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { outdent } from 'outdent';
|
|
2
|
+
import { lintDocument } from '../../../lint';
|
|
3
|
+
import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../../../__tests__/utils';
|
|
4
|
+
import { BaseResolver } from '../../../resolve';
|
|
5
|
+
|
|
6
|
+
describe('Arazzo parameters-unique', () => {
|
|
7
|
+
const document = parseYamlToDocument(
|
|
8
|
+
outdent`
|
|
9
|
+
arazzo: '1.0.0'
|
|
10
|
+
info:
|
|
11
|
+
title: Cool API
|
|
12
|
+
version: 1.0.0
|
|
13
|
+
description: A cool API
|
|
14
|
+
sourceDescriptions:
|
|
15
|
+
- name: museum-api
|
|
16
|
+
type: openapi
|
|
17
|
+
url: openapi.yaml
|
|
18
|
+
workflows:
|
|
19
|
+
- workflowId: get-museum-hours
|
|
20
|
+
description: This workflow demonstrates how to get the museum opening hours and buy tickets.
|
|
21
|
+
parameters:
|
|
22
|
+
- in: header
|
|
23
|
+
name: Authorization
|
|
24
|
+
value: Basic Og==
|
|
25
|
+
- in: header
|
|
26
|
+
name: Authorization
|
|
27
|
+
value: Basic Og==
|
|
28
|
+
steps:
|
|
29
|
+
- stepId: get-museum-hours
|
|
30
|
+
description: >-
|
|
31
|
+
Get museum hours by resolving request details with getMuseumHours operationId from openapi.yaml description.
|
|
32
|
+
operationId: museum-api.getMuseumHours
|
|
33
|
+
parameters:
|
|
34
|
+
- in: header
|
|
35
|
+
name: Secret
|
|
36
|
+
value: Basic Og==
|
|
37
|
+
- in: header
|
|
38
|
+
name: Secret
|
|
39
|
+
value: Basic Og==
|
|
40
|
+
- reference: $components.parameters.notify
|
|
41
|
+
value: 12
|
|
42
|
+
- reference: $components.parameters.notify
|
|
43
|
+
value: 12
|
|
44
|
+
successCriteria:
|
|
45
|
+
- condition: $statusCode == 200
|
|
46
|
+
`,
|
|
47
|
+
'arazzo.yaml'
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
it('should not report on `parameters` duplication', async () => {
|
|
51
|
+
const results = await lintDocument({
|
|
52
|
+
externalRefResolver: new BaseResolver(),
|
|
53
|
+
document,
|
|
54
|
+
config: await makeConfig({ rules: {} }),
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`[]`);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('should report on `parameters` duplication', async () => {
|
|
61
|
+
const results = await lintDocument({
|
|
62
|
+
externalRefResolver: new BaseResolver(),
|
|
63
|
+
document,
|
|
64
|
+
config: await makeConfig({
|
|
65
|
+
rules: {},
|
|
66
|
+
arazzoRules: { 'parameters-unique': 'error' },
|
|
67
|
+
}),
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
|
|
71
|
+
[
|
|
72
|
+
{
|
|
73
|
+
"location": [
|
|
74
|
+
{
|
|
75
|
+
"pointer": "#/workflows/0/parameters/1",
|
|
76
|
+
"reportOnKey": false,
|
|
77
|
+
"source": "arazzo.yaml",
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
"message": "The parameter \`name\` must be unique amongst listed parameters.",
|
|
81
|
+
"ruleId": "parameters-unique",
|
|
82
|
+
"severity": "error",
|
|
83
|
+
"suggest": [],
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
"location": [
|
|
87
|
+
{
|
|
88
|
+
"pointer": "#/workflows/0/steps/0/parameters/1",
|
|
89
|
+
"reportOnKey": false,
|
|
90
|
+
"source": "arazzo.yaml",
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
"message": "The parameter \`name\` must be unique amongst listed parameters.",
|
|
94
|
+
"ruleId": "parameters-unique",
|
|
95
|
+
"severity": "error",
|
|
96
|
+
"suggest": [],
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"location": [
|
|
100
|
+
{
|
|
101
|
+
"pointer": "#/workflows/0/steps/0/parameters/3",
|
|
102
|
+
"reportOnKey": false,
|
|
103
|
+
"source": "arazzo.yaml",
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
"message": "The parameter \`reference\` must be unique amongst listed parameters.",
|
|
107
|
+
"ruleId": "parameters-unique",
|
|
108
|
+
"severity": "error",
|
|
109
|
+
"suggest": [],
|
|
110
|
+
},
|
|
111
|
+
]
|
|
112
|
+
`);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { outdent } from 'outdent';
|
|
2
|
+
import { lintDocument } from '../../../lint';
|
|
3
|
+
import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../../../__tests__/utils';
|
|
4
|
+
import { BaseResolver } from '../../../resolve';
|
|
5
|
+
|
|
6
|
+
describe('Arazzo requestBody-replacements-unique', () => {
|
|
7
|
+
const document = parseYamlToDocument(
|
|
8
|
+
outdent`
|
|
9
|
+
arazzo: '1.0.0'
|
|
10
|
+
info:
|
|
11
|
+
title: Cool API
|
|
12
|
+
version: 1.0.0
|
|
13
|
+
description: A cool API
|
|
14
|
+
sourceDescriptions:
|
|
15
|
+
- name: museum-api
|
|
16
|
+
type: openapi
|
|
17
|
+
url: openapi.yaml
|
|
18
|
+
workflows:
|
|
19
|
+
- workflowId: get-museum-hours
|
|
20
|
+
description: This workflow demonstrates how to get the museum opening hours and buy tickets.
|
|
21
|
+
parameters:
|
|
22
|
+
- in: header
|
|
23
|
+
name: Authorization
|
|
24
|
+
value: Basic Og==
|
|
25
|
+
steps:
|
|
26
|
+
- stepId: create-event
|
|
27
|
+
description: >-
|
|
28
|
+
Create a new special event.
|
|
29
|
+
operationPath: $sourceDescriptions.museum-api#/paths/~1special-events/post
|
|
30
|
+
requestBody:
|
|
31
|
+
replacements:
|
|
32
|
+
- target: $randomString
|
|
33
|
+
value: $randomString
|
|
34
|
+
- target: $randomString
|
|
35
|
+
value: $randomString
|
|
36
|
+
payload:
|
|
37
|
+
name: 'Mermaid Treasure Identification and Analysis'
|
|
38
|
+
location: 'Under the seaaa 🦀 🎶 🌊.'
|
|
39
|
+
eventDescription: 'Join us as we review and classify a rare collection of 20 thingamabobs, gadgets, gizmos, whoosits, and whatsits, kindly donated by Ariel.'
|
|
40
|
+
dates:
|
|
41
|
+
- '2023-09-05'
|
|
42
|
+
- '2023-09-08'
|
|
43
|
+
price: 0
|
|
44
|
+
successCriteria:
|
|
45
|
+
- condition: $statusCode == 201
|
|
46
|
+
- context: $response.body
|
|
47
|
+
condition: $.name == 'Mermaid Treasure Identification and Analysis'
|
|
48
|
+
type: jsonpath
|
|
49
|
+
outputs:
|
|
50
|
+
createdEventId: $response.body.eventId
|
|
51
|
+
name: $response.body.name
|
|
52
|
+
- workflowId: get-museum-hours-2
|
|
53
|
+
description: This workflow demonstrates how to get the museum opening hours and buy tickets.
|
|
54
|
+
parameters:
|
|
55
|
+
- in: header
|
|
56
|
+
name: Authorization
|
|
57
|
+
value: Basic Og==
|
|
58
|
+
steps:
|
|
59
|
+
- stepId: get-museum-hours
|
|
60
|
+
description: >-
|
|
61
|
+
Get museum hours by resolving request details with getMuseumHours operationId from openapi.yaml description.
|
|
62
|
+
operationId: museum-api.getMuseumHours
|
|
63
|
+
successCriteria:
|
|
64
|
+
- condition: $statusCode == 200
|
|
65
|
+
`,
|
|
66
|
+
'arazzo.yaml'
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
it('should report when the `replacement` is not unique amongst all `replacements` in the RequestBody', async () => {
|
|
70
|
+
const results = await lintDocument({
|
|
71
|
+
externalRefResolver: new BaseResolver(),
|
|
72
|
+
document,
|
|
73
|
+
config: await makeConfig({
|
|
74
|
+
rules: {},
|
|
75
|
+
arazzoRules: { 'requestBody-replacements-unique': 'error' },
|
|
76
|
+
}),
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
|
|
80
|
+
[
|
|
81
|
+
{
|
|
82
|
+
"location": [
|
|
83
|
+
{
|
|
84
|
+
"pointer": "#/workflows/0/steps/0/requestBody/replacements/1/target",
|
|
85
|
+
"reportOnKey": false,
|
|
86
|
+
"source": "arazzo.yaml",
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
"message": "Every \`replacement\` in \`requestBody\` must be unique.",
|
|
90
|
+
"ruleId": "requestBody-replacements-unique",
|
|
91
|
+
"severity": "error",
|
|
92
|
+
"suggest": [],
|
|
93
|
+
},
|
|
94
|
+
]
|
|
95
|
+
`);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('should not report when the `replacement` is not unique amongst all `replacements` in the RequestBody', async () => {
|
|
99
|
+
const results = await lintDocument({
|
|
100
|
+
externalRefResolver: new BaseResolver(),
|
|
101
|
+
document,
|
|
102
|
+
config: await makeConfig({
|
|
103
|
+
rules: {},
|
|
104
|
+
}),
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`[]`);
|
|
108
|
+
});
|
|
109
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { outdent } from 'outdent';
|
|
2
|
+
import { lintDocument } from '../../../lint';
|
|
3
|
+
import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../../../__tests__/utils';
|
|
4
|
+
import { BaseResolver } from '../../../resolve';
|
|
5
|
+
|
|
6
|
+
describe('Arazzo sourceDescription-type', () => {
|
|
7
|
+
const document = parseYamlToDocument(
|
|
8
|
+
outdent`
|
|
9
|
+
arazzo: '1.0.0'
|
|
10
|
+
info:
|
|
11
|
+
title: Cool API
|
|
12
|
+
version: 1.0.0
|
|
13
|
+
description: A cool API
|
|
14
|
+
sourceDescriptions:
|
|
15
|
+
- name: museum-api
|
|
16
|
+
type: openapi
|
|
17
|
+
url: openapi.yaml
|
|
18
|
+
- name: api
|
|
19
|
+
type: none
|
|
20
|
+
x-serverUrl: 'http://localhost/api'
|
|
21
|
+
workflows:
|
|
22
|
+
- workflowId: get-museum-hours
|
|
23
|
+
description: This workflow demonstrates how to get the museum opening hours and buy tickets.
|
|
24
|
+
parameters:
|
|
25
|
+
- in: header
|
|
26
|
+
name: Authorization
|
|
27
|
+
value: Basic Og==
|
|
28
|
+
steps:
|
|
29
|
+
- stepId: get-museum-hours
|
|
30
|
+
description: >-
|
|
31
|
+
Get museum hours by resolving request details with getMuseumHours operationId from openapi.yaml description.
|
|
32
|
+
operationId: museum-api.getMuseumHours
|
|
33
|
+
successCriteria:
|
|
34
|
+
- condition: $statusCode == 200
|
|
35
|
+
`,
|
|
36
|
+
'arazzo.yaml'
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
it('should report on sourceDescription with type `none`', async () => {
|
|
40
|
+
const results = await lintDocument({
|
|
41
|
+
externalRefResolver: new BaseResolver(),
|
|
42
|
+
document,
|
|
43
|
+
config: await makeConfig({
|
|
44
|
+
rules: {},
|
|
45
|
+
arazzoRules: { 'sourceDescription-type': 'error' },
|
|
46
|
+
}),
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
|
|
50
|
+
[
|
|
51
|
+
{
|
|
52
|
+
"location": [
|
|
53
|
+
{
|
|
54
|
+
"pointer": "#/sourceDescriptions/1",
|
|
55
|
+
"reportOnKey": false,
|
|
56
|
+
"source": "arazzo.yaml",
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
"message": "The \`type\` property of the \`sourceDescription\` object must be either \`openapi\` or \`arazzo\`.",
|
|
60
|
+
"ruleId": "sourceDescription-type",
|
|
61
|
+
"severity": "error",
|
|
62
|
+
"suggest": [],
|
|
63
|
+
},
|
|
64
|
+
]
|
|
65
|
+
`);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('should not report on sourceDescription with type `none`', async () => {
|
|
69
|
+
const results = await lintDocument({
|
|
70
|
+
externalRefResolver: new BaseResolver(),
|
|
71
|
+
document,
|
|
72
|
+
config: await makeConfig({
|
|
73
|
+
rules: {},
|
|
74
|
+
arazzoRules: { 'sourceDescription-type': 'off' },
|
|
75
|
+
}),
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`[]`);
|
|
79
|
+
});
|
|
80
|
+
});
|