Open bard opened 4 years ago
👍 Thanks for opening this issue! 🏷 I have applied any labels matching special text in your issue.
The team will review the labels and make any necessary changes.
After investigating further, I see that the type is generated, it's just not imported.
Expected code in DefaultApi.ts
:
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
import * as runtime from '../runtime';
import {
Character
} from '../models'
/**
*
*/
export class DefaultApi extends runtime.BaseAPI {
Actual code:
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
import * as runtime from '../runtime';
/**
*
*/
export class DefaultApi extends runtime.BaseAPI {
Any update on this? 😢
@bard I'm curious as to why you're using additionalProperties
to define the response schema. If you need array of map, shouldn't it just be:
"/characters":
get:
responses:
"200":
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/Character"
Perhaps additionalProperties
is intentional but i'm struggling to understand why...
@badsyntax It's not an array of maps, it's a map of array of maps, e.g. comic title to array of characters:
{
"Superman": [
{ "firstName": "Klark", "lastName": "Kent" },
{ "firstName": "Lois", "lastName": "Lane" }
],
"Batman": [
{ "firstName": "Bruce", "lastName": "Wayne" }
]
}
I know, not the best layout, but it's an existing API over which I have no control.
I'm having the same problem with the typescript-angular
generator (I'm guessing they share the same code). I'm trying to generate code from the spring-boot actuator which contains the following schema:
{
"type": "object",
"additionalProperties": {
"type": "object",
"additionalProperties": {
"$ref": "#/components/schemas/Link"
}
}
Same problem, the type under additionalProperties
is not imported causing a compile error for the generated code:
ERROR in ./src/app/_generated/index.ts
Module build failed (from ./node_modules/@ngtools/webpack/src/index.js):
Error: ENOENT: no such file or directory, open '/mnt/c/Users/demarteaub/Projects/clarified-arbustum/client/src/app/_generated/index.ts'
at Object.openSync (fs.js:462:3)
at Object.readFileSync (fs.js:364:35)
at Storage.provideSync (/mnt/c/Users/demarteaub/Projects/clarified-arbustum/client/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:109:13)
at CachedInputFileSystem.readFileSync (/mnt/c/Users/demarteaub/Projects/clarified-arbustum/client/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:289:32)
at Observable._subscribe (/mnt/c/Users/demarteaub/Projects/clarified-arbustum/client/node_modules/@ngtools/webpack/src/webpack-input-host.js:35:51)
at Observable._trySubscribe (/mnt/c/Users/demarteaub/Projects/clarified-arbustum/client/node_modules/@ngtools/webpack/node_modules/rxjs/internal/Observable.js:44:25)
at Observable.subscribe (/mnt/c/Users/demarteaub/Projects/clarified-arbustum/client/node_modules/@ngtools/webpack/node_modules/rxjs/internal/Observable.js:30:22)
at SyncDelegateHost._doSyncCall (/mnt/c/Users/demarteaub/Projects/clarified-arbustum/client/node_modules/@angular-devkit/core/src/virtual-fs/host/sync.js:22:20)
at SyncDelegateHost.read (/mnt/c/Users/demarteaub/Projects/clarified-arbustum/client/node_modules/@angular-devkit/core/src/virtual-fs/host/sync.js:49:21)
at WebpackCompilerHost.readFile (/mnt/c/Users/demarteaub/Projects/clarified-arbustum/client/node_modules/@ngtools/webpack/src/compiler_host.js:150:42)
at WebpackCompilerHost.getSourceFile (/mnt/c/Users/demarteaub/Projects/clarified-arbustum/client/node_modules/@ngtools/webpack/src/compiler_host.js:261:34)
at AngularCompilerPlugin.getDependencies (/mnt/c/Users/demarteaub/Projects/clarified-arbustum/client/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:942:47)
at /mnt/c/Users/demarteaub/Projects/clarified-arbustum/client/node_modules/@ngtools/webpack/src/loader.js:63:59
at Array.forEach (<anonymous>)
at /mnt/c/Users/demarteaub/Projects/clarified-arbustum/client/node_modules/@ngtools/webpack/src/loader.js:63:18
at processTicksAndRejections (internal/process/task_queues.js:97:5)
For reference, I work around this by fixing the generated file on the fly, it is very brittle but the only way to not break our CI build.
rm -rf src/app/_generated/ \
&& openapi-generator batch openapi-config/localhost.yml \
&& sed -i "1s|^|import { Link } from '../model/models';\n|" src/app/_generated/api/actuator.service.ts
Bug Report Checklist
Description
When an item of an array of a map is specified through a referenced schema, the type for the item is not generated.
For example, for an endpoint specification of:
And a schema specification of:
The
Character
type is not generated:openapi-generator version
4.3.1
OpenAPI declaration file content or url
https://github.com/bard/openapi-generator-missing-type/blob/master/example.yaml
Excerpt:
Command line used for generation
Steps to reproduce
yarn install && yarn test
Related issues/PRs
https://github.com/OpenAPITools/openapi-generator/pull/5995 seems to solve a similar issue