thiagobustamante / typescript-rest-swagger

Swagger tools for typescript-rest
156 stars 57 forks source link

Implement Types support in JSDoc for Swagger gen #9

Open vrudikov opened 7 years ago

vrudikov commented 7 years ago

Hi, Thiago So i tried to return declared Type from API method and added type's reference to JSDoc, but swagger generator can't handle it. It just writes 'Inline Model 1':

image

You can see examples here and here

vrudikov commented 7 years ago

@thiagobustamante Hi. Any updates? If you are busy - please suggest me a string or filename. I will do a research

thiagobustamante commented 7 years ago

Hi, @vrudikov ,

The problem is not related to JsDocs. The problem is that typescript-rest-swagger can not understand this declaration:

export type SimpleHelloType = {
    greeting: string;
};

if you use interfaces or classes, it works:

export interface SimpleHelloType {
    greeting: string;
}

or

export class SimpleHelloType {
    greeting: string;
}

I have to check why this type aliases are not working

thiagobustamante commented 7 years ago

@vrudikov , please, try 0.0.10 version

vrudikov commented 7 years ago

@thiagobustamante A-W-E-S-O-M-E! Thank you

The problem is not related to JsDocs. The problem is that typescript-rest-swagger can not understand this declaration

Yeah. I knew that. But wanted to understand where it should be fixed

vrudikov commented 7 years ago

Just a second. I think i found a bug. I will try to created a PR and will post a fix

vrudikov commented 7 years ago

@thiagobustamante Hello! Could you try to replace your object with this one:

export type SimpleHelloType = {
    /**
     * Description for greeting property
     */
    greeting: string;
    arrayOfSomething: Something[];

    profile: {
        name: string
    };

    comparePassword: (candidatePassword: string, cb: (err: any, isMatch: any) => {}) => void
};

export type Something = {
    someone: string,
    kind: string
};

And fire swagger generator again, plz

I receive this error:

Error: Unknown type: TypeLiteral
    at resolveType (/Users/val.rudi/Documents/Nodejs/typescript-rest-swagger/src/metadata/resolveType.ts:38:15)
    at /Users/val.rudi/Documents/Nodejs/typescript-rest-swagger/src/metadata/resolveType.ts:418:27
    at Array.map (native)
    at getModelTypeProperties (/Users/val.rudi/Documents/Nodejs/typescript-rest-swagger/src/metadata/resolveType.ts:378:14)
    at getModelTypeProperties (/Users/val.rudi/Documents/Nodejs/typescript-rest-swagger/src/metadata/resolveType.ts:424:16)
    at getReferenceType (/Users/val.rudi/Documents/Nodejs/typescript-rest-swagger/src/metadata/resolveType.ts:208:28)
    at resolveType (/Users/val.rudi/Documents/Nodejs/typescript-rest-swagger/src/metadata/resolveType.ts:83:25)
thiagobustamante commented 7 years ago

Yes you are right. I added it to the test case and I am reopening the issue.

krazar commented 7 years ago

Is it the same reason why it does not work on types in interface ?

export type GroupId = number;

export interface Group {
  id: GroupId;
  groupName: string;
}

Also, In my case, this object is not directly linked to the rest layer. Is typescript-rest-swagger look for every defined type in the project ?

vrudikov commented 7 years ago

@thiagobustamante hi. have you had a time to look at my case? do you need any help?

ngraef commented 7 years ago

@vrudikov This should be fixed by recent commits. Please try with the latest version (0.0.12) and let me know if you still have issues.

@krazar Your issue is a bit different. I'm looking into it.

vrudikov commented 7 years ago

@ngraef Awesome. Thank you. Will take a look today

vrudikov commented 6 years ago

Wow. Forgot to look at it. Will do in near future