Skip to content

Commit

Permalink
Merge pull request #17 from darvid7/swagger-api-calls
Browse files Browse the repository at this point in the history
Swagger api calls
  • Loading branch information
darvid7 authored Apr 24, 2018
2 parents 4a10554 + 6ce5d02 commit 94adf81
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,5 @@ typings/
dist

yarn.lock

.idea
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "swagger-platform",
"version": "1.0.0",
"repository": "https:/developersteve/swagger-platform.git",
"repository": "https:/telstra/swagger-platform",
"license": "Apache-2.0",
"private": false,
"scripts": {
Expand Down
10 changes: 10 additions & 0 deletions src/backend/specifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ const specifications: Specification[] = [
sdks: [
{ id: 20, name: 'FORTRAN', latestVersion: 'alpha', buildStatus: BuildStatus.FAIL }
]
},
{
id: 2,
title: 'Swagger API Example Uber',
description: 'A test API for Uber',
path: 'https://esi.tech.ccp.is/_latest/swagger.json',
sdks: [
{ id: 1, name: 'Python', latestVersion: 'alpha', buildStatus: BuildStatus.SUCCESS },
{ id: 2, name: 'java', latestVersion: 'alpha', buildStatus: BuildStatus.SUCCESS }
]
}
];

Expand Down
27 changes: 21 additions & 6 deletions src/client/sdkGeneration.tsx
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;
}

0 comments on commit 94adf81

Please sign in to comment.