Skip to content

Commit

Permalink
feat(loadSpec): change the endpoint called by loadSpec (#356)
Browse files Browse the repository at this point in the history
According to this Kubernetes doc:
https://kubernetes.io/docs/concepts/overview/kubernetes-api/#openapi-and-swagger-definitions

The `/swagger*` endpoints have been deprecated starting with v1.10.

This commit changes `loadSpec` to address this:
1. Initially attempts to contact `/openapi/v2` with `Accept: application/json` in order
   to get the swagger file via the new URL
2. If that fails with a 404, attempts to contact `swagger.json` to support clusters which
   do not have the new endpoint
  • Loading branch information
ajpauwels authored and silasbw committed Nov 12, 2018
1 parent 83197bb commit 8a5f5cb
Show file tree
Hide file tree
Showing 3 changed files with 954 additions and 854 deletions.
21 changes: 15 additions & 6 deletions lib/swagger-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,22 @@ class Root extends Component {
*/
loadSpec() {
return new Promise((resolve, reject) => {
this.http.request('GET', { path: '/swagger.json' }, (err, res) => {
if (err) return reject(err);
if (res.statusCode !== 200) {
return reject(new Error(`Failed to get swagger.json: ${res.statusCode}`));
return this.http.request('GET', { path: '/openapi/v2' }, (modernGETErr, modernGETRes) => {
if (modernGETErr) return reject(modernGETErr);
if (modernGETRes.statusCode === 404) {
return this.http.request('GET', { path: '/swagger.json' }, (legacyGETErr, legacyGETRes) => {
if (legacyGETErr) return reject(legacyGETErr);
if (legacyGETRes.statusCode !== 200) {
return reject(new Error(`Failed to get /swagger.json: ${legacyGETRes.statusCode}`));
}
this._addSpec(legacyGETRes.body);
return resolve(this);
});
} else if (modernGETRes.statusCode !== 200) {
return reject(new Error(`Failed to get /openapi/v2: ${modernGETRes.statusCode}`));
}
this._addSpec(res.body);
resolve(this);
this._addSpec(modernGETRes.body);
return resolve(this);
});
});
}
Expand Down
Loading

0 comments on commit 8a5f5cb

Please sign in to comment.