@redocly/openapi-core 1.0.0-beta.65 → 1.0.0-beta.69
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__/__snapshots__/bundle.test.ts.snap +126 -0
- package/__tests__/bundle.test.ts +53 -1
- package/__tests__/fixtures/refs/definitions.yaml +3 -0
- package/__tests__/fixtures/refs/external-request-body.yaml +13 -0
- package/__tests__/fixtures/refs/externalref.yaml +35 -0
- package/__tests__/fixtures/refs/hosted.yaml +35 -0
- package/__tests__/fixtures/refs/rename.yaml +1 -0
- package/__tests__/fixtures/refs/requestBody.yaml +9 -0
- package/__tests__/fixtures/refs/simple.yaml +1 -0
- package/__tests__/fixtures/refs/vendor.schema.yaml +20 -0
- package/lib/bundle.d.ts +4 -0
- package/lib/bundle.js +25 -7
- package/lib/config/all.js +9 -1
- package/lib/config/config.js +1 -1
- package/lib/config/minimal.js +1 -0
- package/lib/config/recommended.js +1 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -1
- package/lib/lint.js +2 -0
- package/lib/redocly/index.d.ts +3 -14
- package/lib/redocly/index.js +19 -186
- package/lib/redocly/registry-api-types.d.ts +28 -0
- package/lib/redocly/registry-api-types.js +2 -0
- package/lib/redocly/registry-api.d.ts +11 -0
- package/lib/redocly/registry-api.js +94 -0
- package/lib/ref-utils.js +1 -2
- package/lib/rules/common/info-license-url.js +1 -0
- package/lib/rules/common/no-http-verbs-in-paths.d.ts +2 -0
- package/lib/rules/common/no-http-verbs-in-paths.js +33 -0
- package/lib/rules/common/operation-4xx-response.d.ts +2 -0
- package/lib/rules/common/operation-4xx-response.js +17 -0
- package/lib/rules/common/path-excludes-patterns.d.ts +2 -0
- package/lib/rules/common/path-excludes-patterns.js +22 -0
- package/lib/rules/common/path-segment-plural.d.ts +2 -0
- package/lib/rules/common/path-segment-plural.js +32 -0
- package/lib/rules/common/registry-dependencies.js +4 -7
- package/lib/rules/oas2/index.d.ts +6 -0
- package/lib/rules/oas2/index.js +12 -0
- package/lib/rules/oas2/request-mime-type.d.ts +2 -0
- package/lib/rules/oas2/request-mime-type.js +17 -0
- package/lib/rules/oas2/response-mime-type.d.ts +2 -0
- package/lib/rules/oas2/response-mime-type.js +17 -0
- package/lib/rules/oas3/index.js +12 -0
- package/lib/rules/oas3/no-server-trailing-slash.js +1 -1
- package/lib/rules/oas3/request-mime-type.d.ts +2 -0
- package/lib/rules/oas3/request-mime-type.js +31 -0
- package/lib/rules/oas3/response-mime-type.d.ts +2 -0
- package/lib/rules/oas3/response-mime-type.js +31 -0
- package/lib/types/oas3_1.js +6 -0
- package/lib/utils.d.ts +10 -0
- package/lib/utils.js +65 -1
- package/lib/walk.d.ts +2 -0
- package/lib/walk.js +7 -0
- package/package.json +5 -3
- package/src/__tests__/utils.test.ts +19 -1
- package/src/bundle.ts +51 -9
- package/src/config/all.ts +9 -1
- package/src/config/config.ts +2 -2
- package/src/config/minimal.ts +1 -0
- package/src/config/recommended.ts +1 -0
- package/src/index.ts +1 -1
- package/src/lint.ts +2 -0
- package/src/redocly/index.ts +17 -194
- package/src/redocly/registry-api-types.ts +31 -0
- package/src/redocly/registry-api.ts +106 -0
- package/src/ref-utils.ts +1 -3
- package/src/rules/common/__tests__/info-license.test.ts +1 -1
- package/src/rules/common/__tests__/operation-4xx-response.test.ts +108 -0
- package/src/rules/common/info-license-url.ts +1 -0
- package/src/rules/common/no-http-verbs-in-paths.ts +36 -0
- package/src/rules/common/operation-4xx-response.ts +17 -0
- package/src/rules/common/path-excludes-patterns.ts +23 -0
- package/src/rules/common/path-segment-plural.ts +31 -0
- package/src/rules/common/registry-dependencies.ts +6 -8
- package/src/rules/oas2/index.ts +12 -0
- package/src/rules/oas2/request-mime-type.ts +17 -0
- package/src/rules/oas2/response-mime-type.ts +17 -0
- package/src/rules/oas3/__tests__/no-server-trailing-slash.test.ts +19 -0
- package/src/rules/oas3/index.ts +12 -0
- package/src/rules/oas3/no-server-trailing-slash.ts +1 -1
- package/src/rules/oas3/request-mime-type.ts +31 -0
- package/src/rules/oas3/response-mime-type.ts +31 -0
- package/src/rules/utils.ts +1 -1
- package/src/types/oas3_1.ts +7 -0
- package/src/utils.ts +75 -0
- package/src/walk.ts +10 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/lib/redocly/query.d.ts +0 -4
- package/lib/redocly/query.js +0 -44
- package/src/redocly/query.ts +0 -38
|
@@ -99,3 +99,129 @@ components:
|
|
|
99
99
|
name: shared-a
|
|
100
100
|
|
|
101
101
|
`;
|
|
102
|
+
|
|
103
|
+
exports[`bundle should not place referened schema inline when component in question is not of type "schemas" 1`] = `
|
|
104
|
+
openapi: 3.0.0
|
|
105
|
+
paths:
|
|
106
|
+
/pet:
|
|
107
|
+
post:
|
|
108
|
+
requestBody:
|
|
109
|
+
content:
|
|
110
|
+
application/json:
|
|
111
|
+
schema:
|
|
112
|
+
$ref: '#/components/schemas/requestBody'
|
|
113
|
+
components:
|
|
114
|
+
schemas:
|
|
115
|
+
requestBody:
|
|
116
|
+
content:
|
|
117
|
+
application/json:
|
|
118
|
+
schema:
|
|
119
|
+
type: object
|
|
120
|
+
properties:
|
|
121
|
+
a:
|
|
122
|
+
type: string
|
|
123
|
+
b:
|
|
124
|
+
type: number
|
|
125
|
+
|
|
126
|
+
`;
|
|
127
|
+
|
|
128
|
+
exports[`bundle should place referenced schema inline when referenced schema name resolves to original schema name 1`] = `
|
|
129
|
+
openapi: 3.1.0
|
|
130
|
+
info:
|
|
131
|
+
title: My API
|
|
132
|
+
description: It ain't so wonderful, but at least it's mine.
|
|
133
|
+
version: '1.0'
|
|
134
|
+
contact:
|
|
135
|
+
email: me@theintenet.com
|
|
136
|
+
name: me
|
|
137
|
+
paths:
|
|
138
|
+
/test:
|
|
139
|
+
get:
|
|
140
|
+
summary: test
|
|
141
|
+
responses:
|
|
142
|
+
'200':
|
|
143
|
+
description: test
|
|
144
|
+
content:
|
|
145
|
+
application/json:
|
|
146
|
+
schema:
|
|
147
|
+
$ref: '#/components/schemas/vendor'
|
|
148
|
+
components:
|
|
149
|
+
schemas:
|
|
150
|
+
vendor:
|
|
151
|
+
title: vendor
|
|
152
|
+
type: object
|
|
153
|
+
description: Vendors
|
|
154
|
+
properties:
|
|
155
|
+
key:
|
|
156
|
+
type: string
|
|
157
|
+
description: System-assigned key for the vendor.
|
|
158
|
+
readOnly: true
|
|
159
|
+
id:
|
|
160
|
+
type: string
|
|
161
|
+
description: >
|
|
162
|
+
Unique identifier of the vendor.
|
|
163
|
+
|
|
164
|
+
You must specify a unique vendor ID when creating a vendor unless
|
|
165
|
+
document sequencing is configured, in which case the ID is
|
|
166
|
+
auto-generated.
|
|
167
|
+
name:
|
|
168
|
+
type: string
|
|
169
|
+
description: Name of the vendor.
|
|
170
|
+
isOneTimeUse:
|
|
171
|
+
type: boolean
|
|
172
|
+
description: One-time use
|
|
173
|
+
default: false
|
|
174
|
+
myvendor:
|
|
175
|
+
$ref: '#/components/schemas/vendor'
|
|
176
|
+
simple:
|
|
177
|
+
type: string
|
|
178
|
+
A:
|
|
179
|
+
type: string
|
|
180
|
+
test:
|
|
181
|
+
$ref: '#/components/schemas/rename-2'
|
|
182
|
+
rename:
|
|
183
|
+
type: string
|
|
184
|
+
rename-2:
|
|
185
|
+
type: number
|
|
186
|
+
|
|
187
|
+
`;
|
|
188
|
+
|
|
189
|
+
exports[`bundle should pull hosted schema 1`] = `
|
|
190
|
+
openapi: 3.0.3
|
|
191
|
+
info:
|
|
192
|
+
title: bugtest
|
|
193
|
+
version: '1.0'
|
|
194
|
+
description: Demo
|
|
195
|
+
license:
|
|
196
|
+
name: DEMO
|
|
197
|
+
url: https://demo.com
|
|
198
|
+
servers:
|
|
199
|
+
- url: http://demo.com/api
|
|
200
|
+
paths:
|
|
201
|
+
/customer:
|
|
202
|
+
summary: Customer scope
|
|
203
|
+
get:
|
|
204
|
+
summary: Get demo no refs
|
|
205
|
+
operationId: GetCustomer
|
|
206
|
+
description: Returns Demo No Refs
|
|
207
|
+
responses:
|
|
208
|
+
'200':
|
|
209
|
+
description: Demo No Refs
|
|
210
|
+
content:
|
|
211
|
+
application/json:
|
|
212
|
+
schema:
|
|
213
|
+
$ref: '#/components/schemas/Customer'
|
|
214
|
+
components:
|
|
215
|
+
schemas:
|
|
216
|
+
Customer:
|
|
217
|
+
type: object
|
|
218
|
+
properties:
|
|
219
|
+
customerName:
|
|
220
|
+
type: string
|
|
221
|
+
accounts:
|
|
222
|
+
type: array
|
|
223
|
+
items:
|
|
224
|
+
$ref: '#/components/schemas/someexternal'
|
|
225
|
+
someexternal: External schema content
|
|
226
|
+
|
|
227
|
+
`;
|
package/__tests__/bundle.test.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { BaseResolver } from '../src/resolve';
|
|
|
10
10
|
describe('bundle', () => {
|
|
11
11
|
expect.addSnapshotSerializer(yamlSerializer);
|
|
12
12
|
|
|
13
|
-
const testDocument =
|
|
13
|
+
const testDocument = parseYamlToDocument(
|
|
14
14
|
outdent`
|
|
15
15
|
openapi: 3.0.0
|
|
16
16
|
paths:
|
|
@@ -77,4 +77,56 @@ describe('bundle', () => {
|
|
|
77
77
|
expect(problems).toHaveLength(0);
|
|
78
78
|
expect(res.parsed).toMatchSnapshot();
|
|
79
79
|
});
|
|
80
|
+
|
|
81
|
+
it('should place referenced schema inline when referenced schema name resolves to original schema name', async () => {
|
|
82
|
+
const { bundle: res, problems } = await bundle({
|
|
83
|
+
config: new Config({}),
|
|
84
|
+
ref: path.join(__dirname, 'fixtures/refs/externalref.yaml'),
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
expect(problems).toHaveLength(0);
|
|
88
|
+
expect(res.parsed).toMatchSnapshot();
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('should not place referened schema inline when component in question is not of type "schemas"', async () => {
|
|
92
|
+
const { bundle: res, problems } = await bundle({
|
|
93
|
+
config: new Config({}),
|
|
94
|
+
ref: path.join(__dirname, 'fixtures/refs/external-request-body.yaml'),
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
expect(problems).toHaveLength(0);
|
|
98
|
+
expect(res.parsed).toMatchSnapshot();
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('should pull hosted schema', async () => {
|
|
102
|
+
const fetchMock = jest.fn(
|
|
103
|
+
() => Promise.resolve({
|
|
104
|
+
ok: true,
|
|
105
|
+
text: () => 'External schema content',
|
|
106
|
+
headers: {
|
|
107
|
+
get: () => ''
|
|
108
|
+
}
|
|
109
|
+
})
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
const { bundle: res, problems } = await bundle({
|
|
113
|
+
config: new Config({}),
|
|
114
|
+
externalRefResolver: new BaseResolver({
|
|
115
|
+
http: {
|
|
116
|
+
customFetch: fetchMock,
|
|
117
|
+
headers: []
|
|
118
|
+
}
|
|
119
|
+
}),
|
|
120
|
+
ref: path.join(__dirname, 'fixtures/refs/hosted.yaml')
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
expect(problems).toHaveLength(0);
|
|
124
|
+
expect(fetchMock).toHaveBeenCalledWith(
|
|
125
|
+
"https://someexternal.schema",
|
|
126
|
+
{
|
|
127
|
+
headers: {}
|
|
128
|
+
}
|
|
129
|
+
);
|
|
130
|
+
expect(res.parsed).toMatchSnapshot();
|
|
131
|
+
})
|
|
80
132
|
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
openapi: 3.1.0
|
|
2
|
+
info:
|
|
3
|
+
title: My API
|
|
4
|
+
description: It ain't so wonderful, but at least it's mine.
|
|
5
|
+
version: '1.0'
|
|
6
|
+
contact:
|
|
7
|
+
email: me@theintenet.com
|
|
8
|
+
name: me
|
|
9
|
+
paths:
|
|
10
|
+
/test:
|
|
11
|
+
get:
|
|
12
|
+
summary: 'test'
|
|
13
|
+
responses:
|
|
14
|
+
200:
|
|
15
|
+
description: test
|
|
16
|
+
content:
|
|
17
|
+
application/json:
|
|
18
|
+
schema:
|
|
19
|
+
$ref: ./vendor.schema.yaml
|
|
20
|
+
components:
|
|
21
|
+
schemas:
|
|
22
|
+
vendor:
|
|
23
|
+
$ref: ./vendor.schema.yaml
|
|
24
|
+
myvendor:
|
|
25
|
+
$ref: ./vendor.schema.yaml
|
|
26
|
+
simple:
|
|
27
|
+
$ref: ./simple.yaml
|
|
28
|
+
A:
|
|
29
|
+
$ref: ./definitions.yaml#/$defs/A
|
|
30
|
+
test:
|
|
31
|
+
$ref: ./rename.yaml
|
|
32
|
+
rename:
|
|
33
|
+
type: string
|
|
34
|
+
rename-2:
|
|
35
|
+
$ref: ./rename.yaml
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
openapi: "3.0.3"
|
|
2
|
+
info:
|
|
3
|
+
title: bugtest
|
|
4
|
+
version: "1.0"
|
|
5
|
+
description: Demo
|
|
6
|
+
license:
|
|
7
|
+
name: DEMO
|
|
8
|
+
url: https://demo.com
|
|
9
|
+
servers:
|
|
10
|
+
- url: http://demo.com/api
|
|
11
|
+
paths:
|
|
12
|
+
/customer:
|
|
13
|
+
summary: "Customer scope"
|
|
14
|
+
get:
|
|
15
|
+
summary: "Get demo no refs"
|
|
16
|
+
operationId: GetCustomer
|
|
17
|
+
description: "Returns Demo No Refs"
|
|
18
|
+
responses:
|
|
19
|
+
200:
|
|
20
|
+
description: Demo No Refs
|
|
21
|
+
content:
|
|
22
|
+
application/json:
|
|
23
|
+
schema:
|
|
24
|
+
$ref: "#/components/schemas/Customer"
|
|
25
|
+
components:
|
|
26
|
+
schemas:
|
|
27
|
+
Customer:
|
|
28
|
+
type: object
|
|
29
|
+
properties:
|
|
30
|
+
customerName:
|
|
31
|
+
type: string
|
|
32
|
+
accounts:
|
|
33
|
+
type: array
|
|
34
|
+
items:
|
|
35
|
+
$ref: "https://someexternal.schema"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
type: number
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
type: string
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
title: vendor
|
|
2
|
+
type: object
|
|
3
|
+
description: Vendors
|
|
4
|
+
properties:
|
|
5
|
+
key:
|
|
6
|
+
type: string
|
|
7
|
+
description: System-assigned key for the vendor.
|
|
8
|
+
readOnly: true
|
|
9
|
+
id:
|
|
10
|
+
type: string
|
|
11
|
+
description: |
|
|
12
|
+
Unique identifier of the vendor.
|
|
13
|
+
You must specify a unique vendor ID when creating a vendor unless document sequencing is configured, in which case the ID is auto-generated.
|
|
14
|
+
name:
|
|
15
|
+
type: string
|
|
16
|
+
description: Name of the vendor.
|
|
17
|
+
isOneTimeUse:
|
|
18
|
+
type: boolean
|
|
19
|
+
description: One-time use
|
|
20
|
+
default: false
|
package/lib/bundle.d.ts
CHANGED
|
@@ -15,12 +15,14 @@ export declare function bundle(opts: {
|
|
|
15
15
|
config: Config;
|
|
16
16
|
dereference?: boolean;
|
|
17
17
|
base?: string;
|
|
18
|
+
skipRedoclyRegistryRefs?: boolean;
|
|
18
19
|
}): Promise<{
|
|
19
20
|
bundle: Document;
|
|
20
21
|
problems: import("./walk").NormalizedProblem[];
|
|
21
22
|
fileDependencies: Set<string>;
|
|
22
23
|
rootType: NormalizedNodeType;
|
|
23
24
|
refTypes: Map<string, NormalizedNodeType> | undefined;
|
|
25
|
+
visitorsData: Record<string, Record<string, unknown>>;
|
|
24
26
|
}>;
|
|
25
27
|
export declare function bundleDocument(opts: {
|
|
26
28
|
document: Document;
|
|
@@ -28,10 +30,12 @@ export declare function bundleDocument(opts: {
|
|
|
28
30
|
customTypes?: Record<string, NodeType>;
|
|
29
31
|
externalRefResolver: BaseResolver;
|
|
30
32
|
dereference?: boolean;
|
|
33
|
+
skipRedoclyRegistryRefs?: boolean;
|
|
31
34
|
}): Promise<{
|
|
32
35
|
bundle: Document;
|
|
33
36
|
problems: import("./walk").NormalizedProblem[];
|
|
34
37
|
fileDependencies: Set<string>;
|
|
35
38
|
rootType: NormalizedNodeType;
|
|
36
39
|
refTypes: Map<string, NormalizedNodeType> | undefined;
|
|
40
|
+
visitorsData: Record<string, Record<string, unknown>>;
|
|
37
41
|
}>;
|
package/lib/bundle.js
CHANGED
|
@@ -23,6 +23,7 @@ const ref_utils_1 = require("./ref-utils");
|
|
|
23
23
|
const rules_1 = require("./config/rules");
|
|
24
24
|
const no_unresolved_refs_1 = require("./rules/no-unresolved-refs");
|
|
25
25
|
const utils_1 = require("./utils");
|
|
26
|
+
const redocly_1 = require("./redocly");
|
|
26
27
|
var OasVersion;
|
|
27
28
|
(function (OasVersion) {
|
|
28
29
|
OasVersion["Version2"] = "oas2";
|
|
@@ -45,24 +46,29 @@ function bundle(opts) {
|
|
|
45
46
|
exports.bundle = bundle;
|
|
46
47
|
function bundleDocument(opts) {
|
|
47
48
|
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
-
const { document, config, customTypes, externalRefResolver, dereference = false } = opts;
|
|
49
|
+
const { document, config, customTypes, externalRefResolver, dereference = false, skipRedoclyRegistryRefs = false, } = opts;
|
|
49
50
|
const oasVersion = oas_types_1.detectOpenAPI(document.parsed);
|
|
50
51
|
const oasMajorVersion = oas_types_1.openAPIMajor(oasVersion);
|
|
51
52
|
const rules = config.getRulesForOasVersion(oasMajorVersion);
|
|
52
|
-
const types = types_1.normalizeTypes(config.extendTypes((customTypes !== null && customTypes !== void 0 ? customTypes : oasMajorVersion === oas_types_1.OasMajorVersion.Version3)
|
|
53
|
+
const types = types_1.normalizeTypes(config.extendTypes((customTypes !== null && customTypes !== void 0 ? customTypes : oasMajorVersion === oas_types_1.OasMajorVersion.Version3)
|
|
54
|
+
? oasVersion === OasVersion.Version3_1
|
|
55
|
+
? oas3_1_1.Oas3_1Types
|
|
56
|
+
: oas3_1.Oas3Types
|
|
57
|
+
: oas2_1.Oas2Types, oasVersion), config);
|
|
53
58
|
const preprocessors = rules_1.initRules(rules, config, 'preprocessors', oasVersion);
|
|
54
59
|
const decorators = rules_1.initRules(rules, config, 'decorators', oasVersion);
|
|
55
60
|
const ctx = {
|
|
56
61
|
problems: [],
|
|
57
62
|
oasVersion: oasVersion,
|
|
58
63
|
refTypes: new Map(),
|
|
64
|
+
visitorsData: {},
|
|
59
65
|
};
|
|
60
66
|
const bundleVisitor = visitors_1.normalizeVisitors([
|
|
61
67
|
...preprocessors,
|
|
62
68
|
{
|
|
63
69
|
severity: 'error',
|
|
64
70
|
ruleId: 'bundler',
|
|
65
|
-
visitor: makeBundleVisitor(oasMajorVersion, dereference, document),
|
|
71
|
+
visitor: makeBundleVisitor(oasMajorVersion, dereference, skipRedoclyRegistryRefs, document),
|
|
66
72
|
},
|
|
67
73
|
...decorators,
|
|
68
74
|
], types);
|
|
@@ -84,6 +90,7 @@ function bundleDocument(opts) {
|
|
|
84
90
|
fileDependencies: externalRefResolver.getFiles(),
|
|
85
91
|
rootType: types.DefinitionRoot,
|
|
86
92
|
refTypes: ctx.refTypes,
|
|
93
|
+
visitorsData: ctx.visitorsData,
|
|
87
94
|
};
|
|
88
95
|
});
|
|
89
96
|
}
|
|
@@ -127,7 +134,7 @@ function mapTypeToComponent(typeName, version) {
|
|
|
127
134
|
}
|
|
128
135
|
}
|
|
129
136
|
// function oas3Move
|
|
130
|
-
function makeBundleVisitor(version, dereference, rootDocument) {
|
|
137
|
+
function makeBundleVisitor(version, dereference, skipRedoclyRegistryRefs, rootDocument) {
|
|
131
138
|
let components;
|
|
132
139
|
const visitor = {
|
|
133
140
|
ref: {
|
|
@@ -142,6 +149,9 @@ function makeBundleVisitor(version, dereference, rootDocument) {
|
|
|
142
149
|
!dereference) {
|
|
143
150
|
return;
|
|
144
151
|
}
|
|
152
|
+
if (skipRedoclyRegistryRefs && redocly_1.isRedoclyRegistryURL(node.$ref)) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
145
155
|
const componentType = mapTypeToComponent(ctx.type.name, version);
|
|
146
156
|
if (!componentType) {
|
|
147
157
|
replaceRef(node, resolved, ctx);
|
|
@@ -210,6 +220,14 @@ function makeBundleVisitor(version, dereference, rootDocument) {
|
|
|
210
220
|
return `#/${componentType}/${name}`;
|
|
211
221
|
}
|
|
212
222
|
}
|
|
223
|
+
function isEqualOrEqualRef(node, target, ctx) {
|
|
224
|
+
var _a;
|
|
225
|
+
if (ref_utils_1.isRef(node) &&
|
|
226
|
+
((_a = ctx.resolve(node).location) === null || _a === void 0 ? void 0 : _a.absolutePointer) === target.location.absolutePointer) {
|
|
227
|
+
return true;
|
|
228
|
+
}
|
|
229
|
+
return isEqual(node, target.node);
|
|
230
|
+
}
|
|
213
231
|
function getComponentName(target, componentType, ctx) {
|
|
214
232
|
const [fileRef, pointer] = [target.location.source.absoluteRef, target.location.pointer];
|
|
215
233
|
const componentsGroup = components[componentType];
|
|
@@ -219,17 +237,17 @@ function makeBundleVisitor(version, dereference, rootDocument) {
|
|
|
219
237
|
name = refParts.pop() + (name ? `-${name}` : '');
|
|
220
238
|
if (!componentsGroup ||
|
|
221
239
|
!componentsGroup[name] ||
|
|
222
|
-
|
|
240
|
+
isEqualOrEqualRef(componentsGroup[name], target, ctx)) {
|
|
223
241
|
return name;
|
|
224
242
|
}
|
|
225
243
|
}
|
|
226
244
|
name = ref_utils_1.refBaseName(fileRef) + (name ? `_${name}` : '');
|
|
227
|
-
if (!componentsGroup[name] ||
|
|
245
|
+
if (!componentsGroup[name] || isEqualOrEqualRef(componentsGroup[name], target, ctx)) {
|
|
228
246
|
return name;
|
|
229
247
|
}
|
|
230
248
|
const prevName = name;
|
|
231
249
|
let serialId = 2;
|
|
232
|
-
while (componentsGroup[name] && !
|
|
250
|
+
while (componentsGroup[name] && !isEqualOrEqualRef(componentsGroup[name], target, ctx)) {
|
|
233
251
|
name = `${prevName}-${serialId}`;
|
|
234
252
|
serialId++;
|
|
235
253
|
}
|
package/lib/config/all.js
CHANGED
|
@@ -12,11 +12,13 @@ exports.default = {
|
|
|
12
12
|
'no-identical-paths': 'error',
|
|
13
13
|
'no-ambiguous-paths': 'error',
|
|
14
14
|
'no-path-trailing-slash': 'error',
|
|
15
|
+
'path-segment-plural': 'error',
|
|
15
16
|
'path-declaration-must-exist': 'error',
|
|
16
17
|
'path-not-include-query': 'error',
|
|
17
18
|
'path-parameters-defined': 'error',
|
|
18
19
|
'operation-description': 'error',
|
|
19
20
|
'operation-2xx-response': 'error',
|
|
21
|
+
'operation-4xx-response': 'error',
|
|
20
22
|
'operation-operationId': 'error',
|
|
21
23
|
'operation-summary': 'error',
|
|
22
24
|
'operation-operationId-unique': 'error',
|
|
@@ -29,6 +31,12 @@ exports.default = {
|
|
|
29
31
|
'no-enum-type-mismatch': 'error',
|
|
30
32
|
'boolean-parameter-prefixes': 'error',
|
|
31
33
|
'paths-kebab-case': 'error',
|
|
34
|
+
'no-http-verbs-in-paths': 'error',
|
|
35
|
+
'path-excludes-patterns': {
|
|
36
|
+
severity: 'error',
|
|
37
|
+
patterns: [],
|
|
38
|
+
},
|
|
39
|
+
'request-mime-type': 'error',
|
|
32
40
|
spec: 'error',
|
|
33
41
|
},
|
|
34
42
|
oas3_0Rules: {
|
|
@@ -49,5 +57,5 @@ exports.default = {
|
|
|
49
57
|
'no-unused-components': 'error',
|
|
50
58
|
'no-undefined-server-variable': 'error',
|
|
51
59
|
'no-servers-empty-enum': 'error',
|
|
52
|
-
}
|
|
60
|
+
},
|
|
53
61
|
};
|
package/lib/config/config.js
CHANGED
|
@@ -73,7 +73,7 @@ class LintConfig {
|
|
|
73
73
|
const ignoreFile = path.join(dir, exports.IGNORE_FILE);
|
|
74
74
|
const mapped = {};
|
|
75
75
|
for (const absFileName of Object.keys(this.ignore)) {
|
|
76
|
-
const ignoredRules = (mapped[path.relative(dir, absFileName)] = this.ignore[absFileName]);
|
|
76
|
+
const ignoredRules = (mapped[utils_1.slash(path.relative(dir, absFileName))] = this.ignore[absFileName]);
|
|
77
77
|
for (const ruleId of Object.keys(ignoredRules)) {
|
|
78
78
|
ignoredRules[ruleId] = Array.from(ignoredRules[ruleId]);
|
|
79
79
|
}
|
package/lib/config/minimal.js
CHANGED
|
@@ -17,6 +17,7 @@ exports.default = {
|
|
|
17
17
|
'path-parameters-defined': 'warn',
|
|
18
18
|
'operation-description': 'off',
|
|
19
19
|
'operation-2xx-response': 'warn',
|
|
20
|
+
'operation-4xx-response': 'off',
|
|
20
21
|
'operation-operationId': 'warn',
|
|
21
22
|
'operation-summary': 'warn',
|
|
22
23
|
'operation-operationId-unique': 'warn',
|
|
@@ -17,6 +17,7 @@ exports.default = {
|
|
|
17
17
|
'path-parameters-defined': 'error',
|
|
18
18
|
'operation-description': 'off',
|
|
19
19
|
'operation-2xx-response': 'warn',
|
|
20
|
+
'operation-4xx-response': 'warn',
|
|
20
21
|
'operation-operationId': 'warn',
|
|
21
22
|
'operation-summary': 'error',
|
|
22
23
|
'operation-operationId-unique': 'error',
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.bundleDocument = exports.bundle = exports.lintConfig = exports.lintFromString = exports.lintDocument = exports.validate = exports.lint = exports.getTotals = exports.formatProblems = exports.getLineColLocation = exports.getAstNodeByPointer = exports.walkDocument = exports.normalizeVisitors = exports.OasVersion = exports.openAPIMajor = exports.OasMajorVersion = exports.detectOpenAPI = exports.unescapePointer = exports.stringifyYaml = exports.parseYaml = exports.makeDocumentFromString = exports.YamlParseError = exports.ResolveError = exports.resolveDocument = exports.BaseResolver = exports.Source = exports.RedoclyClient = exports.loadConfig = exports.IGNORE_FILE = exports.LintConfig = exports.Config = exports.Stats = exports.normalizeTypes = exports.ConfigTypes = exports.Oas2Types = exports.Oas3Types = exports.Oas3_1Types = exports.readFileFromUrl = void 0;
|
|
3
|
+
exports.bundleDocument = exports.bundle = exports.lintConfig = exports.lintFromString = exports.lintDocument = exports.validate = exports.lint = exports.getTotals = exports.formatProblems = exports.getLineColLocation = exports.getAstNodeByPointer = exports.walkDocument = exports.normalizeVisitors = exports.OasVersion = exports.openAPIMajor = exports.OasMajorVersion = exports.detectOpenAPI = exports.unescapePointer = exports.stringifyYaml = exports.parseYaml = exports.makeDocumentFromString = exports.YamlParseError = exports.ResolveError = exports.resolveDocument = exports.BaseResolver = exports.Source = exports.RedoclyClient = exports.loadConfig = exports.IGNORE_FILE = exports.LintConfig = exports.Config = exports.Stats = exports.normalizeTypes = exports.ConfigTypes = exports.Oas2Types = exports.Oas3Types = exports.Oas3_1Types = exports.slash = exports.readFileFromUrl = void 0;
|
|
4
4
|
var utils_1 = require("./utils");
|
|
5
5
|
Object.defineProperty(exports, "readFileFromUrl", { enumerable: true, get: function () { return utils_1.readFileFromUrl; } });
|
|
6
|
+
Object.defineProperty(exports, "slash", { enumerable: true, get: function () { return utils_1.slash; } });
|
|
6
7
|
var oas3_1_1 = require("./types/oas3_1");
|
|
7
8
|
Object.defineProperty(exports, "Oas3_1Types", { enumerable: true, get: function () { return oas3_1_1.Oas3_1Types; } });
|
|
8
9
|
var oas3_1 = require("./types/oas3");
|
package/lib/lint.js
CHANGED
|
@@ -51,6 +51,7 @@ function lintDocument(opts) {
|
|
|
51
51
|
const ctx = {
|
|
52
52
|
problems: [],
|
|
53
53
|
oasVersion: oasVersion,
|
|
54
|
+
visitorsData: {},
|
|
54
55
|
};
|
|
55
56
|
const preprocessors = rules_1.initRules(rules, config, 'preprocessors', oasVersion);
|
|
56
57
|
const regularRules = rules_1.initRules(rules, config, 'rules', oasVersion);
|
|
@@ -77,6 +78,7 @@ function lintConfig(opts) {
|
|
|
77
78
|
const ctx = {
|
|
78
79
|
problems: [],
|
|
79
80
|
oasVersion: oas_types_1.OasVersion.Version3_0,
|
|
81
|
+
visitorsData: {},
|
|
80
82
|
};
|
|
81
83
|
const config = new config_1.LintConfig({
|
|
82
84
|
plugins: [builtIn_1.defaultPlugin],
|
package/lib/redocly/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { RegistryApi } from './registry-api';
|
|
1
2
|
export declare class RedoclyClient {
|
|
2
3
|
private accessToken;
|
|
4
|
+
registryApi: RegistryApi;
|
|
3
5
|
constructor();
|
|
4
6
|
hasToken(): boolean;
|
|
5
7
|
loadToken(): void;
|
|
@@ -8,18 +10,5 @@ export declare class RedoclyClient {
|
|
|
8
10
|
getAuthorizationHeader(): Promise<string | undefined>;
|
|
9
11
|
login(accessToken: string, verbose?: boolean): Promise<void>;
|
|
10
12
|
logout(): void;
|
|
11
|
-
query(queryString: string, parameters?: {}, headers?: {}): Promise<any>;
|
|
12
|
-
static authorize(accessToken: string, options: {
|
|
13
|
-
queryName?: string;
|
|
14
|
-
verbose?: boolean;
|
|
15
|
-
}): Promise<any>;
|
|
16
|
-
updateDependencies(dependencies: string[] | undefined): Promise<void>;
|
|
17
|
-
updateDefinitionVersion(definitionId: number, versionId: number, updatePatch: object): Promise<void>;
|
|
18
|
-
getOrganizationId(organizationId: string): Promise<any>;
|
|
19
|
-
getDefinitionByName(name: string, organizationId: string): Promise<any>;
|
|
20
|
-
createDefinition(organizationId: string, name: string): Promise<any>;
|
|
21
|
-
createDefinitionVersion(definitionId: string, name: string, sourceType: string, source: any): Promise<any>;
|
|
22
|
-
getSignedUrl(organizationId: string, filesHash: string, fileName: string): Promise<any>;
|
|
23
|
-
getDefinitionVersion(organizationId: string, definitionName: string, versionName: string): Promise<any>;
|
|
24
|
-
static isRegistryURL(link: string): boolean;
|
|
25
13
|
}
|
|
14
|
+
export declare function isRedoclyRegistryURL(link: string): boolean;
|