cyclosproject / ng-openapi-gen

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

Fix model import with namespaces #284

Closed hbunjes closed 1 year ago

hbunjes commented 1 year ago

Models with namespaces that have references between each other are broken since v0.50.

This is a simple openapi 3 definition with a model named "Ns.Ns2.Customer" referencing another one named "Ns.Address": openapi.json.txt

The import to Customer in the API service is modeled correctly: import { Customer as NsNs2Customer } from '../models/Ns/Ns2/customer';

However, the import from Customer to Address is broken: import { Address as NsAddress } from '..//../models/Ns/address';

From what I found:

  1. in lib/model.ts "pathToModels" creates the double "//" as it joins "../" with a "/"
  2. in lib/imports.ts "add" seems to introduce the "models"

My idea (in this PR):

  1. Remove the "/" in join of pathToModels
  2. Add another "../" to get one level up of "model".

Models with namespaces that have references between each other are broken since v0.50.

This is a simple openapi 3 definition with a model named "Ns.Ns2.Customer" referencing another one named "Ns.Address": openapi.json.txt

The import to Customer in the API service is modeled correctly: import { Customer as NsNs2Customer } from '../models/Ns/Ns2/customer';

However, the import from Customer to Address is broken: import { Address as NsAddress } from '..//../models/Ns/address';

From what I found:

  1. in lib/model.ts "pathToModels" creates the double "//" as it joins "../" with a "/"
  2. in lib/imports.ts "add" seems to introduce the "models"

My idea (in this PR):

  1. Remove the "/" in join of pathToModels
  2. Add another "../" to get one level up of "models".
hbunjes commented 1 year ago

Build error due to trailing space is fixed in https://github.com/cyclosproject/ng-openapi-gen/pull/285