@@ -8,17 +8,17 @@ describe('@apidevtools/swagger-parser', () => {
8
8
info : { title : 'Test API' , version : '1.0.0' } ,
9
9
paths : { } ,
10
10
definitions : {
11
- 'io.k8s.apimachinery.pkg.apis.meta. v1.ObjectMeta ' : {
11
+ 'io.k8s.api.apps. v1.Deployment ' : {
12
12
type : 'object' ,
13
13
properties : {
14
- name : { type : 'string' } ,
15
- namespace : { type : 'string' } ,
14
+ metadata : { $ref : '#/definitions/io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta' } ,
16
15
} ,
17
16
} ,
18
- 'io.k8s.api.apps. v1.Deployment ' : {
17
+ 'io.k8s.apimachinery.pkg.apis.meta. v1.ObjectMeta ' : {
19
18
type : 'object' ,
20
19
properties : {
21
- metadata : { $ref : '#/definitions/io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta' } ,
20
+ name : { type : 'string' } ,
21
+ namespace : { type : 'string' } ,
22
22
} ,
23
23
} ,
24
24
} ,
@@ -35,16 +35,34 @@ describe('@apidevtools/swagger-parser', () => {
35
35
} ) ;
36
36
} ) ;
37
37
38
+ it ( 'should throw an error for invalid $ref references' , async ( ) => {
39
+ const doc : OpenAPIV2 . Document = {
40
+ swagger : '2.0' ,
41
+ info : { title : 'Test API' , version : '1.0.0' } ,
42
+ paths : { } ,
43
+ definitions : {
44
+ 'io.k8s.api.core.v1.Pod' : {
45
+ type : 'object' ,
46
+ properties : {
47
+ metadata : { $ref : '#/definitions/NonExistentRef' } ,
48
+ } ,
49
+ } ,
50
+ } ,
51
+ } ;
52
+
53
+ await expect ( Swagger . dereference ( doc ) ) . rejects . toThrow ( / T o k e n " N o n E x i s t e n t R e f " / ) ;
54
+ } ) ;
55
+
38
56
it ( 'should handle deeply nested $ref references' , async ( ) => {
39
57
const doc : OpenAPIV2 . Document = {
40
58
swagger : '2.0' ,
41
59
info : { title : 'Test API' , version : '1.0.0' } ,
42
60
paths : { } ,
43
61
definitions : {
44
- 'io.k8s.api.core.v1.Container ' : {
62
+ 'io.k8s.api.core.v1.Pod ' : {
45
63
type : 'object' ,
46
64
properties : {
47
- image : { type : 'string ' } ,
65
+ spec : { $ref : '#/definitions/io.k8s.api.core.v1.PodSpec ' } ,
48
66
} ,
49
67
} ,
50
68
'io.k8s.api.core.v1.PodSpec' : {
@@ -56,10 +74,10 @@ describe('@apidevtools/swagger-parser', () => {
56
74
} ,
57
75
} ,
58
76
} ,
59
- 'io.k8s.api.core.v1.Pod ' : {
77
+ 'io.k8s.api.core.v1.Container ' : {
60
78
type : 'object' ,
61
79
properties : {
62
- spec : { $ref : '#/definitions/io.k8s.api.core.v1.PodSpec ' } ,
80
+ image : { type : 'string ' } ,
63
81
} ,
64
82
} ,
65
83
} ,
@@ -78,48 +96,37 @@ describe('@apidevtools/swagger-parser', () => {
78
96
} ) ;
79
97
} ) ;
80
98
81
- it ( 'should throw an error for invalid $ref references' , async ( ) => {
82
- const doc : OpenAPIV2 . Document = {
83
- swagger : '2.0' ,
84
- info : { title : 'Test API' , version : '1.0.0' } ,
85
- paths : { } ,
86
- definitions : {
87
- 'io.k8s.api.core.v1.Pod' : {
88
- type : 'object' ,
89
- properties : {
90
- metadata : { $ref : '#/definitions/NonExistentRef' } ,
91
- } ,
92
- } ,
93
- } ,
94
- } ;
95
-
96
- await expect ( Swagger . dereference ( doc ) ) . rejects . toThrow ( / T o k e n " N o n E x i s t e n t R e f " / ) ;
97
- } ) ;
98
-
99
99
it ( 'should handle circular references' , async ( ) => {
100
100
const doc : OpenAPIV2 . Document = {
101
101
swagger : '2.0' ,
102
102
info : { title : 'Test API' , version : '1.0.0' } ,
103
103
paths : { } ,
104
104
definitions : {
105
- 'io.k8s.api.core.v1.Container ' : {
105
+ 'io.k8s.api.core.v1.Pod ' : {
106
106
type : 'object' ,
107
107
properties : {
108
- pod : { $ref : '#/definitions/io.k8s.api.core.v1.Pod' } ,
108
+ metadata : {
109
+ $ref : '#/definitions/io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta' ,
110
+ } ,
109
111
} ,
110
112
} ,
111
- 'io.k8s.api.core. v1.Pod ' : {
113
+ 'io.k8s.apimachinery.pkg.apis.meta. v1.ObjectMeta ' : {
112
114
type : 'object' ,
113
115
properties : {
114
- container : { $ref : '#/definitions/io.k8s.api.core.v1.Container' } ,
116
+ ownerReferences : {
117
+ $ref : '#/definitions/io.k8s.api.core.v1.Pod' ,
118
+ } ,
115
119
} ,
116
120
} ,
117
121
} ,
118
122
} ;
119
123
120
124
const result = ( await Swagger . dereference ( doc ) ) as OpenAPIV2 . Document ;
121
125
122
- expect ( result . definitions ?. [ 'io.k8s.api.core.v1.Pod' ] . properties ?. container ) . toBeDefined ( ) ;
123
- expect ( result . definitions ?. [ 'io.k8s.api.core.v1.Container' ] . properties ?. pod ) . toBeDefined ( ) ;
126
+ expect ( result . definitions ?. [ 'io.k8s.api.core.v1.Pod' ] . properties ?. metadata ) . toBeDefined ( ) ;
127
+ expect (
128
+ result . definitions ?. [ 'io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta' ] . properties
129
+ ?. ownerReferences
130
+ ) . toBeDefined ( ) ;
124
131
} ) ;
125
132
} ) ;
0 commit comments