-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from darvid7/swagger-api-calls
Swagger api calls
- Loading branch information
Showing
4 changed files
with
34 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,3 +59,5 @@ typings/ | |
dist | ||
|
||
yarn.lock | ||
|
||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,29 @@ | ||
import { Specification } from 'model/Specification'; | ||
import fetch from 'node-fetch'; | ||
|
||
export async function generateSdk(spec: Specification): Promise<string> { | ||
const SWAGGER_CODEGEN_ENDPOINT = 'http://generator.swagger.io/api/gen/clients/'; | ||
const BAD_SPECIFICATION = 'Error: Bad specification'; | ||
|
||
export async function generateSdk(spec: Specification): Promise<any> { | ||
/* Generates an SDK for a specification | ||
* @param {Specification} spec - The specification object for which the sdk needs to be generated | ||
* @return {Promise<string>} - The URL from which the sdk can be downloaded | ||
*/ | ||
|
||
//TODO | ||
|
||
var sdkUrl: string = 'exampleSdkUrl.io'; | ||
|
||
return sdkUrl; | ||
// TODO: Get it working for .yaml files like below. | ||
// 'https:/OAI/OpenAPI-Specification/blob/master/examples/v2.0/yaml/uber.yaml' } | ||
console.log('generateSdk'); | ||
const body = { swaggerUrl: spec.path }; | ||
console.log(body); | ||
const response = await fetch(SWAGGER_CODEGEN_ENDPOINT + 'python', { | ||
method: 'POST', | ||
body: JSON.stringify(body), | ||
headers: { 'Content-Type': 'application/json' } | ||
}); | ||
const fulfilled = await response.json(); | ||
console.log(fulfilled); | ||
if (fulfilled.type == 'error') { | ||
return BAD_SPECIFICATION; | ||
} | ||
return fulfilled.link; | ||
} |