Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #1947
Closed
Open
Issue created Jan 20, 2019 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG] typescript-fetch should not use namespaces (SyntaxError: Namespaces are not supported.)

Created by: ceefour

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?
  • [Optional] Bounty to sponsor the fix (example)
Description

Generated files result in error: (e.g. in create-react-app with TypeScript support)

./src/api/profile/models/Culture.ts
SyntaxError: C:\Users\ceefour\git\heartenly-pwa\src\api\profile\models\Culture.ts: Namespaces are not supported.
  110 |  * @namespace Culture
  111 |  */
> 112 | export namespace Culture {
      |        ^
  113 |     /**
  114 |      * @export
  115 |      * @enum {string}

Adding configuration supportsES6: true doesn't help.

Via @DanielRosenwasser - https://github.com/facebook/create-react-app/pull/4837#issuecomment-430107471 :

TypeScript PM here. Broadly speaking, I feel that

namespaces are not a huge loss; the React community is firmly on-board with ES modules anyway, and that's the direction the TypeScript world is taking. const enums are often misused. Sure, they can be great for the internals of a library to get some speed improvements, but they generally shouldn't be used outside of that scope. Merging behavior is marginally useful now that TypeScript 3.1 has the ability to tack properties onto functions. The fact that enums merge is also something I've never seen used out in the wild.

via @Timer - https://github.com/facebook/create-react-app/issues/5681#issuecomment-435372634 :

I'm sorry and understand that this is likely frustrating, but namespaces are a proprietary, legacy feature. They have been replaced by specification behavior: ES Modules. Namespaces are deprecated. The TypeScript documentation is going to remove all references to them in examples and stop usage. In other words, you should not be using namespaces anymore. Const Enums are rarely needed and often misused.

openapi-generator version

0.0.7-4.0.0-beta

OpenAPI declaration file content or url

anything that uses enum

Command line used for generation
openapi-generator generate -i E:\tmp\lovia-heartenly-profile-4.0-swagger.yaml -g typescript-fetch -o src/api/profile
Steps to reproduce
  1. generate using typescript-fetch
  2. @babel/preset-typescript won't compile, and the generated files use deprecated namespace feature
Related issues/PRs
  • https://github.com/OpenAPITools/openapi-generator/issues/802#issuecomment-437249935 @acornett
  • https://github.com/facebook/create-react-app/issues/5633#issuecomment-434518065 @Timer
Suggest a fix

Remove the namespace and use the enum directly in the module.

Assignee
Assign to
Time tracking