Skip to content

Add imports to typescript generator #116

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

Merged
merged 1 commit into from
May 9, 2019

Conversation

luca-nardelli
Copy link
Contributor

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT
Doc PR

I've noticed that the generated interfaces for typescript are missing the import { ResourceName } from "./resourcefile"; statements, making them less useful when used in a Typescript application (imports would need to be manually added everytime).

This PR fixes this and also adds a test to the typescript generator, testing for both interfaces with references to other interfaces and interfaces without references.

@luca-nardelli
Copy link
Contributor Author

ping @alanpoulain or @dunglas (should I ping someone else as well?)

@luca-nardelli
Copy link
Contributor Author

Travis was failing, I forgot to run yarn fix, now it's ok

… reference other fields

Add test to test interface without references
@luca-nardelli
Copy link
Contributor Author

I've noticed a thing. At the moment the handlebars template for the typescript interface has the @id field marked as not required, whereas id is required.

{{#each imports}}
import { {{type}} } from "{{file}}";
{{/each}}
{{#if imports.length}}

{{/if}}
export interface {{{name}}} {
  '@id'?: string;
  id: string;
{{#each fields}}
 {{#if readonly}} readonly{{/if}} {{{name}}}{{#if notrequired}}?{{/if}}: {{{type}}};
{{/each}}
}

I'd make both non-required, otherwise you might have issues when using that interface for POST (collection add) operations, where the ID might be unspecified (or would you have to set it as null?)

What do you think?

@dunglas
Copy link
Member

dunglas commented May 9, 2019

@luca-nardelli I agree with you. Can you open a new PR please?

@dunglas dunglas merged commit 7468728 into api-platform:master May 9, 2019
@dunglas
Copy link
Member

dunglas commented May 9, 2019

Thanks @luca-nardelli

@luca-nardelli
Copy link
Contributor Author

You're welcome! I'll open the other PR asap

@luca-nardelli
Copy link
Contributor Author

Done! #123

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.

4 participants