@@ -15,23 +15,25 @@ const key = 'API_KEY';
15
15
const id = '5aa0409b7cf527a93bfb44df' ;
16
16
const version = '1.0.0' ;
17
17
const exampleRefLocation = `${ config . get ( 'host' ) } /project/example-project/1.0.1/refs/ex` ;
18
- const successfulMessageBase = [
18
+ const successfulMessageBase = ( specPath , specType ) => [
19
19
'' ,
20
20
`\t${ chalk . green ( exampleRefLocation ) } ` ,
21
21
'' ,
22
- ' To update your OpenAPI or Swagger definition, run the following:' ,
22
+ ` To update your ${ specType } definition, run the following:` ,
23
23
'' ,
24
- `\t${ chalk . green ( `rdme openapi FILE --key=${ key } --id=1` ) } ` ,
24
+ `\t${ chalk . green ( `rdme openapi ${ specPath } --key=${ key } --id=1` ) } ` ,
25
25
] ;
26
- const successfulUpload = [
27
- "You've successfully uploaded a new OpenAPI file to your ReadMe project!" ,
28
- ...successfulMessageBase ,
29
- ] . join ( '\n' ) ;
30
-
31
- const successfulUpdate = [
32
- "You've successfully updated an OpenAPI file on your ReadMe project!" ,
33
- ...successfulMessageBase ,
34
- ] . join ( '\n' ) ;
26
+ const successfulUpload = ( specPath , specType = 'OpenAPI' ) =>
27
+ [
28
+ `You've successfully uploaded a new ${ specType } file to your ReadMe project!` ,
29
+ ...successfulMessageBase ( specPath , specType ) ,
30
+ ] . join ( '\n' ) ;
31
+
32
+ const successfulUpdate = ( specPath , specType = 'OpenAPI' ) =>
33
+ [
34
+ `You've successfully updated an existing ${ specType } file on your ReadMe project!` ,
35
+ ...successfulMessageBase ( specPath , specType ) ,
36
+ ] . join ( '\n' ) ;
35
37
36
38
const testWorkingDir = process . cwd ( ) ;
37
39
@@ -60,13 +62,13 @@ describe('rdme openapi', () => {
60
62
61
63
describe ( 'upload' , ( ) => {
62
64
it . each ( [
63
- [ 'Swagger 2.0' , 'json' , '2.0' ] ,
64
- [ 'Swagger 2.0' , 'yaml' , '2.0' ] ,
65
- [ 'OpenAPI 3.0' , 'json' , '3.0' ] ,
66
- [ 'OpenAPI 3.0' , 'yaml' , '3.0' ] ,
67
- [ 'OpenAPI 3.1' , 'json' , '3.1' ] ,
68
- [ 'OpenAPI 3.1' , 'yaml' , '3.1' ] ,
69
- ] ) ( 'should support uploading a %s definition (format: %s)' , async ( _ , format , specVersion ) => {
65
+ [ 'Swagger 2.0' , 'json' , '2.0' , 'Swagger' ] ,
66
+ [ 'Swagger 2.0' , 'yaml' , '2.0' , 'Swagger' ] ,
67
+ [ 'OpenAPI 3.0' , 'json' , '3.0' , 'OpenAPI' ] ,
68
+ [ 'OpenAPI 3.0' , 'yaml' , '3.0' , 'OpenAPI' ] ,
69
+ [ 'OpenAPI 3.1' , 'json' , '3.1' , 'OpenAPI' ] ,
70
+ [ 'OpenAPI 3.1' , 'yaml' , '3.1' , 'OpenAPI' ] ,
71
+ ] ) ( 'should support uploading a %s definition (format: %s)' , async ( _ , format , specVersion , type ) => {
70
72
const mock = getApiNock ( )
71
73
. get ( '/api/v1/api-specification' )
72
74
. basicAuth ( { user : key } )
@@ -78,13 +80,15 @@ describe('rdme openapi', () => {
78
80
. basicAuth ( { user : key } )
79
81
. reply ( 201 , { _id : 1 } , { location : exampleRefLocation } ) ;
80
82
83
+ const spec = require . resolve ( `@readme/oas-examples/${ specVersion } /${ format } /petstore.${ format } ` ) ;
84
+
81
85
await expect (
82
86
openapi . run ( {
83
- spec : require . resolve ( `@readme/oas-examples/ ${ specVersion } / ${ format } /petstore. ${ format } ` ) ,
87
+ spec,
84
88
key,
85
89
version,
86
90
} )
87
- ) . resolves . toBe ( successfulUpload ) ;
91
+ ) . resolves . toBe ( successfulUpload ( spec , type ) ) ;
88
92
89
93
expect ( console . info ) . toHaveBeenCalledTimes ( 0 ) ;
90
94
@@ -114,7 +118,7 @@ describe('rdme openapi', () => {
114
118
// to break.
115
119
fs . copyFileSync ( require . resolve ( '@readme/oas-examples/2.0/json/petstore.json' ) , './swagger.json' ) ;
116
120
117
- await expect ( openapi . run ( { key } ) ) . resolves . toBe ( successfulUpload ) ;
121
+ await expect ( openapi . run ( { key } ) ) . resolves . toBe ( successfulUpload ( 'swagger.json' , 'Swagger' ) ) ;
118
122
119
123
expect ( console . info ) . toHaveBeenCalledTimes ( 1 ) ;
120
124
@@ -128,26 +132,28 @@ describe('rdme openapi', () => {
128
132
129
133
describe ( 'updates / resyncs' , ( ) => {
130
134
it . each ( [
131
- [ 'Swagger 2.0' , 'json' , '2.0' ] ,
132
- [ 'Swagger 2.0' , 'yaml' , '2.0' ] ,
133
- [ 'OpenAPI 3.0' , 'json' , '3.0' ] ,
134
- [ 'OpenAPI 3.0' , 'yaml' , '3.0' ] ,
135
- [ 'OpenAPI 3.1' , 'json' , '3.1' ] ,
136
- [ 'OpenAPI 3.1' , 'yaml' , '3.1' ] ,
137
- ] ) ( 'should support updating a %s definition (format: %s)' , async ( _ , format , specVersion ) => {
135
+ [ 'Swagger 2.0' , 'json' , '2.0' , 'Swagger' ] ,
136
+ [ 'Swagger 2.0' , 'yaml' , '2.0' , 'Swagger' ] ,
137
+ [ 'OpenAPI 3.0' , 'json' , '3.0' , 'OpenAPI' ] ,
138
+ [ 'OpenAPI 3.0' , 'yaml' , '3.0' , 'OpenAPI' ] ,
139
+ [ 'OpenAPI 3.1' , 'json' , '3.1' , 'OpenAPI' ] ,
140
+ [ 'OpenAPI 3.1' , 'yaml' , '3.1' , 'OpenAPI' ] ,
141
+ ] ) ( 'should support updating a %s definition (format: %s)' , async ( _ , format , specVersion , type ) => {
138
142
const mock = getApiNock ( )
139
143
. put ( `/api/v1/api-specification/${ id } ` , body => body . match ( 'form-data; name="spec"' ) )
140
144
. basicAuth ( { user : key } )
141
145
. reply ( 201 , { _id : 1 } , { location : exampleRefLocation } ) ;
142
146
147
+ const spec = require . resolve ( `@readme/oas-examples/${ specVersion } /${ format } /petstore.${ format } ` ) ;
148
+
143
149
await expect (
144
150
openapi . run ( {
145
- spec : require . resolve ( `@readme/oas-examples/ ${ specVersion } / ${ format } /petstore. ${ format } ` ) ,
151
+ spec,
146
152
key,
147
153
id,
148
154
version,
149
155
} )
150
- ) . resolves . toBe ( successfulUpdate ) ;
156
+ ) . resolves . toBe ( successfulUpdate ( spec , type ) ) ;
151
157
152
158
return mock . done ( ) ;
153
159
} ) ;
@@ -158,9 +164,9 @@ describe('rdme openapi', () => {
158
164
. basicAuth ( { user : key } )
159
165
. reply ( 201 , { _id : 1 } , { location : exampleRefLocation } ) ;
160
166
161
- await expect (
162
- openapi . run ( { spec : require . resolve ( '@readme/oas-examples/3.1/json/petstore.json' ) , key , id , version } )
163
- ) . resolves . toBe ( successfulUpdate ) ;
167
+ const spec = require . resolve ( '@readme/oas-examples/3.1/json/petstore.json' ) ;
168
+
169
+ await expect ( openapi . run ( { spec , key , id , version } ) ) . resolves . toBe ( successfulUpdate ( spec ) ) ;
164
170
165
171
expect ( console . warn ) . toHaveBeenCalledTimes ( 1 ) ;
166
172
expect ( console . info ) . toHaveBeenCalledTimes ( 0 ) ;
@@ -225,9 +231,9 @@ describe('rdme openapi', () => {
225
231
. basicAuth ( { user : key } )
226
232
. reply ( 201 , { _id : 1 } , { location : exampleRefLocation } ) ;
227
233
228
- await expect (
229
- openapi . run ( { spec : require . resolve ( '@readme/oas-examples/2.0/json/petstore.json' ) , key } )
230
- ) . resolves . toBe ( successfulUpload ) ;
234
+ const spec = require . resolve ( '@readme/oas-examples/2.0/json/petstore.json' ) ;
235
+
236
+ await expect ( openapi . run ( { spec , key } ) ) . resolves . toBe ( successfulUpload ( spec , 'Swagger' ) ) ;
231
237
232
238
return mock . done ( ) ;
233
239
} ) ;
@@ -251,9 +257,9 @@ describe('rdme openapi', () => {
251
257
. basicAuth ( { user : key } )
252
258
. reply ( 201 , { _id : 1 } , { location : exampleRefLocation } ) ;
253
259
254
- await expect ( openapi . run ( { spec : './__tests__/__fixtures__/ref-oas/petstore.json' , key , version } ) ) . resolves . toBe (
255
- successfulUpload
256
- ) ;
260
+ const spec = './__tests__/__fixtures__/ref-oas/petstore.json' ;
261
+
262
+ await expect ( openapi . run ( { spec , key , version } ) ) . resolves . toBe ( successfulUpload ( spec ) ) ;
257
263
258
264
expect ( console . info ) . toHaveBeenCalledTimes ( 0 ) ;
259
265
@@ -280,14 +286,16 @@ describe('rdme openapi', () => {
280
286
. basicAuth ( { user : key } )
281
287
. reply ( 201 , { _id : 1 } , { location : exampleRefLocation } ) ;
282
288
289
+ const spec = 'petstore.json' ;
290
+
283
291
await expect (
284
292
openapi . run ( {
285
- spec : 'petstore.json' ,
293
+ spec,
286
294
key,
287
295
version,
288
296
workingDirectory : './__tests__/__fixtures__/relative-ref-oas' ,
289
297
} )
290
- ) . resolves . toBe ( successfulUpload ) ;
298
+ ) . resolves . toBe ( successfulUpload ( spec ) ) ;
291
299
292
300
expect ( console . info ) . toHaveBeenCalledTimes ( 0 ) ;
293
301
@@ -460,7 +468,7 @@ describe('rdme swagger', () => {
460
468
it ( 'should run `rdme openapi`' , ( ) => {
461
469
return expect ( swagger . run ( { spec : '' , key, id, version } ) ) . rejects . toThrow (
462
470
"We couldn't find an OpenAPI or Swagger definition.\n\n" +
463
- 'Run `rdme openapi ./ path/to/api/definition` to upload an existing definition or `rdme oas init` to create a fresh one! '
471
+ 'Please specify the path to your definition with `rdme openapi ./path/to/api/definition`. '
464
472
) ;
465
473
} ) ;
466
474
} ) ;
0 commit comments