cyclosproject / ng-openapi-gen

An OpenAPI 3.0 codegen for Angular
MIT License
397 stars 132 forks source link

Add support for model namespaces #39

Closed snebjorn closed 4 years ago

snebjorn commented 5 years ago

According to https://github.com/OAI/OpenAPI-Specification/issues/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  {}
snebjorn commented 5 years ago

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 commented 4 years ago

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'