cyclosproject / ng-openapi-gen

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

[Bug] Operation parameter objects won't be imported #295

Open Gerandon opened 1 year ago

Gerandon commented 1 year ago

Just recently found out, that the operation parameters will not get imported, if they represent a complex object.

I've got a custom template for operationParameters.handlebars, where basically I want to use models as my parameter type. The name of these models will be used as a parameter, but they are missing from the imports.

My custom template:

params{{^operation.parametersRequired}}?{{/operation.parametersRequired}}: {
{{#operation.parameters}}
    {{tsComments}}{{{var}}}{{^required}}?{{/required}}: {{{type}}};{{#tsComments}}{{/tsComments}}
{{/operation.parameters}}
{{#requestBody}}
{{{../operation.requestBody.tsComments}}}body{{^../operation.requestBody.required}}?{{/../operation.requestBody.required}}: {{{type}}}
{{/requestBody}}  }

I saw that back in August there were a few changes about that (lib/service.ts:22), including the following lines:

// Add the parameters as additional dependencies
for (const parameter of operation.parameters) {
    this.collectImports(parameter.spec.schema, true);
}

Previously, in case of operation.parameters, they were "collected" as additional: false. Now as they are additional, they won't appear in the import list.

Is it something that was made on purpose and I'm missing something, or was that made by mistake?

Gerandon commented 1 year ago

Same happens with requestBody Changed from

if (operation.requestBody) {
    for (const content of operation.requestBody.content) {
        this.collectImports(content.spec.schema);
    }
}

To

// Add the request body additional dependencies
this.collectImports(variant.requestBody?.spec?.schema, true);
luisfpg commented 11 months ago

Do you mind sharing some example project to reproduce the issue?

Gerandon commented 11 months ago

Do you mind sharing some example project to reproduce the issue?

Sure, I'm gonna create a test project later if you don't mind, 'cause the exact problem came across in a private production app