Skip to content

Commit eb3dec7

Browse files
committed
partially resolve issue with circular $refs; fix wrong usage of patternProperties
1 parent 9bb8462 commit eb3dec7

File tree

9 files changed

+1986
-310
lines changed

9 files changed

+1986
-310
lines changed

applications/__tests__/__snapshots__/e2e.test.js.snap

Lines changed: 26 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ paths:
7676
- required
7777
additionalProperties:
7878
type: boolean
79-
patternProperties: {}
8079
Ref:
8180
type: number
8281
RefObject:
@@ -98,7 +97,6 @@ paths:
9897
- somekey
9998
- string
10099
additionalProperties: false
101-
patternProperties: {}
102100
ConditionalRef:
103101
type: object
104102
properties:
@@ -118,7 +116,6 @@ paths:
118116
- somekey
119117
- string
120118
additionalProperties: false
121-
patternProperties: {}
122119
required:
123120
- Simple
124121
- Or
@@ -127,7 +124,6 @@ paths:
127124
- Ref
128125
- RefObject
129126
additionalProperties: false
130-
patternProperties: {}
131127
components:
132128
x-types:
133129
Foo: number
@@ -202,7 +198,6 @@ paths:
202198
- string
203199
additionalProperties:
204200
type: boolean
205-
patternProperties: {}
206201
description: An array of boolean records with the fixed 'string' property.
207202
Conditional:
208203
type: string
@@ -226,7 +221,6 @@ paths:
226221
required:
227222
- ReferencedAgain
228223
additionalProperties: false
229-
patternProperties: {}
230224
description: A reference with nested references.
231225
required:
232226
- Plain
@@ -235,7 +229,6 @@ paths:
235229
- Referenced
236230
- NestedReferenced
237231
additionalProperties: false
238-
patternProperties: {}
239232
components:
240233
x-types:
241234
Referenced: string
@@ -284,7 +277,6 @@ paths:
284277
- az
285278
- vidh
286279
additionalProperties: false
287-
patternProperties: {}
288280
- type: object
289281
properties:
290282
bukh:
@@ -295,7 +287,6 @@ paths:
295287
- bukh
296288
- vidh
297289
additionalProperties: false
298-
patternProperties: {}
299290
components: {}
300291
"
301292
`;
@@ -374,7 +365,6 @@ paths:
374365
- WrongSchemaFormat
375366
- Referenced
376367
additionalProperties: false
377-
patternProperties: {}
378368
components:
379369
schemas:
380370
Foo:
@@ -454,7 +444,6 @@ paths:
454444
- foo
455445
- bar
456446
additionalProperties: false
457-
patternProperties: {}
458447
application/problems+json:
459448
x-type:
460449
WrongAndFormat:
@@ -481,7 +470,6 @@ paths:
481470
- Empty
482471
- ImpossibleArraysCombination
483472
additionalProperties: false
484-
patternProperties: {}
485473
components:
486474
x-types:
487475
CorrectAnd:
@@ -518,27 +506,12 @@ paths:
518506
schema:
519507
type: object
520508
properties:
521-
AFieldWithRegularRef:
522-
anyOf:
523-
- type: string
524-
- type: number
525-
- type: boolean
526-
- type: object
527-
- type: array
528-
- type: 'null'
529-
AFieldWithInlineRef:
530-
anyOf:
531-
- type: string
532-
- type: number
533-
- type: boolean
534-
- type: object
535-
- type: array
536-
- type: 'null'
509+
AFieldWithRegularRef: {}
510+
AFieldWithInlineRef: {}
537511
required:
538512
- AFieldWithRegularRef
539513
- AFieldWithInlineRef
540514
additionalProperties: false
541-
patternProperties: {}
542515
'201':
543516
description: A bare ref
544517
content:
@@ -547,14 +520,7 @@ paths:
547520
examples:
548521
Correct:
549522
value: Anything
550-
schema:
551-
anyOf:
552-
- type: string
553-
- type: number
554-
- type: boolean
555-
- type: object
556-
- type: array
557-
- type: 'null'
523+
schema: {}
558524
'202':
559525
description: A file reference
560526
content:
@@ -581,14 +547,7 @@ paths:
581547
value: anything
582548
schema:
583549
type: array
584-
items:
585-
anyOf:
586-
- type: string
587-
- type: number
588-
- type: boolean
589-
- type: object
590-
- type: array
591-
- type: 'null'
550+
items: {}
592551
'404':
593552
description: A wrong ref
594553
content:
@@ -601,18 +560,10 @@ paths:
601560
schema:
602561
type: object
603562
properties:
604-
AWrongRef:
605-
anyOf:
606-
- type: string
607-
- type: number
608-
- type: boolean
609-
- type: object
610-
- type: array
611-
- type: 'null'
563+
AWrongRef: {}
612564
required:
613565
- AWrongRef
614566
additionalProperties: false
615-
patternProperties: {}
616567
components:
617568
x-types:
618569
Foo: any
@@ -681,11 +632,9 @@ paths:
681632
- Number
682633
- Integer
683634
additionalProperties: false
684-
patternProperties: {}
685635
required:
686636
- Formats
687637
additionalProperties: false
688-
patternProperties: {}
689638
components: {}
690639
"
691640
`;
@@ -799,12 +748,10 @@ paths:
799748
required:
800749
- bukh
801750
additionalProperties: false
802-
patternProperties: {}
803751
required:
804752
- Or
805753
- ComplexOr
806754
additionalProperties: false
807-
patternProperties: {}
808755
components:
809756
x-types:
810757
Or:
@@ -982,48 +929,48 @@ referenced from applications/outputs/x-openapi-with-refs.yaml:13:15 at #/paths/~
982929
Error was generated by the no-invalid-media-type-examples rule.
983930
984931
985-
[4] applications/outputs/x-openapi-with-refs.yaml:73:26 at #/paths/~1test/get/responses/202/content/application~1json/examples/Incorrect/value
932+
[4] applications/outputs/x-openapi-with-refs.yaml:51:26 at #/paths/~1test/get/responses/202/content/application~1json/examples/Incorrect/value
986933
987934
Example value must conform to the schema: type must be number.
988935
989-
71 | value: 42
990-
72 | Incorrect:
991-
73 | value: false
936+
49 | value: 42
937+
50 | Incorrect:
938+
51 | value: false
992939
| ^^^^^
993-
74 | schema:
994-
75 | type: number
940+
52 | schema:
941+
53 | type: number
995942
996-
referenced from applications/outputs/x-openapi-with-refs.yaml:68:15 at #/paths/~1test/get/responses/202/content/application~1json
943+
referenced from applications/outputs/x-openapi-with-refs.yaml:46:15 at #/paths/~1test/get/responses/202/content/application~1json
997944
998945
Error was generated by the no-invalid-media-type-examples rule.
999946
1000947
1001-
[5] applications/outputs/x-openapi-with-refs.yaml:87:26 at #/paths/~1test/get/responses/203/content/application~1json/examples/Incorrect/value
948+
[5] applications/outputs/x-openapi-with-refs.yaml:65:26 at #/paths/~1test/get/responses/203/content/application~1json/examples/Incorrect/value
1002949
1003950
Example value must conform to the schema: type must be array.
1004951
1005-
85 | - anything
1006-
86 | Incorrect:
1007-
87 | value: anything
952+
63 | - anything
953+
64 | Incorrect:
954+
65 | value: anything
1008955
| ^^^^^^^^
1009-
88 | schema:
1010-
89 | type: array
956+
66 | schema:
957+
67 | type: array
1011958
1012-
referenced from applications/outputs/x-openapi-with-refs.yaml:80:15 at #/paths/~1test/get/responses/203/content/application~1json
959+
referenced from applications/outputs/x-openapi-with-refs.yaml:58:15 at #/paths/~1test/get/responses/203/content/application~1json
1013960
1014961
Error was generated by the no-invalid-media-type-examples rule.
1015962
1016963
1017-
[6] applications/outputs/x-openapi-with-refs.yaml:104:19 at #/paths/~1test/get/responses/404/content/application~1json/x-type/AWrongRef
964+
[6] applications/outputs/x-openapi-with-refs.yaml:75:19 at #/paths/~1test/get/responses/404/content/application~1json/x-type/AWrongRef
1018965
1019966
Can't resolve $ref: ENOENT: no such file or directory './applications/outputs/wrong-file.yaml'
1020967
1021-
102 | x-type:
1022-
103 | AWrongRef:
1023-
104 | $ref: wrong-file.yaml
1024-
| ^^^^^^^^^^^^^^^^^^^^^
1025-
105 | example:
1026-
106 | AWrongRef: Accepts anything
968+
73 | x-type:
969+
74 | AWrongRef:
970+
75 | $ref: wrong-file.yaml
971+
| ^^^^^^^^^^^^^^^^^^^^^
972+
76 | example:
973+
77 | AWrongRef: Accepts anything
1027974
1028975
Error was generated by the no-unresolved-refs rule.
1029976

applications/__tests__/adapter.test.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ describe('adapter', () => {
1313
type: 'object',
1414
properties: {string: {type: 'string', enum: ['boolean']}},
1515
additionalProperties: false,
16-
patternProperties: {},
1716
required: ['string'],
1817
})
1918
})
@@ -50,7 +49,6 @@ describe('adapter', () => {
5049
Conditional: {type: 'string'},
5150
},
5251
additionalProperties: false,
53-
patternProperties: {},
5452
required: ['Required'],
5553
})
5654
})
@@ -61,6 +59,22 @@ describe('adapter', () => {
6159
})
6260
})
6361

62+
test('arrays', () => {
63+
expect(translateXTypeToSchema({array: 'string'})).toEqual({
64+
type: 'array',
65+
items: {type: 'string'},
66+
})
67+
})
68+
69+
test('records', () => {
70+
expect(translateXTypeToSchema({string: 'number'})).toEqual({
71+
type: 'object',
72+
properties: {},
73+
additionalProperties: {type: 'number'},
74+
required: [],
75+
})
76+
})
77+
6478
test('string formats and modifiers', () => {
6579
expect(translateXTypeToSchema('string::date-time')).toEqual({
6680
type: 'string',

0 commit comments

Comments
 (0)