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

Add support for model namespaces #39

Closed
snebjorn opened this issue Aug 16, 2019 · 2 comments
Closed

Add support for model namespaces #39

snebjorn opened this issue Aug 16, 2019 · 2 comments
Labels
bug Something isn't working
Milestone

Comments

@snebjorn
Copy link

According to OAI/OpenAPI-Specification#1362 namespaces are "supported" and tooling should handle them gracefully.

Given this schema with a namespace

{
  "openapi": "3.0.0",
  // omitted
  "components": {
    "schemas": {
      "MY_NAMESPACE.FooBar": {
        // omitted
      }
    }
  }
}

Generates this TS model

export interface MY_NAMESPACE.FooBar  {}

. is not an allowed character in an interface.

https://github.com/openapitools/openapi-generator-cli handles this by just generating

export interface MYNAMESPACEFooBar  {}
@luisfpg luisfpg added the bug Something isn't working label Sep 11, 2019
@snebjorn
Copy link
Author

snebjorn commented Oct 8, 2019

Perhaps an option to strip the namespace from the generated model could be added along with this fix.

So an option like excludeNamespaceInModels: boolean. The default value isn't important as namespaces don't currently work, so either will do :)

On 2nd thought the filename currently includes the namespace so the default value should probably be false and excludeNamespaceInModels should impact the generated filename.

@objt-ba
Copy link

objt-ba commented Oct 30, 2019

imho, the only correct handling, would be to translate namespaces to folders.
so, that would roughly mean:

 |-- MYNAMESPACE
      |-- foobar.interface.ts

with then the code

export interface FooBar {}

an import would then look as follows:

 import { FooBar } from '... /MYNAMESPACE/foobar.interface.ts'.

and if that ever comes down to a clash, of 2 interfaces having the same name:

import { FooBar as MyNamespaceFooBar } from '.../MYNAMESPACE/foobar.interface.ts'
import { FooBar as MyOtherFooBar }           from '.../MYOTHER/foobar.interface.ts'

@luisfpg luisfpg changed the title Namespaces break generated interface names Add support for model namespaces Dec 20, 2019
@luisfpg luisfpg added this to the 0.7.0 milestone Dec 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants