@@ -64,6 +64,9 @@ describe('Swagger', () => {
64
64
65
65
const res = await app . handle ( req ( '/v2/swagger' ) )
66
66
expect ( res . status ) . toBe ( 200 )
67
+
68
+ const resJson = await app . handle ( req ( '/v2/swagger/json' ) )
69
+ expect ( resJson . status ) . toBe ( 200 )
67
70
} )
68
71
69
72
it ( 'Swagger UI options' , async ( ) => {
@@ -75,56 +78,70 @@ describe('Swagger', () => {
75
78
} )
76
79
)
77
80
const res = await app . handle ( req ( '/swagger' ) ) . then ( ( x ) => x . text ( ) )
78
- const expected = `
79
- window.onload = () => {
80
- window.ui = SwaggerUIBundle({"url":"/swagger/json","dom_id":"#swagger-ui","persistAuthorization":true});
81
- };
82
- `
81
+ const expected = `"persistAuthorization":true`
82
+
83
83
expect ( res . trim ( ) . includes ( expected . trim ( ) ) ) . toBe ( true )
84
84
} )
85
85
86
86
it ( 'should not return content response when using Void type' , async ( ) => {
87
- const app = new Elysia ( ) . use (
88
- swagger ( ) )
89
- . get ( '/void' , ( ) => { } , {
90
- response : { 204 : t . Void ( {
87
+ const app = new Elysia ( ) . use ( swagger ( ) ) . get ( '/void' , ( ) => { } , {
88
+ response : {
89
+ 204 : t . Void ( {
91
90
description : 'Void response'
92
- } ) } } ) ;
91
+ } )
92
+ }
93
+ } )
93
94
94
95
const res = await app . handle ( req ( '/swagger/json' ) )
95
96
expect ( res . status ) . toBe ( 200 )
96
- const response = await res . json ( ) ;
97
- expect ( response . paths [ '/void' ] . get . responses [ '204' ] . description ) . toBe ( 'Void response' ) ;
98
- expect ( response . paths [ '/void' ] . get . responses [ '204' ] . content ) . toBeUndefined ( ) ;
97
+ const response = await res . json ( )
98
+ expect ( response . paths [ '/void' ] . get . responses [ '204' ] . description ) . toBe (
99
+ 'Void response'
100
+ )
101
+ expect (
102
+ response . paths [ '/void' ] . get . responses [ '204' ] . content
103
+ ) . toBeUndefined ( )
99
104
} )
100
105
101
106
it ( 'should not return content response when using Undefined type' , async ( ) => {
102
- const app = new Elysia ( ) . use (
103
- swagger ( ) )
107
+ const app = new Elysia ( )
108
+ . use ( swagger ( ) )
104
109
. get ( '/undefined' , ( ) => undefined , {
105
- response : { 204 : t . Undefined ( {
106
- description : 'Undefined response'
107
- } ) } } ) ;
110
+ response : {
111
+ 204 : t . Undefined ( {
112
+ description : 'Undefined response'
113
+ } )
114
+ }
115
+ } )
108
116
109
117
const res = await app . handle ( req ( '/swagger/json' ) )
110
118
expect ( res . status ) . toBe ( 200 )
111
- const response = await res . json ( ) ;
112
- expect ( response . paths [ '/undefined' ] . get . responses [ '204' ] . description ) . toBe ( 'Undefined response' ) ;
113
- expect ( response . paths [ '/undefined' ] . get . responses [ '204' ] . content ) . toBeUndefined ( ) ;
119
+ const response = await res . json ( )
120
+ expect (
121
+ response . paths [ '/undefined' ] . get . responses [ '204' ] . description
122
+ ) . toBe ( 'Undefined response' )
123
+ expect (
124
+ response . paths [ '/undefined' ] . get . responses [ '204' ] . content
125
+ ) . toBeUndefined ( )
114
126
} )
115
127
116
128
it ( 'should not return content response when using Null type' , async ( ) => {
117
- const app = new Elysia ( ) . use (
118
- swagger ( ) )
119
- . get ( '/null' , ( ) => null , {
120
- response : { 204 : t . Null ( {
129
+ const app = new Elysia ( ) . use ( swagger ( ) ) . get ( '/null' , ( ) => null , {
130
+ response : {
131
+ 204 : t . Null ( {
121
132
description : 'Null response'
122
- } ) } } ) ;
133
+ } )
134
+ }
135
+ } )
123
136
124
137
const res = await app . handle ( req ( '/swagger/json' ) )
125
138
expect ( res . status ) . toBe ( 200 )
126
- const response = await res . json ( ) ;
127
- expect ( response . paths [ '/null' ] . get . responses [ '204' ] . description ) . toBe ( 'Null response' ) ;
128
- expect ( response . paths [ '/null' ] . get . responses [ '204' ] . content ) . toBeUndefined ( ) ;
139
+ const response = await res . json ( )
140
+ expect ( response . paths [ '/null' ] . get . responses [ '204' ] . description ) . toBe (
141
+ 'Null response'
142
+ )
143
+ expect (
144
+ response . paths [ '/null' ] . get . responses [ '204' ] . content
145
+ ) . toBeUndefined ( )
129
146
} )
130
147
} )
0 commit comments