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

[typescript-node] Add RequestFile to typescript-node model template #4903

Merged
merged 1 commit into from Jan 6, 2020
Merged

[typescript-node] Add RequestFile to typescript-node model template #4903

merged 1 commit into from Jan 6, 2020

Conversation

ryannjohnson
Copy link
Contributor

@ryannjohnson ryannjohnson commented Jan 1, 2020

Fixes #4902.

PR checklist

  • Read the contribution guidelines.
  • If contributing template-only or documentation-only changes which will change sample output, build the project before.
  • Run the shell script(s) under ./bin/ (or Windows batch scripts under.\bin\windows) to update Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit, and these must match the expectations made by your contribution. You only need to run ./bin/{LANG}-petstore.sh, ./bin/openapi3/{LANG}-petstore.sh if updating the code or mustache templates for a language ({LANG}) (e.g. php, ruby, python, etc).
  • File the PR against the correct branch: master, 4.3.x, 5.0.x. Default: master.
  • Copy the technical committee to review the pull request if your PR is targeting a particular programming language.

Typescript technical committee

@TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01) @nicokoenig (2018/09) @topce (2018/10) @akehir (2019/07) @petejohansonxo (2019/11)

RequestFile is defined in the [api-all.mustache
template](https://github.com/OpenAPITools/openapi-generator/blob/ac4ead9e7805d4dc89d791376539496a57c49df7/modules/openapi-generator/src/main/resources/typescript-node/api-all.mustache#L29),
and it gets used [as a special
case](https://github.com/OpenAPITools/openapi-generator/blob/ac4ead9e7805d4dc89d791376539496a57c49df7/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptNodeClientCodegen.java#L92)
[in the model.mustache
template](https://github.com/OpenAPITools/openapi-generator/blob/ac4ead9e7805d4dc89d791376539496a57c49df7/modules/openapi-generator/src/main/resources/typescript-node/model.mustache#L21).

When this special case is triggered and `RequestFile` is used in a model
file, Typescript complains that the type is not found.

```
TSError: Unable to compile TypeScript:
path/to/model.ts:15:16 - error TS2304: Cannot find name 'RequestFile'.

15      'myFile'?: RequestFile;
                   ~~~~~~~~~~~
```

This solution is to import `RequestFile` by adding it to the model
template.

Here is an openapi schema that would trigger this use-case:

```yaml
openapi: 3.0.0
components:
    schemas:
        IUploadMyFileBody:
            type: object
            properties:
                myFile:
                    type: string
                    format: binary
```
@ryannjohnson ryannjohnson changed the title Add RequestFile to typescript-node model template [typescript-node] Add RequestFile to typescript-node model template Jan 1, 2020
@macjohnny macjohnny merged commit d513547 into OpenAPITools:master Jan 6, 2020
@macjohnny macjohnny added this to the 4.2.3 milestone Jan 6, 2020
jimschubert added a commit to jimschubert/openapi-generator that referenced this pull request Jan 11, 2020
* master: (187 commits)
  [core] Initial FeatureSet structures and definitions (OpenAPITools#3614)
  Add Cisco to the user list (OpenAPITools#4971)
  comment out php slim4 in ensure-up-to-date
  update samples
  [Python] Allow models to have properties of type self (OpenAPITools#4888)
  Add npmRepository option to javascript generators (OpenAPITools#4956)
  [Slim4] Add ref support to Data Mocker (OpenAPITools#4932)
  Fix auto-labeler for jax-rs (OpenAPITools#4943)
  [doc] full generator details (OpenAPITools#4941)
  comment out python flask 2 test (OpenAPITools#4949)
  [jaxrs-spec][quarkus] update to version 1.1.1.Final (OpenAPITools#4935)
  [cli] Full config help details (OpenAPITools#4928)
  Add RequestFile to typescript-node model template (OpenAPITools#4903)
  [csharp] enum suffix changes enumValueNameSuffix to enumValueSuffix (OpenAPITools#4927)
  [C#] allow customization of generated enum suffixes (OpenAPITools#4301)
  [Kotlin] Correct isInherited flag for Kotlin generators (OpenAPITools#4254)
  [Rust Server] Fix panic handling headers (OpenAPITools#4877)
  Initial CODEOWNERS (OpenAPITools#4924)
  [scala] Support for Set when array has uniqueItems=true (OpenAPITools#4926)
  remove nodejs server samples, scripts (OpenAPITools#4919)
  ...
@KadoBOT
Copy link

KadoBOT commented Mar 26, 2020

@ryannjohnson @macjohnny

This shouldn't be the case for every generated model. In my case, I just generate the models and nothing else (-Dmodels). But the RequiredFile import is still present, which, points to an nonexistent file.

@macjohnny
Copy link
Member

@KadoBOT would you like to file a PR to fix this?

@KadoBOT
Copy link

KadoBOT commented Mar 27, 2020

@macjohnny I've spent a couple of minutes trying to create a bool variable which checks if the /apis folder exist and wrap the RequestFile with it, but Java is not something I'm used to and it didn't worked :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG][Typescript-node] Cannot find name 'RequestFile'
3 participants