@redocly/openapi-core 1.25.8 → 1.25.10
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 +14 -0
- package/lib/config/config.js +1 -1
- package/lib/decorators/common/remove-x-internal.js +21 -9
- package/lib/resolve.js +4 -4
- package/lib/rules/oas3/component-name-unique.js +33 -22
- package/package.json +3 -3
- package/src/__tests__/lint.test.ts +0 -1
- package/src/benchmark/benches/rebilly.yaml +0 -3
- package/src/bundle.ts +6 -6
- package/src/config/config.ts +1 -1
- package/src/decorators/__tests__/remove-x-internal.test.ts +97 -0
- package/src/decorators/common/remove-x-internal.ts +28 -11
- package/src/resolve.ts +4 -4
- package/src/rules/oas3/__tests__/component-name-unique.test.ts +176 -33
- package/src/rules/oas3/component-name-unique.ts +37 -35
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -44,18 +44,31 @@ describe('Oas3 component-name-unique', () => {
|
|
|
44
44
|
{
|
|
45
45
|
"location": [
|
|
46
46
|
{
|
|
47
|
-
"pointer": "#/",
|
|
47
|
+
"pointer": "#/components/schemas/SomeSchema",
|
|
48
48
|
"reportOnKey": false,
|
|
49
49
|
"source": "/foobar.yaml",
|
|
50
50
|
},
|
|
51
51
|
],
|
|
52
|
-
"message": "Component 'schemas/SomeSchema' is not unique. It is defined at:
|
|
53
|
-
- /foobar.yaml#/components/schemas/SomeSchema
|
|
52
|
+
"message": "Component 'schemas/SomeSchema' is not unique. It is also defined at:
|
|
54
53
|
- /test.yaml#/components/schemas/SomeSchema",
|
|
55
54
|
"ruleId": "component-name-unique",
|
|
56
55
|
"severity": "error",
|
|
57
56
|
"suggest": [],
|
|
58
57
|
},
|
|
58
|
+
{
|
|
59
|
+
"location": [
|
|
60
|
+
{
|
|
61
|
+
"pointer": "#/components/schemas/SomeSchema",
|
|
62
|
+
"reportOnKey": false,
|
|
63
|
+
"source": "/test.yaml",
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
"message": "Component 'schemas/SomeSchema' is not unique. It is also defined at:
|
|
67
|
+
- /foobar.yaml#/components/schemas/SomeSchema",
|
|
68
|
+
"ruleId": "component-name-unique",
|
|
69
|
+
"severity": "error",
|
|
70
|
+
"suggest": [],
|
|
71
|
+
},
|
|
59
72
|
]
|
|
60
73
|
`);
|
|
61
74
|
});
|
|
@@ -99,18 +112,31 @@ describe('Oas3 component-name-unique', () => {
|
|
|
99
112
|
{
|
|
100
113
|
"location": [
|
|
101
114
|
{
|
|
102
|
-
"pointer": "#/",
|
|
115
|
+
"pointer": "#/components/schemas/SomeSchema",
|
|
103
116
|
"reportOnKey": false,
|
|
104
117
|
"source": "/foobar.yaml",
|
|
105
118
|
},
|
|
106
119
|
],
|
|
107
|
-
"message": "Component 'schemas/SomeSchema' is not unique. It is defined at:
|
|
108
|
-
- /foobar.yaml#/components/schemas/SomeSchema
|
|
120
|
+
"message": "Component 'schemas/SomeSchema' is not unique. It is also defined at:
|
|
109
121
|
- /SomeSchema.yaml",
|
|
110
122
|
"ruleId": "component-name-unique",
|
|
111
123
|
"severity": "error",
|
|
112
124
|
"suggest": [],
|
|
113
125
|
},
|
|
126
|
+
{
|
|
127
|
+
"location": [
|
|
128
|
+
{
|
|
129
|
+
"pointer": "#/",
|
|
130
|
+
"reportOnKey": false,
|
|
131
|
+
"source": "/SomeSchema.yaml",
|
|
132
|
+
},
|
|
133
|
+
],
|
|
134
|
+
"message": "Component 'schemas/SomeSchema' is not unique. It is also defined at:
|
|
135
|
+
- /foobar.yaml#/components/schemas/SomeSchema",
|
|
136
|
+
"ruleId": "component-name-unique",
|
|
137
|
+
"severity": "error",
|
|
138
|
+
"suggest": [],
|
|
139
|
+
},
|
|
114
140
|
]
|
|
115
141
|
`);
|
|
116
142
|
});
|
|
@@ -202,18 +228,31 @@ describe('Oas3 component-name-unique', () => {
|
|
|
202
228
|
{
|
|
203
229
|
"location": [
|
|
204
230
|
{
|
|
205
|
-
"pointer": "#/",
|
|
231
|
+
"pointer": "#/components/parameters/ParameterOne",
|
|
206
232
|
"reportOnKey": false,
|
|
207
233
|
"source": "/foobar.yaml",
|
|
208
234
|
},
|
|
209
235
|
],
|
|
210
|
-
"message": "Component 'parameters/ParameterOne' is not unique. It is defined at:
|
|
211
|
-
- /foobar.yaml#/components/parameters/ParameterOne
|
|
236
|
+
"message": "Component 'parameters/ParameterOne' is not unique. It is also defined at:
|
|
212
237
|
- /test.yaml#/components/parameters/ParameterOne",
|
|
213
238
|
"ruleId": "component-name-unique",
|
|
214
239
|
"severity": "error",
|
|
215
240
|
"suggest": [],
|
|
216
241
|
},
|
|
242
|
+
{
|
|
243
|
+
"location": [
|
|
244
|
+
{
|
|
245
|
+
"pointer": "#/components/parameters/ParameterOne",
|
|
246
|
+
"reportOnKey": false,
|
|
247
|
+
"source": "/test.yaml",
|
|
248
|
+
},
|
|
249
|
+
],
|
|
250
|
+
"message": "Component 'parameters/ParameterOne' is not unique. It is also defined at:
|
|
251
|
+
- /foobar.yaml#/components/parameters/ParameterOne",
|
|
252
|
+
"ruleId": "component-name-unique",
|
|
253
|
+
"severity": "error",
|
|
254
|
+
"suggest": [],
|
|
255
|
+
},
|
|
217
256
|
]
|
|
218
257
|
`);
|
|
219
258
|
});
|
|
@@ -261,18 +300,31 @@ describe('Oas3 component-name-unique', () => {
|
|
|
261
300
|
{
|
|
262
301
|
"location": [
|
|
263
302
|
{
|
|
264
|
-
"pointer": "#/",
|
|
303
|
+
"pointer": "#/components/parameters/ParameterOne",
|
|
265
304
|
"reportOnKey": false,
|
|
266
305
|
"source": "/foobar.yaml",
|
|
267
306
|
},
|
|
268
307
|
],
|
|
269
|
-
"message": "Component 'parameters/ParameterOne' is not unique. It is defined at:
|
|
270
|
-
- /foobar.yaml#/components/parameters/ParameterOne
|
|
308
|
+
"message": "Component 'parameters/ParameterOne' is not unique. It is also defined at:
|
|
271
309
|
- /ParameterOne.yaml",
|
|
272
310
|
"ruleId": "component-name-unique",
|
|
273
311
|
"severity": "error",
|
|
274
312
|
"suggest": [],
|
|
275
313
|
},
|
|
314
|
+
{
|
|
315
|
+
"location": [
|
|
316
|
+
{
|
|
317
|
+
"pointer": "#/",
|
|
318
|
+
"reportOnKey": false,
|
|
319
|
+
"source": "/ParameterOne.yaml",
|
|
320
|
+
},
|
|
321
|
+
],
|
|
322
|
+
"message": "Component 'parameters/ParameterOne' is not unique. It is also defined at:
|
|
323
|
+
- /foobar.yaml#/components/parameters/ParameterOne",
|
|
324
|
+
"ruleId": "component-name-unique",
|
|
325
|
+
"severity": "error",
|
|
326
|
+
"suggest": [],
|
|
327
|
+
},
|
|
276
328
|
]
|
|
277
329
|
`);
|
|
278
330
|
});
|
|
@@ -378,18 +430,31 @@ describe('Oas3 component-name-unique', () => {
|
|
|
378
430
|
{
|
|
379
431
|
"location": [
|
|
380
432
|
{
|
|
381
|
-
"pointer": "#/",
|
|
433
|
+
"pointer": "#/components/responses/SuccessResponse",
|
|
382
434
|
"reportOnKey": false,
|
|
383
435
|
"source": "/foobar.yaml",
|
|
384
436
|
},
|
|
385
437
|
],
|
|
386
|
-
"message": "Component 'responses/SuccessResponse' is not unique. It is defined at:
|
|
387
|
-
- /foobar.yaml#/components/responses/SuccessResponse
|
|
438
|
+
"message": "Component 'responses/SuccessResponse' is not unique. It is also defined at:
|
|
388
439
|
- /test.yaml#/components/responses/SuccessResponse",
|
|
389
440
|
"ruleId": "component-name-unique",
|
|
390
441
|
"severity": "error",
|
|
391
442
|
"suggest": [],
|
|
392
443
|
},
|
|
444
|
+
{
|
|
445
|
+
"location": [
|
|
446
|
+
{
|
|
447
|
+
"pointer": "#/components/responses/SuccessResponse",
|
|
448
|
+
"reportOnKey": false,
|
|
449
|
+
"source": "/test.yaml",
|
|
450
|
+
},
|
|
451
|
+
],
|
|
452
|
+
"message": "Component 'responses/SuccessResponse' is not unique. It is also defined at:
|
|
453
|
+
- /foobar.yaml#/components/responses/SuccessResponse",
|
|
454
|
+
"ruleId": "component-name-unique",
|
|
455
|
+
"severity": "error",
|
|
456
|
+
"suggest": [],
|
|
457
|
+
},
|
|
393
458
|
]
|
|
394
459
|
`);
|
|
395
460
|
});
|
|
@@ -444,18 +509,31 @@ describe('Oas3 component-name-unique', () => {
|
|
|
444
509
|
{
|
|
445
510
|
"location": [
|
|
446
511
|
{
|
|
447
|
-
"pointer": "#/",
|
|
512
|
+
"pointer": "#/components/responses/SuccessResponse",
|
|
448
513
|
"reportOnKey": false,
|
|
449
514
|
"source": "/foobar.yaml",
|
|
450
515
|
},
|
|
451
516
|
],
|
|
452
|
-
"message": "Component 'responses/SuccessResponse' is not unique. It is defined at:
|
|
453
|
-
- /foobar.yaml#/components/responses/SuccessResponse
|
|
517
|
+
"message": "Component 'responses/SuccessResponse' is not unique. It is also defined at:
|
|
454
518
|
- /SuccessResponse.yaml",
|
|
455
519
|
"ruleId": "component-name-unique",
|
|
456
520
|
"severity": "error",
|
|
457
521
|
"suggest": [],
|
|
458
522
|
},
|
|
523
|
+
{
|
|
524
|
+
"location": [
|
|
525
|
+
{
|
|
526
|
+
"pointer": "#/",
|
|
527
|
+
"reportOnKey": false,
|
|
528
|
+
"source": "/SuccessResponse.yaml",
|
|
529
|
+
},
|
|
530
|
+
],
|
|
531
|
+
"message": "Component 'responses/SuccessResponse' is not unique. It is also defined at:
|
|
532
|
+
- /foobar.yaml#/components/responses/SuccessResponse",
|
|
533
|
+
"ruleId": "component-name-unique",
|
|
534
|
+
"severity": "error",
|
|
535
|
+
"suggest": [],
|
|
536
|
+
},
|
|
459
537
|
]
|
|
460
538
|
`);
|
|
461
539
|
});
|
|
@@ -565,18 +643,31 @@ describe('Oas3 component-name-unique', () => {
|
|
|
565
643
|
{
|
|
566
644
|
"location": [
|
|
567
645
|
{
|
|
568
|
-
"pointer": "#/",
|
|
646
|
+
"pointer": "#/components/requestBodies/MyRequestBody",
|
|
569
647
|
"reportOnKey": false,
|
|
570
648
|
"source": "/foobar.yaml",
|
|
571
649
|
},
|
|
572
650
|
],
|
|
573
|
-
"message": "Component 'requestBodies/MyRequestBody' is not unique. It is defined at:
|
|
574
|
-
- /foobar.yaml#/components/requestBodies/MyRequestBody
|
|
651
|
+
"message": "Component 'requestBodies/MyRequestBody' is not unique. It is also defined at:
|
|
575
652
|
- /test.yaml#/components/requestBodies/MyRequestBody",
|
|
576
653
|
"ruleId": "component-name-unique",
|
|
577
654
|
"severity": "error",
|
|
578
655
|
"suggest": [],
|
|
579
656
|
},
|
|
657
|
+
{
|
|
658
|
+
"location": [
|
|
659
|
+
{
|
|
660
|
+
"pointer": "#/components/requestBodies/MyRequestBody",
|
|
661
|
+
"reportOnKey": false,
|
|
662
|
+
"source": "/test.yaml",
|
|
663
|
+
},
|
|
664
|
+
],
|
|
665
|
+
"message": "Component 'requestBodies/MyRequestBody' is not unique. It is also defined at:
|
|
666
|
+
- /foobar.yaml#/components/requestBodies/MyRequestBody",
|
|
667
|
+
"ruleId": "component-name-unique",
|
|
668
|
+
"severity": "error",
|
|
669
|
+
"suggest": [],
|
|
670
|
+
},
|
|
580
671
|
]
|
|
581
672
|
`);
|
|
582
673
|
});
|
|
@@ -632,18 +723,31 @@ describe('Oas3 component-name-unique', () => {
|
|
|
632
723
|
{
|
|
633
724
|
"location": [
|
|
634
725
|
{
|
|
635
|
-
"pointer": "#/",
|
|
726
|
+
"pointer": "#/components/requestBodies/MyRequestBody",
|
|
636
727
|
"reportOnKey": false,
|
|
637
728
|
"source": "/foobar.yaml",
|
|
638
729
|
},
|
|
639
730
|
],
|
|
640
|
-
"message": "Component 'requestBodies/MyRequestBody' is not unique. It is defined at:
|
|
641
|
-
- /foobar.yaml#/components/requestBodies/MyRequestBody
|
|
731
|
+
"message": "Component 'requestBodies/MyRequestBody' is not unique. It is also defined at:
|
|
642
732
|
- /MyRequestBody.yaml",
|
|
643
733
|
"ruleId": "component-name-unique",
|
|
644
734
|
"severity": "error",
|
|
645
735
|
"suggest": [],
|
|
646
736
|
},
|
|
737
|
+
{
|
|
738
|
+
"location": [
|
|
739
|
+
{
|
|
740
|
+
"pointer": "#/",
|
|
741
|
+
"reportOnKey": false,
|
|
742
|
+
"source": "/MyRequestBody.yaml",
|
|
743
|
+
},
|
|
744
|
+
],
|
|
745
|
+
"message": "Component 'requestBodies/MyRequestBody' is not unique. It is also defined at:
|
|
746
|
+
- /foobar.yaml#/components/requestBodies/MyRequestBody",
|
|
747
|
+
"ruleId": "component-name-unique",
|
|
748
|
+
"severity": "error",
|
|
749
|
+
"suggest": [],
|
|
750
|
+
},
|
|
647
751
|
]
|
|
648
752
|
`);
|
|
649
753
|
});
|
|
@@ -761,13 +865,12 @@ describe('Oas3 component-name-unique', () => {
|
|
|
761
865
|
{
|
|
762
866
|
"location": [
|
|
763
867
|
{
|
|
764
|
-
"pointer": "#/",
|
|
868
|
+
"pointer": "#/components/requestBodies/MyRequestBody",
|
|
765
869
|
"reportOnKey": false,
|
|
766
870
|
"source": "/foobar.yaml",
|
|
767
871
|
},
|
|
768
872
|
],
|
|
769
|
-
"message": "Component 'requestBodies/MyRequestBody' is not unique. It is defined at:
|
|
770
|
-
- /foobar.yaml#/components/requestBodies/MyRequestBody
|
|
873
|
+
"message": "Component 'requestBodies/MyRequestBody' is not unique. It is also defined at:
|
|
771
874
|
- /test.yaml#/components/requestBodies/MyRequestBody",
|
|
772
875
|
"ruleId": "component-name-unique",
|
|
773
876
|
"severity": "error",
|
|
@@ -776,18 +879,45 @@ describe('Oas3 component-name-unique', () => {
|
|
|
776
879
|
{
|
|
777
880
|
"location": [
|
|
778
881
|
{
|
|
779
|
-
"pointer": "#/",
|
|
882
|
+
"pointer": "#/components/requestBodies/MyRequestBody",
|
|
883
|
+
"reportOnKey": false,
|
|
884
|
+
"source": "/test.yaml",
|
|
885
|
+
},
|
|
886
|
+
],
|
|
887
|
+
"message": "Component 'requestBodies/MyRequestBody' is not unique. It is also defined at:
|
|
888
|
+
- /foobar.yaml#/components/requestBodies/MyRequestBody",
|
|
889
|
+
"ruleId": "component-name-unique",
|
|
890
|
+
"severity": "error",
|
|
891
|
+
"suggest": [],
|
|
892
|
+
},
|
|
893
|
+
{
|
|
894
|
+
"location": [
|
|
895
|
+
{
|
|
896
|
+
"pointer": "#/components/schemas/SomeSchema",
|
|
780
897
|
"reportOnKey": false,
|
|
781
898
|
"source": "/foobar.yaml",
|
|
782
899
|
},
|
|
783
900
|
],
|
|
784
|
-
"message": "Component 'schemas/SomeSchema' is not unique. It is defined at:
|
|
785
|
-
- /foobar.yaml#/components/schemas/SomeSchema
|
|
901
|
+
"message": "Component 'schemas/SomeSchema' is not unique. It is also defined at:
|
|
786
902
|
- /test.yaml#/components/schemas/SomeSchema",
|
|
787
903
|
"ruleId": "component-name-unique",
|
|
788
904
|
"severity": "error",
|
|
789
905
|
"suggest": [],
|
|
790
906
|
},
|
|
907
|
+
{
|
|
908
|
+
"location": [
|
|
909
|
+
{
|
|
910
|
+
"pointer": "#/components/schemas/SomeSchema",
|
|
911
|
+
"reportOnKey": false,
|
|
912
|
+
"source": "/test.yaml",
|
|
913
|
+
},
|
|
914
|
+
],
|
|
915
|
+
"message": "Component 'schemas/SomeSchema' is not unique. It is also defined at:
|
|
916
|
+
- /foobar.yaml#/components/schemas/SomeSchema",
|
|
917
|
+
"ruleId": "component-name-unique",
|
|
918
|
+
"severity": "error",
|
|
919
|
+
"suggest": [],
|
|
920
|
+
},
|
|
791
921
|
]
|
|
792
922
|
`);
|
|
793
923
|
});
|
|
@@ -804,18 +934,31 @@ describe('Oas3 component-name-unique', () => {
|
|
|
804
934
|
{
|
|
805
935
|
"location": [
|
|
806
936
|
{
|
|
807
|
-
"pointer": "#/",
|
|
937
|
+
"pointer": "#/components/requestBodies/MyRequestBody",
|
|
808
938
|
"reportOnKey": false,
|
|
809
939
|
"source": "/foobar.yaml",
|
|
810
940
|
},
|
|
811
941
|
],
|
|
812
|
-
"message": "Component 'requestBodies/MyRequestBody' is not unique. It is defined at:
|
|
813
|
-
- /foobar.yaml#/components/requestBodies/MyRequestBody
|
|
942
|
+
"message": "Component 'requestBodies/MyRequestBody' is not unique. It is also defined at:
|
|
814
943
|
- /test.yaml#/components/requestBodies/MyRequestBody",
|
|
815
944
|
"ruleId": "component-name-unique",
|
|
816
945
|
"severity": "error",
|
|
817
946
|
"suggest": [],
|
|
818
947
|
},
|
|
948
|
+
{
|
|
949
|
+
"location": [
|
|
950
|
+
{
|
|
951
|
+
"pointer": "#/components/requestBodies/MyRequestBody",
|
|
952
|
+
"reportOnKey": false,
|
|
953
|
+
"source": "/test.yaml",
|
|
954
|
+
},
|
|
955
|
+
],
|
|
956
|
+
"message": "Component 'requestBodies/MyRequestBody' is not unique. It is also defined at:
|
|
957
|
+
- /foobar.yaml#/components/requestBodies/MyRequestBody",
|
|
958
|
+
"ruleId": "component-name-unique",
|
|
959
|
+
"severity": "error",
|
|
960
|
+
"suggest": [],
|
|
961
|
+
},
|
|
819
962
|
]
|
|
820
963
|
`);
|
|
821
964
|
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Location } from '../../ref-utils';
|
|
1
2
|
import type { Problem, UserContext } from '../../walk';
|
|
2
3
|
import type { Oas2Rule, Oas3Rule, Oas3Visitor } from '../../visitors';
|
|
3
4
|
import type {
|
|
@@ -21,8 +22,10 @@ const TYPE_NAME_TO_OPTION_COMPONENT_NAME: { [key: string]: string } = {
|
|
|
21
22
|
[TYPE_NAME_REQUEST_BODY]: 'requestBodies',
|
|
22
23
|
};
|
|
23
24
|
|
|
25
|
+
type ComponentsMapValue = { absolutePointers: Set<string>; locations: Location[] };
|
|
26
|
+
|
|
24
27
|
export const ComponentNameUnique: Oas3Rule | Oas2Rule = (options) => {
|
|
25
|
-
const components = new Map<string,
|
|
28
|
+
const components = new Map<string, ComponentsMapValue>();
|
|
26
29
|
|
|
27
30
|
const typeNames: string[] = [];
|
|
28
31
|
if (options.schemas !== 'off') {
|
|
@@ -46,32 +49,31 @@ export const ComponentNameUnique: Oas3Rule | Oas2Rule = (options) => {
|
|
|
46
49
|
const resolvedRef = resolve(ref);
|
|
47
50
|
if (!resolvedRef.location) return;
|
|
48
51
|
|
|
49
|
-
addComponentFromAbsoluteLocation(
|
|
50
|
-
typeName,
|
|
51
|
-
resolvedRef.location.absolutePointer.toString()
|
|
52
|
-
);
|
|
52
|
+
addComponentFromAbsoluteLocation(typeName, resolvedRef.location);
|
|
53
53
|
}
|
|
54
54
|
},
|
|
55
55
|
},
|
|
56
56
|
Root: {
|
|
57
57
|
leave(root: Oas3Definition, ctx: UserContext) {
|
|
58
58
|
components.forEach((value, key, _) => {
|
|
59
|
-
if (value.size > 1) {
|
|
59
|
+
if (value.absolutePointers.size > 1) {
|
|
60
60
|
const component = getComponentFromKey(key);
|
|
61
61
|
const optionComponentName = getOptionComponentNameForTypeName(component.typeName);
|
|
62
|
-
const definitions = Array.from(value)
|
|
63
|
-
.map((v) => `- ${v}`)
|
|
64
|
-
.join('\n');
|
|
65
|
-
|
|
66
|
-
const problem: Problem = {
|
|
67
|
-
message: `Component '${optionComponentName}/${component.componentName}' is not unique. It is defined at:\n${definitions}`,
|
|
68
|
-
};
|
|
69
|
-
|
|
70
62
|
const componentSeverity = optionComponentName ? options[optionComponentName] : null;
|
|
71
|
-
|
|
72
|
-
|
|
63
|
+
for (const location of value.locations) {
|
|
64
|
+
const definitions = Array.from(value.absolutePointers)
|
|
65
|
+
.filter((v) => v !== location.absolutePointer.toString())
|
|
66
|
+
.map((v) => `- ${v}`)
|
|
67
|
+
.join('\n');
|
|
68
|
+
const problem: Problem = {
|
|
69
|
+
message: `Component '${optionComponentName}/${component.componentName}' is not unique. It is also defined at:\n${definitions}`,
|
|
70
|
+
location: location,
|
|
71
|
+
};
|
|
72
|
+
if (componentSeverity) {
|
|
73
|
+
problem.forceSeverity = componentSeverity;
|
|
74
|
+
}
|
|
75
|
+
ctx.report(problem);
|
|
73
76
|
}
|
|
74
|
-
ctx.report(problem);
|
|
75
77
|
}
|
|
76
78
|
});
|
|
77
79
|
},
|
|
@@ -81,7 +83,7 @@ export const ComponentNameUnique: Oas3Rule | Oas2Rule = (options) => {
|
|
|
81
83
|
if (options.schemas != 'off') {
|
|
82
84
|
rule.NamedSchemas = {
|
|
83
85
|
Schema(_: Oas3Schema, { location }: UserContext) {
|
|
84
|
-
addComponentFromAbsoluteLocation(TYPE_NAME_SCHEMA, location
|
|
86
|
+
addComponentFromAbsoluteLocation(TYPE_NAME_SCHEMA, location);
|
|
85
87
|
},
|
|
86
88
|
};
|
|
87
89
|
}
|
|
@@ -89,7 +91,7 @@ export const ComponentNameUnique: Oas3Rule | Oas2Rule = (options) => {
|
|
|
89
91
|
if (options.responses != 'off') {
|
|
90
92
|
rule.NamedResponses = {
|
|
91
93
|
Response(_: Oas3Response, { location }: UserContext) {
|
|
92
|
-
addComponentFromAbsoluteLocation(TYPE_NAME_RESPONSE, location
|
|
94
|
+
addComponentFromAbsoluteLocation(TYPE_NAME_RESPONSE, location);
|
|
93
95
|
},
|
|
94
96
|
};
|
|
95
97
|
}
|
|
@@ -97,7 +99,7 @@ export const ComponentNameUnique: Oas3Rule | Oas2Rule = (options) => {
|
|
|
97
99
|
if (options.parameters != 'off') {
|
|
98
100
|
rule.NamedParameters = {
|
|
99
101
|
Parameter(_: Oas3Parameter, { location }: UserContext) {
|
|
100
|
-
addComponentFromAbsoluteLocation(TYPE_NAME_PARAMETER, location
|
|
102
|
+
addComponentFromAbsoluteLocation(TYPE_NAME_PARAMETER, location);
|
|
101
103
|
},
|
|
102
104
|
};
|
|
103
105
|
}
|
|
@@ -105,10 +107,7 @@ export const ComponentNameUnique: Oas3Rule | Oas2Rule = (options) => {
|
|
|
105
107
|
if (options.requestBodies != 'off') {
|
|
106
108
|
rule.NamedRequestBodies = {
|
|
107
109
|
RequestBody(_: Oas3RequestBody, { location }: UserContext) {
|
|
108
|
-
addComponentFromAbsoluteLocation(
|
|
109
|
-
TYPE_NAME_REQUEST_BODY,
|
|
110
|
-
location.absolutePointer.toString()
|
|
111
|
-
);
|
|
110
|
+
addComponentFromAbsoluteLocation(TYPE_NAME_REQUEST_BODY, location);
|
|
112
111
|
},
|
|
113
112
|
};
|
|
114
113
|
}
|
|
@@ -127,20 +126,23 @@ export const ComponentNameUnique: Oas3Rule | Oas2Rule = (options) => {
|
|
|
127
126
|
return componentName;
|
|
128
127
|
}
|
|
129
128
|
|
|
130
|
-
function addFoundComponent(
|
|
131
|
-
typeName: string,
|
|
132
|
-
componentName: string,
|
|
133
|
-
absoluteLocation: string
|
|
134
|
-
): void {
|
|
129
|
+
function addFoundComponent(typeName: string, componentName: string, location: Location): void {
|
|
135
130
|
const key = getKeyForComponent(typeName, componentName);
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
131
|
+
const entry: ComponentsMapValue = components.get(key) ?? {
|
|
132
|
+
absolutePointers: new Set(),
|
|
133
|
+
locations: [],
|
|
134
|
+
};
|
|
135
|
+
const absoluteLocation = location.absolutePointer.toString();
|
|
136
|
+
if (!entry.absolutePointers.has(absoluteLocation)) {
|
|
137
|
+
entry.absolutePointers.add(absoluteLocation);
|
|
138
|
+
entry.locations.push(location);
|
|
139
|
+
}
|
|
140
|
+
components.set(key, entry);
|
|
139
141
|
}
|
|
140
142
|
|
|
141
|
-
function addComponentFromAbsoluteLocation(typeName: string,
|
|
142
|
-
const componentName = getComponentNameFromAbsoluteLocation(
|
|
143
|
-
addFoundComponent(typeName, componentName,
|
|
143
|
+
function addComponentFromAbsoluteLocation(typeName: string, location: Location): void {
|
|
144
|
+
const componentName = getComponentNameFromAbsoluteLocation(location.absolutePointer.toString());
|
|
145
|
+
addFoundComponent(typeName, componentName, location);
|
|
144
146
|
}
|
|
145
147
|
};
|
|
146
148
|
|