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

Support for index signatures #374

Closed
manast-apsis opened this issue Jul 25, 2019 · 6 comments · Fixed by #462
Closed

Support for index signatures #374

manast-apsis opened this issue Jul 25, 2019 · 6 comments · Fixed by #462

Comments

@manast-apsis
Copy link

Seems like index signatures such as

class myClass {
    nodes: {
        [nodeName: string]: Node;
    };
}

are not currently supported.

https://www.typescriptlang.org/docs/handbook/advanced-types.html#index-types-and-string-index-signatures

nodes will just show as an empty object in the swagger file.

@dgreene1
Copy link
Collaborator

dgreene1 commented Aug 6, 2019

I'll look into making a PR for this after #385 merges (since that's a big PR with lots of changes.

In the meantime, although the swagger output will not contain the correct information, the request validation will ensure that the data is correct. There is an API test that confirms that the following interface actually gets validated.

export interface ValidateMapStringToNumber {
  [key: string]: number;
}

And here's the unit test that proves the validation works as expected:

it('should validate string-to-number dictionary body', () => {

So long story short, please continue to use tsoa for your validation, and we'll add a PR for better swagger generation for indexed types soon. :)

I know it's a bit strange that tsoa's swagger output is separate from it's runtime validation, but that's advantageous because we return nice, human readable output.

@javichi
Copy link

javichi commented Aug 6, 2019

Looking forward for this feature :)

@dgreene1
Copy link
Collaborator

dgreene1 commented Aug 9, 2019

I'm closing this because it's a duplicate of #50. However, until #50 is solved, the workaround for this particular case is:

interface INodeDictionary {
    [nodeName: string]: Node;
}
class myClass {
    nodes: INodeDictionary;
}

@dgreene1
Copy link
Collaborator

dgreene1 commented Sep 5, 2019

We need to reopen this to make sure that the case presented by @javichi works: #50 (comment)

@dgreene1
Copy link
Collaborator

dgreene1 commented Sep 5, 2019

@javichi / @manast-apsis this fix/feature was just released in v2.5.1. Can you let us know how it worked out for you?

Side note: we're looking for companies that want to be featured in tsoa's readme: #464

@javichi
Copy link

javichi commented Sep 11, 2019

Sorry for the delay. I can confirm that all index signatures are generated in v2.5.1. Great work guys!

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 a pull request may close this issue.

3 participants