cyclosproject / ng-openapi-gen

An OpenAPI 3.0 codegen for Angular
MIT License
403 stars 134 forks source link

Wrong import path for model files in index.ts #291

Closed scurk1415 closed 1 year ago

scurk1415 commented 1 year ago

Not sure if i am doing something wrong or if there is a bug with the import paths for model files if you are using the "indexFile": true config. All model import paths are missing the ./models prefix. So if i have a User model then the generated code is

export { User } from '/api-sport';

instead of

export { User } from './models/api-sport';

It works ok for services.

I am using the lates 0.50.2 version of this library. The generation also works ok with the 0.25.1 version, so i guess something is wrong with the 0.50.x version of the library

luisfpg commented 1 year ago

I can't reproduce it. Tried with:

npm i -g ng-openapi-gen@0.50.2
ng-openapi-gen --input https://petstore3.swagger.io/api/v3/openapi.json --output petstore

And this is the content of petstore/models.ts:

/* tslint:disable */
/* eslint-disable */
export { ApiResponse } from './models/api-response';
export { Category } from './models/category';
export { Order } from './models/order';
export { Pet } from './models/pet';
export { Tag } from './models/tag';
export { User } from './models/user';
scurk1415 commented 1 year ago

Here is the reproduction: https://github.com/scurk1415/open-api-reproduction

Just run npm run generate-api and then check src/app/api/index.ts

The line export { Test } from '/test'; has errors -> TS2307: Cannot find module  /test  or its corresponding type declarations.

Also, running your example from your comment gives the same errors in index.ts file

luisfpg commented 1 year ago

Is it the same result with the latest 0.50.3?

Em ter., 10 de out. de 2023 11:09, GLaw @.***> escreveu:

Here is the reproduction: https://github.com/scurk1415/open-api-reproduction

Just run npm run generate-api and then check src/app/api/index.ts

The line export { Test } from '/test'; has errors

— Reply to this email directly, view it on GitHub https://github.com/cyclosproject/ng-openapi-gen/issues/291#issuecomment-1755506408, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJA76P7TZUQEJESXFBLNNTX6VJK7AVCNFSM6AAAAAA5VO5FAGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONJVGUYDMNBQHA . You are receiving this because you modified the open/close state.Message ID: @.***>

scurk1415 commented 1 year ago

My reproduction repository above has v0.50.3 and the errors still persist

mokeev1995 commented 1 year ago

@luisfpg can confirm that this bug still exists.

here's example swagger.json with the same issue

Снимок экрана 2023-10-15 в 02 50 52

swagger.json

mokeev1995 commented 1 year ago

@luisfpg if i understand correctly, the bug is here:

https://github.com/cyclosproject/ng-openapi-gen/blob/master/templates/index.handlebars#L6

Possibly this

{{#modelIndex.imports}}export { {{{typeName}}}{{#useAlias}} as {{{qualifiedName}}}{{/useAlias}} } from '{{{file}}}';
{{/modelIndex.imports}}

Should be like this (like in models.ts generator template)

{{#modelIndex.imports}}export { {{{typeName}}}{{#useAlias}} as {{{qualifiedName}}}{{/useAlias}} } from './models{{{file}}}';
{{/modelIndex.imports}}