@@ -29,7 +29,7 @@ import { ApiMetadata } from '../../model/api/api-interfaces';
29
29
const UploadSpecButton = styled ( SettingsButton ) . attrs ( ( ) => ( {
30
30
type : 'submit'
31
31
} ) ) `
32
- grid-column: 1 / span 2 ;
32
+ grid-column: 1 / span 3 ;
33
33
` ;
34
34
35
35
const BaseUrlInput = styled ( TextInput ) `
@@ -82,7 +82,7 @@ export class ApiSettingsCard extends React.Component<
82
82
private uploadSpecButtonRef = React . createRef < HTMLButtonElement > ( ) ;
83
83
84
84
@observable
85
- private specUploadInProgress = false ;
85
+ private specProcessingInProgress = false ;
86
86
87
87
@observable
88
88
private enteredBaseUrl = "" ;
@@ -127,12 +127,12 @@ export class ApiSettingsCard extends React.Component<
127
127
{ ! this . selectedSpec
128
128
? < UploadSpecButton
129
129
type = 'submit' // Ensures we can show validation messages here
130
- onClick = { this . specUploadInProgress ? undefined : this . uploadSpec }
130
+ onClick = { this . specProcessingInProgress ? undefined : this . uploadSpec }
131
131
ref = { this . uploadSpecButtonRef }
132
132
>
133
- { this . specUploadInProgress
133
+ { this . specProcessingInProgress
134
134
? < Icon icon = { [ 'fas' , 'spinner' ] } spin />
135
- : "Load an OpenAPI spec"
135
+ : "Load an OpenAPI or Swagger spec"
136
136
}
137
137
</ UploadSpecButton >
138
138
: < >
@@ -148,20 +148,19 @@ export class ApiSettingsCard extends React.Component<
148
148
< Icon icon = { [ 'fas' , 'undo' ] } />
149
149
</ UndoButton >
150
150
</ Spec >
151
+ < AddButton
152
+ disabled = { ! this . selectedSpec || ! this . enteredBaseUrl || ! ! this . baseUrlError }
153
+ onClick = { this . saveApi }
154
+ >
155
+ < Icon icon = { [ 'fas' , 'save' ] } />
156
+ </ AddButton >
151
157
</ >
152
158
}
153
-
154
- < AddButton
155
- disabled = { ! this . selectedSpec || ! this . enteredBaseUrl || ! ! this . baseUrlError }
156
- onClick = { this . saveApi }
157
- >
158
- < Icon icon = { [ 'fas' , 'plus' ] } />
159
- </ AddButton >
160
159
</ ApiRows >
161
160
162
161
< SettingsExplanation >
163
- APIs added here will provide documentation and validation for all requests within their
164
- base URL.
162
+ APIs added here will provide documentation and validation for all matching
163
+ requests within their base URL.
165
164
</ SettingsExplanation >
166
165
< SettingsExplanation >
167
166
HTTP Toolkit also includes built-in specifications for 2600+ popular public APIs.
@@ -170,18 +169,21 @@ export class ApiSettingsCard extends React.Component<
170
169
}
171
170
172
171
uploadSpec = flow ( function * ( this : ApiSettingsCard ) {
173
- this . specUploadInProgress = true ;
174
172
updateValidationMessage ( this . uploadSpecButtonRef . current ! ) ;
175
173
176
174
try {
177
175
const file : string = yield uploadFile ( 'text' , [ '.json' , '.yaml' ] ) ;
178
176
if ( ! file ) return ;
179
177
178
+ this . specProcessingInProgress = true ;
180
179
let content : any = yield attempt ( ( ) =>
181
180
JSON . parse ( file )
182
181
) . catch ( ( ) =>
183
182
yaml . parse ( file )
184
- ) ;
183
+ ) . catch ( ( e ) => {
184
+ console . warn ( 'OpenAPI spec parsing error:' , e ) ;
185
+ throw new Error ( 'File could not be parsed as either YAML or JSON' )
186
+ } ) ;
185
187
186
188
let openApiSpec : OpenAPIObject ;
187
189
@@ -208,7 +210,9 @@ export class ApiSettingsCard extends React.Component<
208
210
}
209
211
210
212
// Build the API just to test that we *can* (we'll rebuild with the base URL later)
211
- yield buildApiMetadataAsync ( openApiSpec ) ;
213
+ yield buildApiMetadataAsync ( openApiSpec , [
214
+ 'api.build.example' // Need a default base here in case the spec has no servers
215
+ ] ) ;
212
216
213
217
this . selectedSpec = openApiSpec ;
214
218
@@ -229,7 +233,7 @@ export class ApiSettingsCard extends React.Component<
229
233
console . log ( e ) ;
230
234
updateValidationMessage ( this . uploadSpecButtonRef . current ! , asError ( e ) . message ) ;
231
235
} finally {
232
- this . specUploadInProgress = false ;
236
+ this . specProcessingInProgress = false ;
233
237
}
234
238
} ) . bind ( this ) ;
235
239
0 commit comments