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

[BUG] [typescript-node] Generating only models generates invalid TS #7126

Closed
5 tasks done
sarumont opened this issue Aug 4, 2020 · 1 comment · Fixed by #7127
Closed
5 tasks done

[BUG] [typescript-node] Generating only models generates invalid TS #7126

sarumont opened this issue Aug 4, 2020 · 1 comment · Fixed by #7127

Comments

@sarumont
Copy link
Contributor

sarumont commented Aug 4, 2020

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
Description

When providing --global-property models to generate only models, the resultant TypeScript references ../api for importing RequestFile.

openapi-generator version
4.3.1

Not a regression that I know of.

OpenAPI declaration file content or url

Any valid OpenAPI file containing models will reproduce this.

openapi: 3.0.2
info:
  version: 0.3.0
  description: null
  title: '@devsupply/core-types-typedefs'
paths:
  /foo:
    get:
      tags:
        - foo
      operationId: getFoo
      responses:
        "204":
          description: Foo
components:
  schemas:
    CloudProvider:
      type: string
      enum:
        - AWS
        - AZURE
        - GOOGLE
      x-enum-descriptions:
        - Amazon AWS
        - Microsoft Azure
        - Google Cloud Platform
Generation Details
npx openapi-generator generate 
    -g typescript-node 
    --global-property models 
    -i ./example.yml -o gen/
Steps to reproduce

Generate code as above. Attempt to build via TypeScript:

npx tsc gen/model/cloudProvider.ts

Results in:

13 import { RequestFile } from '../api';
                               ~~~~~~~~


Found 1 error.
Suggest a fix

Suggest moving the RequestFile definition into models.ts and also generating this file when --global-property models is provided. Will submit a PR with this fix...

Related Issue: #7040 (it should be noted that moving the RequestFile definition will not work until #7040 is addressed, as the validators import things from request)

@sarumont
Copy link
Contributor Author

sarumont commented Aug 4, 2020

It actually appears that the better approach may be defining a new supporting file for model/index.ts. I'm working on that approach in my WIP PR... :)

macjohnny added a commit that referenced this issue Aug 28, 2020
* add model/index.ts

- move export of all models to model/index.ts
- move RequestFile definition to model/index.ts

This fixes #7126

* update samples

* Back out models/index.ts

Make this backwards-compatible:

- move `RequestFile` definition to `model/models.ts`
- remove `model/index.ts`
- re-export `RequestFile` from `api/apis.ts`
- make generation of `ObjectSerializer` conditional

* for some reason, Symfony isn't up to date

* reverts changes to php-symfony sample

* moves comment to mustache comment rather than TS comment

Co-authored-by: Esteban Gehring <esteban.gehring@gmail.com>

* removes stale files from samples (no longer generated)

* updates samples

Co-authored-by: Esteban Gehring <esteban.gehring@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant