Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swagger api calls #17

Merged
merged 7 commits into from
Apr 24, 2018
Merged

Swagger api calls #17

merged 7 commits into from
Apr 24, 2018

Conversation

darvid7
Copy link
Collaborator

@darvid7 darvid7 commented Apr 22, 2018

Add Swagger Codegen API call

  • need to make it support *.yaml files, it just supports json for now.

@darvid7
Copy link
Collaborator Author

darvid7 commented Apr 22, 2018

Does anyone know how to change the diffbase?
There is some stuff here that #16 does but the diff still shows :(

Not sure if we can do this:

@@ -1,5 +1,6 @@
import { Specification } from 'model/Specification';
import { BuildStatus } from 'model/SDK';
import { isUndefined } from 'util';
Copy link
Collaborator

@PatrickShaw PatrickShaw Apr 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@darvid7 Why do you need this? It's a deprecated method for one thing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ty for pointing that out, idk webstorm just prompted me to use it :P

@@ -42,6 +53,11 @@ const specifications: Specification[] = [
* @return {Specification | undefined} - returns the Specification with the matching id if it exists
*/
export function getSpecificationById(id: number): Specification | undefined {
// TODO: Remove this later.
if (isUndefined(id)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we get the last item if we don't specify an id? The parameter doesn't allow for undefined values.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When trying to implement it was always undefined so I just added it to show it can work.
Also the type being Specification | undefined, doesn't that allow it to be undefined?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No as in id is never undefined (as specified by the parameter type) so why account for id being undefined if the function explicitly says that id will only ever be a number (i.e. never be undefined)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is true, idk what I was thinking. Thanks for pointing it out!

console.log('generateSdk');
let body = { swaggerUrl: spec['path'] };
console.log(body);
return fetch(SWAGGER_CODEGEN_ENDPOINT + 'python', {
Copy link
Collaborator

@PatrickShaw PatrickShaw Apr 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change this to use await?

  • Change .then()s to await

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean we need to nest them somehow because there are two .thens()?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Figured out how to :) although if you know what .json() does pls lmk

if ('type' in json && json['type'] == 'error') {
return BAD_SPECIFICATION;
}
return json['link'];
Copy link
Collaborator

@PatrickShaw PatrickShaw Apr 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use json.type and json.link rather than json['link']

  • Change ['xx'] syntax to .xx

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't know this was a thing, ty

import fetch from 'node-fetch';

const SWAGGER_CODEGEN_ENDPOINT = 'http://generator.swagger.io/api/gen/clients/';
const BAD_SPECIFICATION = 'Error: Bad specification';

export async function generateSdk(spec: Specification): Promise<string> {
Copy link
Collaborator

@PatrickShaw PatrickShaw Apr 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised this passed the checker:types test. By the looks of things, generateSdk doesn't return Promise<string> anymore. Can we make this something less wrong for now? (E.g. Promise<any> or something similar?)

  • Change the return type of generateSdk

// TODO: Get it working for .yaml files like below.
// 'https:/OAI/OpenAPI-Specification/blob/master/examples/v2.0/yaml/uber.yaml' }
console.log('generateSdk');
let body = { swaggerUrl: spec['path'] };
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spec.path rather than spec['path']

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@darvid7
Copy link
Collaborator Author

darvid7 commented Apr 23, 2018

@PatrickShaw Please take another look, made all changes except the getting last item if an id is not specified.

Wasn't any point having it since id is never undefined
Copy link
Collaborator

@PatrickShaw PatrickShaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this LGTM now 👍

@@ -42,6 +53,11 @@ const specifications: Specification[] = [
* @return {Specification | undefined} - returns the Specification with the matching id if it exists
*/
export function getSpecificationById(id: number): Specification | undefined {
// TODO: Remove this later.
if (isUndefined(id)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No as in id is never undefined (as specified by the parameter type) so why account for id being undefined if the function explicitly says that id will only ever be a number (i.e. never be undefined)

@darvid7 darvid7 merged commit 94adf81 into telstra:development Apr 24, 2018
darvid7 added a commit that referenced this pull request Apr 24, 2018
General Updates

Just going to merge it now cuz I forgot to merge it before #17 and idk what is going to happen to the git tree now :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants