@redocly/openapi-core 1.0.0-beta.76 → 1.0.0-beta.80
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/bundle.d.ts +3 -1
- package/lib/bundle.js +30 -8
- package/lib/config/builtIn.js +18 -4
- package/lib/config/config.d.ts +2 -9
- 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/decorators/common/remove-x-internal.d.ts +2 -0
- package/lib/decorators/common/remove-x-internal.js +58 -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/format/format.d.ts +1 -1
- package/lib/format/format.js +39 -1
- package/lib/js-yaml/index.js +1 -1
- package/lib/resolve.d.ts +1 -0
- package/lib/resolve.js +7 -3
- package/lib/rules/oas2/index.d.ts +1 -7
- package/lib/rules/oas2/index.js +1 -11
- package/lib/rules/oas2/remove-unused-components.d.ts +2 -0
- package/lib/rules/oas2/remove-unused-components.js +73 -0
- package/lib/rules/oas3/index.d.ts +0 -7
- package/lib/rules/oas3/index.js +1 -11
- package/lib/rules/oas3/remove-unused-components.d.ts +2 -0
- package/lib/rules/oas3/remove-unused-components.js +83 -0
- package/lib/typings/swagger.d.ts +14 -0
- package/lib/utils.d.ts +2 -0
- package/lib/utils.js +9 -1
- package/lib/walk.js +5 -8
- package/package.json +1 -1
- package/src/__tests__/js-yaml.test.ts +29 -5
- package/src/__tests__/lint.test.ts +1 -3
- package/src/bundle.ts +37 -8
- package/src/config/builtIn.ts +20 -7
- package/src/config/config.ts +2 -3
- package/src/decorators/__tests__/remove-x-internal.test.ts +316 -0
- 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/decorators/common/remove-x-internal.ts +59 -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/format/format.ts +47 -2
- package/src/js-yaml/index.ts +1 -2
- package/src/resolve.ts +6 -6
- 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/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 -11
- package/src/rules/oas2/remove-unused-components.ts +76 -0
- 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 -12
- package/src/rules/oas3/remove-unused-components.ts +84 -0
- package/src/types/oas2.ts +0 -3
- package/src/typings/swagger.ts +7 -0
- package/src/utils.ts +8 -0
- package/src/walk.ts +6 -13
- package/tsconfig.tsbuildinfo +1 -1
- package/lib/rules/builtin.d.ts +0 -20
- package/lib/rules/builtin.js +0 -17
- package/src/rules/__tests__/config.ts +0 -10
- package/src/rules/builtin.ts +0 -18
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
import { outdent } from 'outdent';
|
|
2
|
+
import { bundleDocument } from '../../bundle';
|
|
3
|
+
import { BaseResolver } from '../../resolve';
|
|
4
|
+
import { parseYamlToDocument, yamlSerializer, makeConfig } from '../../../__tests__/utils';
|
|
5
|
+
|
|
6
|
+
describe('oas3 remove-x-internal', () => {
|
|
7
|
+
expect.addSnapshotSerializer(yamlSerializer);
|
|
8
|
+
const testDocument = parseYamlToDocument(
|
|
9
|
+
outdent`
|
|
10
|
+
openapi: 3.0.0
|
|
11
|
+
paths:
|
|
12
|
+
/pet:
|
|
13
|
+
removeit: true
|
|
14
|
+
get:
|
|
15
|
+
parameters:
|
|
16
|
+
- $ref: '#/components/parameters/x'
|
|
17
|
+
components:
|
|
18
|
+
parameters:
|
|
19
|
+
x:
|
|
20
|
+
name: x
|
|
21
|
+
`,
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
it('should use `internalFlagProperty` option to remove internal paths', async () => {
|
|
25
|
+
const { bundle: res } = await bundleDocument({
|
|
26
|
+
document: testDocument,
|
|
27
|
+
externalRefResolver: new BaseResolver(),
|
|
28
|
+
config: makeConfig({}, { 'remove-x-internal': { internalFlagProperty: 'removeit' } }),
|
|
29
|
+
});
|
|
30
|
+
expect(res.parsed).toMatchInlineSnapshot(`
|
|
31
|
+
openapi: 3.0.0
|
|
32
|
+
components:
|
|
33
|
+
parameters:
|
|
34
|
+
x:
|
|
35
|
+
name: x
|
|
36
|
+
|
|
37
|
+
`);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('should clean types: Server, Operation, Parameter, PathItem, Example', async () => {
|
|
41
|
+
const testDoc = parseYamlToDocument(
|
|
42
|
+
outdent`
|
|
43
|
+
openapi: 3.1.0
|
|
44
|
+
servers:
|
|
45
|
+
- url: //petstore.swagger.io/v2
|
|
46
|
+
description: Default server
|
|
47
|
+
x-internal: true
|
|
48
|
+
paths:
|
|
49
|
+
/pet:
|
|
50
|
+
get:
|
|
51
|
+
x-internal: true
|
|
52
|
+
operationId: getPet
|
|
53
|
+
parameters:
|
|
54
|
+
- $ref: '#/components/parameters/x'
|
|
55
|
+
put:
|
|
56
|
+
parameters:
|
|
57
|
+
- name: Accept-Language
|
|
58
|
+
x-internal: true
|
|
59
|
+
in: header
|
|
60
|
+
example: en-US
|
|
61
|
+
required: false
|
|
62
|
+
- name: cookieParam
|
|
63
|
+
x-internal: true
|
|
64
|
+
in: cookie
|
|
65
|
+
description: Some cookie
|
|
66
|
+
required: true
|
|
67
|
+
/admin:
|
|
68
|
+
x-internal: true
|
|
69
|
+
post:
|
|
70
|
+
parameters:
|
|
71
|
+
- $ref: '#/components/parameters/y'
|
|
72
|
+
/store/order:
|
|
73
|
+
post:
|
|
74
|
+
operationId: placeOrder
|
|
75
|
+
responses:
|
|
76
|
+
'200':
|
|
77
|
+
description: successful operation
|
|
78
|
+
content:
|
|
79
|
+
application/json:
|
|
80
|
+
examples:
|
|
81
|
+
response:
|
|
82
|
+
x-internal: true
|
|
83
|
+
value: OK
|
|
84
|
+
components:
|
|
85
|
+
parameters:
|
|
86
|
+
x:
|
|
87
|
+
name: x
|
|
88
|
+
y:
|
|
89
|
+
name: y
|
|
90
|
+
`,
|
|
91
|
+
);
|
|
92
|
+
const { bundle: res } = await bundleDocument({
|
|
93
|
+
document: testDoc,
|
|
94
|
+
externalRefResolver: new BaseResolver(),
|
|
95
|
+
config: makeConfig({}, { 'remove-x-internal': 'on' }),
|
|
96
|
+
});
|
|
97
|
+
expect(res.parsed).toMatchInlineSnapshot(`
|
|
98
|
+
openapi: 3.1.0
|
|
99
|
+
paths:
|
|
100
|
+
/pet:
|
|
101
|
+
put: {}
|
|
102
|
+
/store/order:
|
|
103
|
+
post:
|
|
104
|
+
operationId: placeOrder
|
|
105
|
+
responses:
|
|
106
|
+
'200':
|
|
107
|
+
description: successful operation
|
|
108
|
+
content:
|
|
109
|
+
application/json: {}
|
|
110
|
+
components:
|
|
111
|
+
parameters:
|
|
112
|
+
x:
|
|
113
|
+
name: x
|
|
114
|
+
'y':
|
|
115
|
+
name: 'y'
|
|
116
|
+
|
|
117
|
+
`);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('should clean types: Schema, Response, RequestBody, MediaType, Callback', async () => {
|
|
121
|
+
const testDoc = parseYamlToDocument(
|
|
122
|
+
outdent`
|
|
123
|
+
openapi: 3.1.0
|
|
124
|
+
paths:
|
|
125
|
+
/pet:
|
|
126
|
+
post:
|
|
127
|
+
summary: test
|
|
128
|
+
requestBody:
|
|
129
|
+
x-internal: true
|
|
130
|
+
content:
|
|
131
|
+
application/x-www-form-urlencoded:
|
|
132
|
+
schema:
|
|
133
|
+
type: object
|
|
134
|
+
/store/order:
|
|
135
|
+
post:
|
|
136
|
+
operationId: storeOrder
|
|
137
|
+
parameters:
|
|
138
|
+
- name: api_key
|
|
139
|
+
schema:
|
|
140
|
+
x-internal: true
|
|
141
|
+
type: string
|
|
142
|
+
responses:
|
|
143
|
+
'200':
|
|
144
|
+
x-internal: true
|
|
145
|
+
content:
|
|
146
|
+
application/json:
|
|
147
|
+
examples:
|
|
148
|
+
response:
|
|
149
|
+
value: OK
|
|
150
|
+
requestBody:
|
|
151
|
+
content:
|
|
152
|
+
application/x-www-form-urlencoded:
|
|
153
|
+
x-internal: true
|
|
154
|
+
schema:
|
|
155
|
+
type: object
|
|
156
|
+
callbacks:
|
|
157
|
+
orderInProgress:
|
|
158
|
+
x-internal: true
|
|
159
|
+
'{$request.body#/callbackUrl}?event={$request.body#/eventName}':
|
|
160
|
+
servers:
|
|
161
|
+
- url: //callback-url.path-level/v1
|
|
162
|
+
description: Path level server
|
|
163
|
+
`,
|
|
164
|
+
);
|
|
165
|
+
const { bundle: res } = await bundleDocument({
|
|
166
|
+
document: testDoc,
|
|
167
|
+
externalRefResolver: new BaseResolver(),
|
|
168
|
+
config: makeConfig({}, { 'remove-x-internal': 'on' }),
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
expect(res.parsed).toMatchInlineSnapshot(`
|
|
172
|
+
openapi: 3.1.0
|
|
173
|
+
paths:
|
|
174
|
+
/pet:
|
|
175
|
+
post:
|
|
176
|
+
summary: test
|
|
177
|
+
/store/order:
|
|
178
|
+
post:
|
|
179
|
+
operationId: storeOrder
|
|
180
|
+
parameters:
|
|
181
|
+
- name: api_key
|
|
182
|
+
requestBody: {}
|
|
183
|
+
components: {}
|
|
184
|
+
|
|
185
|
+
`);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('should remove refs', async () => {
|
|
189
|
+
const testDoc = parseYamlToDocument(
|
|
190
|
+
outdent`
|
|
191
|
+
openapi: 3.0.1
|
|
192
|
+
info:
|
|
193
|
+
version: 1.0.0
|
|
194
|
+
title: Test API
|
|
195
|
+
paths:
|
|
196
|
+
/test1:
|
|
197
|
+
get:
|
|
198
|
+
parameters:
|
|
199
|
+
- $ref: '#/components/parameters/Internal'
|
|
200
|
+
- in: query
|
|
201
|
+
name: inline
|
|
202
|
+
schema:
|
|
203
|
+
type: string
|
|
204
|
+
- in: query
|
|
205
|
+
name: inline-internal
|
|
206
|
+
schema:
|
|
207
|
+
type: string
|
|
208
|
+
x-internal: true
|
|
209
|
+
/test2:
|
|
210
|
+
get:
|
|
211
|
+
parameters:
|
|
212
|
+
- $ref: '#/components/parameters/Public'
|
|
213
|
+
- $ref: '#/components/parameters/Internal'
|
|
214
|
+
requestBody:
|
|
215
|
+
$ref: '#/components/requestBodies/Public'
|
|
216
|
+
components:
|
|
217
|
+
requestBodies:
|
|
218
|
+
Public:
|
|
219
|
+
content:
|
|
220
|
+
application/json:
|
|
221
|
+
schema:
|
|
222
|
+
type: string
|
|
223
|
+
required: true
|
|
224
|
+
x-internal: true
|
|
225
|
+
parameters:
|
|
226
|
+
Public:
|
|
227
|
+
in: path
|
|
228
|
+
name: product_id
|
|
229
|
+
schema:
|
|
230
|
+
type: string
|
|
231
|
+
Internal:
|
|
232
|
+
in: header
|
|
233
|
+
name: X-Vendor
|
|
234
|
+
schema:
|
|
235
|
+
type: string
|
|
236
|
+
x-internal: true
|
|
237
|
+
`,
|
|
238
|
+
);
|
|
239
|
+
const { bundle: res } = await bundleDocument({
|
|
240
|
+
document: testDoc,
|
|
241
|
+
externalRefResolver: new BaseResolver(),
|
|
242
|
+
config: makeConfig({}, { 'remove-x-internal': 'on' }),
|
|
243
|
+
});
|
|
244
|
+
expect(res.parsed).toMatchInlineSnapshot(`
|
|
245
|
+
openapi: 3.0.1
|
|
246
|
+
info:
|
|
247
|
+
version: 1.0.0
|
|
248
|
+
title: Test API
|
|
249
|
+
paths:
|
|
250
|
+
/test1:
|
|
251
|
+
get:
|
|
252
|
+
parameters:
|
|
253
|
+
- in: query
|
|
254
|
+
name: inline
|
|
255
|
+
schema:
|
|
256
|
+
type: string
|
|
257
|
+
/test2:
|
|
258
|
+
get:
|
|
259
|
+
parameters:
|
|
260
|
+
- $ref: '#/components/parameters/Public'
|
|
261
|
+
components:
|
|
262
|
+
parameters:
|
|
263
|
+
Public:
|
|
264
|
+
in: path
|
|
265
|
+
name: product_id
|
|
266
|
+
schema:
|
|
267
|
+
type: string
|
|
268
|
+
|
|
269
|
+
`);
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
describe('oas2 remove-x-internal', () => {
|
|
274
|
+
it('should clean types - base test', async () => {
|
|
275
|
+
const testDoc = parseYamlToDocument(
|
|
276
|
+
outdent`
|
|
277
|
+
swagger: '2.0'
|
|
278
|
+
host: api.instagram.com
|
|
279
|
+
paths:
|
|
280
|
+
'/geographies/{geo-id}/media/recent':
|
|
281
|
+
get:
|
|
282
|
+
parameters:
|
|
283
|
+
- description: The geography ID.
|
|
284
|
+
x-internal: true
|
|
285
|
+
in: path
|
|
286
|
+
name: geo-id
|
|
287
|
+
required: true
|
|
288
|
+
type: string
|
|
289
|
+
- description: Max number of media to return.
|
|
290
|
+
x-internal: true
|
|
291
|
+
format: int32
|
|
292
|
+
in: query
|
|
293
|
+
name: count
|
|
294
|
+
required: false
|
|
295
|
+
type: integer
|
|
296
|
+
responses:
|
|
297
|
+
'200':
|
|
298
|
+
x-internal: true
|
|
299
|
+
description: List of recent media entries.
|
|
300
|
+
`,
|
|
301
|
+
);
|
|
302
|
+
const { bundle: res } = await bundleDocument({
|
|
303
|
+
document: testDoc,
|
|
304
|
+
externalRefResolver: new BaseResolver(),
|
|
305
|
+
config: makeConfig({}, { 'remove-x-internal': 'on' }),
|
|
306
|
+
});
|
|
307
|
+
expect(res.parsed).toMatchInlineSnapshot(`
|
|
308
|
+
swagger: '2.0'
|
|
309
|
+
host: api.instagram.com
|
|
310
|
+
paths:
|
|
311
|
+
/geographies/{geo-id}/media/recent:
|
|
312
|
+
get: {}
|
|
313
|
+
|
|
314
|
+
`);
|
|
315
|
+
});
|
|
316
|
+
});
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Oas3Decorator, Oas2Decorator } from '../../visitors';
|
|
2
|
+
import { isEmptyArray, isEmptyObject, isPlainObject } from '../../utils';
|
|
3
|
+
import { UserContext } from '../../walk';
|
|
4
|
+
import { isRef } from '../../ref-utils';
|
|
5
|
+
|
|
6
|
+
const DEFAULT_INTERNAL_PROPERTY_NAME = 'x-internal';
|
|
7
|
+
|
|
8
|
+
export const RemoveXInternal: Oas3Decorator | Oas2Decorator = ({ internalFlagProperty }) => {
|
|
9
|
+
const hiddenTag = internalFlagProperty || DEFAULT_INTERNAL_PROPERTY_NAME;
|
|
10
|
+
|
|
11
|
+
function removeInternal(node: any, ctx: UserContext) {
|
|
12
|
+
const { parent, key } = ctx;
|
|
13
|
+
let didDelete = false;
|
|
14
|
+
if (Array.isArray(node)) {
|
|
15
|
+
for (let i = 0; i < node.length; i++) {
|
|
16
|
+
if (isRef(node[i])) {
|
|
17
|
+
const resolved = ctx.resolve(node[i]);
|
|
18
|
+
if (resolved.node?.[hiddenTag]) {
|
|
19
|
+
node.splice(i, 1);
|
|
20
|
+
didDelete = true;
|
|
21
|
+
i--;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (node[i]?.[hiddenTag]) {
|
|
25
|
+
node.splice(i, 1);
|
|
26
|
+
didDelete = true;
|
|
27
|
+
i--;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
} else if (isPlainObject(node)) {
|
|
31
|
+
for (const key of Object.keys(node)) {
|
|
32
|
+
node = node as any;
|
|
33
|
+
if (isRef(node[key])) {
|
|
34
|
+
const resolved = ctx.resolve(node[key]);
|
|
35
|
+
if (resolved.node?.[hiddenTag]) {
|
|
36
|
+
delete node[key];
|
|
37
|
+
didDelete = true;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (node[key]?.[hiddenTag]) {
|
|
41
|
+
delete node[key];
|
|
42
|
+
didDelete = true;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (didDelete && (isEmptyObject(node) || isEmptyArray(node))) {
|
|
48
|
+
delete parent[key];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
any: {
|
|
54
|
+
enter: (node, ctx) => {
|
|
55
|
+
removeInternal(node, ctx);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
File without changes
|
|
@@ -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/format/format.ts
CHANGED
|
@@ -46,7 +46,7 @@ function severityToNumber(severity: ProblemSeverity) {
|
|
|
46
46
|
return severity === 'error' ? 1 : 2;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
export type OutputFormat = 'codeframe' | 'stylish' | 'json';
|
|
49
|
+
export type OutputFormat = 'codeframe' | 'stylish' | 'json' | 'checkstyle';
|
|
50
50
|
|
|
51
51
|
export function getTotals(problems: (NormalizedProblem & { ignored?: boolean })[]): Totals {
|
|
52
52
|
let errors = 0;
|
|
@@ -111,7 +111,7 @@ export function formatProblems(
|
|
|
111
111
|
process.stderr.write(`${formatCodeframe(problem, i)}\n`);
|
|
112
112
|
}
|
|
113
113
|
break;
|
|
114
|
-
case 'stylish':
|
|
114
|
+
case 'stylish': {
|
|
115
115
|
const groupedByFile = groupByFiles(problems);
|
|
116
116
|
for (const [file, { ruleIdPad, locationPad: positionPad, fileProblems }] of Object.entries(
|
|
117
117
|
groupedByFile,
|
|
@@ -126,6 +126,22 @@ export function formatProblems(
|
|
|
126
126
|
process.stderr.write('\n');
|
|
127
127
|
}
|
|
128
128
|
break;
|
|
129
|
+
}
|
|
130
|
+
case 'checkstyle': {
|
|
131
|
+
const groupedByFile = groupByFiles(problems);
|
|
132
|
+
|
|
133
|
+
process.stdout.write('<?xml version="1.0" encoding="UTF-8"?>\n');
|
|
134
|
+
process.stdout.write('<checkstyle version="4.3">\n');
|
|
135
|
+
|
|
136
|
+
for (const [file, { fileProblems }] of Object.entries(groupedByFile)) {
|
|
137
|
+
process.stdout.write(`<file name="${xmlEscape(path.relative(cwd, file))}">\n`);
|
|
138
|
+
fileProblems.forEach(formatCheckstyle);
|
|
139
|
+
process.stdout.write(`</file>\n`);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
process.stdout.write(`</checkstyle>\n`);
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
129
145
|
}
|
|
130
146
|
|
|
131
147
|
if (totalProblems - ignoredProblems > maxProblems) {
|
|
@@ -204,6 +220,16 @@ export function formatProblems(
|
|
|
204
220
|
locationPad,
|
|
205
221
|
)} ${severityName} ${problem.ruleId.padEnd(ruleIdPad)} ${problem.message}`;
|
|
206
222
|
}
|
|
223
|
+
|
|
224
|
+
function formatCheckstyle(problem: OnlyLineColProblem) {
|
|
225
|
+
const { line, col } = problem.location[0].start;
|
|
226
|
+
const severity = problem.severity == 'warn' ? 'warning' : 'error';
|
|
227
|
+
const message = xmlEscape(problem.message);
|
|
228
|
+
const source = xmlEscape(problem.ruleId);
|
|
229
|
+
process.stdout.write(
|
|
230
|
+
`<error line="${line}" column="${col}" severity="${severity}" message="${message}" source="${source}" />\n`,
|
|
231
|
+
);
|
|
232
|
+
}
|
|
207
233
|
}
|
|
208
234
|
|
|
209
235
|
function formatFrom(cwd: string, location?: LocationObject) {
|
|
@@ -261,3 +287,22 @@ const groupByFiles = (problems: NormalizedProblem[]) => {
|
|
|
261
287
|
|
|
262
288
|
return fileGroups;
|
|
263
289
|
};
|
|
290
|
+
|
|
291
|
+
function xmlEscape(s: string): string {
|
|
292
|
+
return s.replace(/[<>&"'\x00-\x1F\x7F\u0080-\uFFFF]/gu, (char) => {
|
|
293
|
+
switch (char) {
|
|
294
|
+
case '<':
|
|
295
|
+
return '<';
|
|
296
|
+
case '>':
|
|
297
|
+
return '>';
|
|
298
|
+
case '&':
|
|
299
|
+
return '&';
|
|
300
|
+
case '"':
|
|
301
|
+
return '"';
|
|
302
|
+
case "'":
|
|
303
|
+
return ''';
|
|
304
|
+
default:
|
|
305
|
+
return `&#${char.charCodeAt(0)};`;
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
}
|
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);
|
package/src/resolve.ts
CHANGED
|
@@ -74,6 +74,10 @@ export type Document = {
|
|
|
74
74
|
parsed: any;
|
|
75
75
|
};
|
|
76
76
|
|
|
77
|
+
export function makeRefId(absoluteRef: string, pointer: string) {
|
|
78
|
+
return absoluteRef + '::' + pointer;
|
|
79
|
+
}
|
|
80
|
+
|
|
77
81
|
export function makeDocumentFromString(sourceString: string, absoluteRef: string) {
|
|
78
82
|
const source = new Source(absoluteRef, sourceString);
|
|
79
83
|
try {
|
|
@@ -323,10 +327,8 @@ export async function resolveDocument(opts: {
|
|
|
323
327
|
document: undefined,
|
|
324
328
|
error: error,
|
|
325
329
|
};
|
|
326
|
-
|
|
327
|
-
const refId = document.source.absoluteRef + '::' + ref.$ref;
|
|
330
|
+
const refId = makeRefId(document.source.absoluteRef, ref.$ref);
|
|
328
331
|
resolvedRefMap.set(refId, resolvedRef);
|
|
329
|
-
|
|
330
332
|
return resolvedRef;
|
|
331
333
|
}
|
|
332
334
|
|
|
@@ -367,13 +369,11 @@ export async function resolveDocument(opts: {
|
|
|
367
369
|
|
|
368
370
|
resolvedRef.node = target;
|
|
369
371
|
resolvedRef.document = targetDoc;
|
|
370
|
-
const refId = document.source.absoluteRef
|
|
371
|
-
|
|
372
|
+
const refId = makeRefId(document.source.absoluteRef, ref.$ref);
|
|
372
373
|
if (resolvedRef.document && isRef(target)) {
|
|
373
374
|
resolvedRef = await followRef(resolvedRef.document, target, pushRef(refStack, target));
|
|
374
375
|
}
|
|
375
376
|
resolvedRefMap.set(refId, resolvedRef);
|
|
376
|
-
|
|
377
377
|
return { ...resolvedRef };
|
|
378
378
|
}
|
|
379
379
|
}
|
|
@@ -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', () => {
|