@@ -38,6 +38,17 @@ describe('http', () => {
3838 }
3939 }
4040
41+ if ( req . headers [ 'x-setcontenttype' ] ) {
42+ console . log ( 'here come dat header' , req . headers )
43+ // Allow the test to explicitly set (or unset) a content type
44+ if ( req . headers [ 'x-setcontenttype' ] === 'none' ) {
45+ res . removeHeader ( 'Content-Type' )
46+ }
47+ else {
48+ res . setHeader ( 'Content-Type' , req . headers [ 'x-setcontenttype' ] )
49+ }
50+ }
51+
4152 fs . exists ( filename , function ( exists ) {
4253 if ( exists ) {
4354 const fileStream = fs . createReadStream ( filename )
@@ -61,7 +72,25 @@ describe('http', () => {
6172 afterEach ( function ( ) {
6273 } )
6374
64- it . skip ( 'should get the petstore api and build it' , ( done ) => {
75+ it ( 'should get the JSON petstore api and build it' , ( done ) => {
76+ Swagger ( 'http://localhost:8000/petstore.json' )
77+ . then ( ( client ) => {
78+ expect ( client ) . toExist ( )
79+
80+ // we have 3 tags
81+ expect ( Object . keys ( client . apis ) . length ) . toBe ( 3 )
82+
83+ // the pet tag exists
84+ expect ( client . apis . pet ) . toExist ( )
85+
86+ // the get pet operation
87+ expect ( client . apis . pet . getPetById ) . toExist ( )
88+
89+ done ( )
90+ } )
91+ } )
92+
93+ it ( 'should get the YAML petstore api and build it' , ( done ) => {
6594 Swagger ( 'http://localhost:8000/petstore.json' )
6695 . then ( ( client ) => {
6796 expect ( client ) . toExist ( )
@@ -79,6 +108,54 @@ describe('http', () => {
79108 } )
80109 } )
81110
111+ it ( 'should get the JSON petstore api and build it when response lacks a `Content-Type`' , ( done ) => {
112+ Swagger ( 'http://localhost:8000/petstore.json' , {
113+ requestInterceptor : ( req ) => {
114+ req . headers [ 'X-SetContentType' ] = 'none'
115+ return req
116+ }
117+ } )
118+ . then ( ( client ) => {
119+ expect ( client ) . toExist ( )
120+
121+ // we have 3 tags
122+ expect ( Object . keys ( client . apis ) . length ) . toBe ( 3 )
123+
124+ // the pet tag exists
125+ expect ( client . apis . pet ) . toExist ( )
126+
127+ // the get pet operation
128+ expect ( client . apis . pet . getPetById ) . toExist ( )
129+
130+ done ( )
131+ } )
132+ . catch ( err => done ( err ) )
133+ } )
134+
135+ it ( 'should get the YAML petstore api and build it when response lacks a `Content-Type`' , ( done ) => {
136+ Swagger ( 'http://localhost:8000/petstore.yaml' , {
137+ requestInterceptor : ( req ) => {
138+ req . headers [ 'X-SetContentType' ] = 'none'
139+ return req
140+ }
141+ } )
142+ . then ( ( client ) => {
143+ expect ( client ) . toExist ( )
144+
145+ // we have 3 tags
146+ expect ( Object . keys ( client . apis ) . length ) . toBe ( 3 )
147+
148+ // the pet tag exists
149+ expect ( client . apis . pet ) . toExist ( )
150+
151+ // the get pet operation
152+ expect ( client . apis . pet . getPetById ) . toExist ( )
153+
154+ done ( )
155+ } )
156+ . catch ( err => done ( err ) )
157+ } )
158+
82159 /**
83160 * See https://github.com/swagger-api/swagger-js/issues/1005
84161 */
0 commit comments