@redocly/openapi-core 1.10.6 → 1.12.0
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/config-resolvers.d.ts +5 -1
- package/lib/config/config-resolvers.js +4 -4
- package/lib/config/load.d.ts +1 -0
- package/lib/config/load.js +7 -2
- package/lib/config/utils.js +1 -1
- package/lib/decorators/oas2/remove-unused-components.js +36 -22
- package/lib/decorators/oas3/remove-unused-components.js +34 -19
- package/lib/format/format.d.ts +1 -1
- package/lib/format/format.js +57 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +3 -2
- package/lib/rules/common/assertions/utils.js +2 -2
- package/lib/rules/oas3/no-invalid-media-type-examples.js +3 -0
- package/lib/utils.d.ts +1 -0
- package/lib/utils.js +7 -1
- package/package.json +2 -2
- package/src/__tests__/format.test.ts +34 -0
- package/src/bundle.ts +1 -1
- package/src/config/__tests__/config-resolvers.test.ts +4 -4
- package/src/config/__tests__/fixtures/load-external.yaml +2 -0
- package/src/config/__tests__/load.test.ts +14 -0
- package/src/config/config-resolvers.ts +13 -7
- package/src/config/load.ts +13 -4
- package/src/config/utils.ts +1 -1
- package/src/decorators/oas2/__tests__/remove-unused-components.test.ts +74 -1
- package/src/decorators/oas2/remove-unused-components.ts +46 -24
- package/src/decorators/oas3/__tests__/remove-unused-components.test.ts +142 -0
- package/src/decorators/oas3/remove-unused-components.ts +45 -20
- package/src/format/format.ts +62 -1
- package/src/index.ts +8 -1
- package/src/rules/common/assertions/utils.ts +2 -2
- package/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts +145 -0
- package/src/rules/oas3/no-invalid-media-type-examples.ts +3 -0
- package/src/utils.ts +4 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -470,4 +470,149 @@ describe('no-invalid-media-type-examples', () => {
|
|
|
470
470
|
|
|
471
471
|
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`[]`);
|
|
472
472
|
});
|
|
473
|
+
|
|
474
|
+
it('should not report if only externalValue is set', async () => {
|
|
475
|
+
const document = parseYamlToDocument(
|
|
476
|
+
outdent`
|
|
477
|
+
openapi: 3.0.0
|
|
478
|
+
paths:
|
|
479
|
+
/pet:
|
|
480
|
+
get:
|
|
481
|
+
responses:
|
|
482
|
+
'200':
|
|
483
|
+
content:
|
|
484
|
+
application/json:
|
|
485
|
+
schema:
|
|
486
|
+
type: object
|
|
487
|
+
properties:
|
|
488
|
+
a:
|
|
489
|
+
type: string
|
|
490
|
+
b:
|
|
491
|
+
type: number
|
|
492
|
+
examples:
|
|
493
|
+
first:
|
|
494
|
+
externalValue: "https://example.com/example.json"
|
|
495
|
+
`,
|
|
496
|
+
'foobar.yaml'
|
|
497
|
+
);
|
|
498
|
+
|
|
499
|
+
const results = await lintDocument({
|
|
500
|
+
externalRefResolver: new BaseResolver(),
|
|
501
|
+
document,
|
|
502
|
+
config: await makeConfig({ 'no-invalid-media-type-examples': 'error' }),
|
|
503
|
+
});
|
|
504
|
+
|
|
505
|
+
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`[]`);
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
it('should not report if value is valid and externalValue is also set', async () => {
|
|
509
|
+
const document = parseYamlToDocument(
|
|
510
|
+
outdent`
|
|
511
|
+
openapi: 3.0.0
|
|
512
|
+
paths:
|
|
513
|
+
/pet:
|
|
514
|
+
get:
|
|
515
|
+
responses:
|
|
516
|
+
'200':
|
|
517
|
+
content:
|
|
518
|
+
application/json:
|
|
519
|
+
schema:
|
|
520
|
+
type: object
|
|
521
|
+
properties:
|
|
522
|
+
a:
|
|
523
|
+
type: string
|
|
524
|
+
b:
|
|
525
|
+
type: number
|
|
526
|
+
examples:
|
|
527
|
+
first:
|
|
528
|
+
externalValue: "https://example.com/example.json"
|
|
529
|
+
value:
|
|
530
|
+
a: "A"
|
|
531
|
+
b: 0
|
|
532
|
+
`,
|
|
533
|
+
'foobar.yaml'
|
|
534
|
+
);
|
|
535
|
+
|
|
536
|
+
const results = await lintDocument({
|
|
537
|
+
externalRefResolver: new BaseResolver(),
|
|
538
|
+
document,
|
|
539
|
+
config: await makeConfig({ 'no-invalid-media-type-examples': 'error' }),
|
|
540
|
+
});
|
|
541
|
+
|
|
542
|
+
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`[]`);
|
|
543
|
+
});
|
|
544
|
+
|
|
545
|
+
it('should report invalid value when externalValue is also set', async () => {
|
|
546
|
+
const document = parseYamlToDocument(
|
|
547
|
+
outdent`
|
|
548
|
+
openapi: 3.0.0
|
|
549
|
+
paths:
|
|
550
|
+
/pet:
|
|
551
|
+
get:
|
|
552
|
+
responses:
|
|
553
|
+
'200':
|
|
554
|
+
content:
|
|
555
|
+
application/json:
|
|
556
|
+
schema:
|
|
557
|
+
type: object
|
|
558
|
+
properties:
|
|
559
|
+
a:
|
|
560
|
+
type: string
|
|
561
|
+
b:
|
|
562
|
+
type: number
|
|
563
|
+
examples:
|
|
564
|
+
first:
|
|
565
|
+
externalValue: "https://example.com/example.json"
|
|
566
|
+
value:
|
|
567
|
+
a: 0
|
|
568
|
+
b: "0"
|
|
569
|
+
`,
|
|
570
|
+
'foobar.yaml'
|
|
571
|
+
);
|
|
572
|
+
|
|
573
|
+
const results = await lintDocument({
|
|
574
|
+
externalRefResolver: new BaseResolver(),
|
|
575
|
+
document,
|
|
576
|
+
config: await makeConfig({ 'no-invalid-media-type-examples': 'error' }),
|
|
577
|
+
});
|
|
578
|
+
|
|
579
|
+
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
|
|
580
|
+
[
|
|
581
|
+
{
|
|
582
|
+
"from": {
|
|
583
|
+
"pointer": "#/paths/~1pet/get/responses/200/content/application~1json",
|
|
584
|
+
"source": "foobar.yaml",
|
|
585
|
+
},
|
|
586
|
+
"location": [
|
|
587
|
+
{
|
|
588
|
+
"pointer": "#/paths/~1pet/get/responses/200/content/application~1json/examples/first/value/a",
|
|
589
|
+
"reportOnKey": false,
|
|
590
|
+
"source": "foobar.yaml",
|
|
591
|
+
},
|
|
592
|
+
],
|
|
593
|
+
"message": "Example value must conform to the schema: \`a\` property type must be string.",
|
|
594
|
+
"ruleId": "no-invalid-media-type-examples",
|
|
595
|
+
"severity": "error",
|
|
596
|
+
"suggest": [],
|
|
597
|
+
},
|
|
598
|
+
{
|
|
599
|
+
"from": {
|
|
600
|
+
"pointer": "#/paths/~1pet/get/responses/200/content/application~1json",
|
|
601
|
+
"source": "foobar.yaml",
|
|
602
|
+
},
|
|
603
|
+
"location": [
|
|
604
|
+
{
|
|
605
|
+
"pointer": "#/paths/~1pet/get/responses/200/content/application~1json/examples/first/value/b",
|
|
606
|
+
"reportOnKey": false,
|
|
607
|
+
"source": "foobar.yaml",
|
|
608
|
+
},
|
|
609
|
+
],
|
|
610
|
+
"message": "Example value must conform to the schema: \`b\` property type must be number.",
|
|
611
|
+
"ruleId": "no-invalid-media-type-examples",
|
|
612
|
+
"severity": "error",
|
|
613
|
+
"suggest": [],
|
|
614
|
+
},
|
|
615
|
+
]
|
|
616
|
+
`);
|
|
617
|
+
});
|
|
473
618
|
});
|
|
@@ -35,6 +35,9 @@ export const ValidContentExamples: Oas3Rule = (opts) => {
|
|
|
35
35
|
location = isMultiple ? resolved.location.child('value') : resolved.location;
|
|
36
36
|
example = resolved.node;
|
|
37
37
|
}
|
|
38
|
+
if (isMultiple && typeof example.value === 'undefined') {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
38
41
|
validateExample(
|
|
39
42
|
isMultiple ? example.value : example,
|
|
40
43
|
mediaType.schema!,
|
package/src/utils.ts
CHANGED
|
@@ -271,6 +271,10 @@ export function nextTick() {
|
|
|
271
271
|
});
|
|
272
272
|
}
|
|
273
273
|
|
|
274
|
+
export async function pause(ms: number): Promise<void> {
|
|
275
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
276
|
+
}
|
|
277
|
+
|
|
274
278
|
function getUpdatedFieldName(updatedField: string, updatedObject?: string) {
|
|
275
279
|
return `${typeof updatedObject !== 'undefined' ? `${updatedObject}.` : ''}${updatedField}`;
|
|
276
280
|
}
|