[typescript-node] Import missing when additional properties point to $ref on the root of a schema
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 38/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- node.js, openapi, typescript
- Domain
- tooling
Research direction
Use the provided OpenAPI schema and run the documented openapi-generator command for the typescript-node generator. Inspect the generated TypeScript, especially api.ts and the model references, then run tsc ./ts/api.ts to reproduce the missing B error. Done means the generated code includes the needed import and compiles successfully.
Written by the indexing model from the issue text.
Description
Description
When additionalProperties are on the root of a schema and they point to a $ref of another schema, the generated code for the API does not include the import statement for the model. The generated code attempts to use the model, but the code fails to compile due to the missing import.
openapi-generator version
3.3.0-SNAPSHOT
OpenAPI declaration file content or url
components:
schemas:
A:
type: object
properties:
name:
type: string
additionalProperties:
$ref: '#/components/schemas/B'
B:
type: object
properties:
id:
type: string
value:
anyOf:
- type: string
- type: integer
Full test yaml: https://gist.github.com/johnkoerner/faea41ec36ddea55d6522752b9981452
Command line used for generation
openapi-generator generate -i Test.yaml -g typescript-node -o ./ts
Steps to reproduce
- Generate the typescript using the command above
- Attempt to build the typescript using
tsc ./ts/api.ts - Notice that you will get the error
error TS2304: Cannot find name 'B'.
Related issues/PRs
See #398 as that is a similar issue. Note that you need 3.3.0 or higher as there are errors you receive from the generator in prior versions.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 100
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from OpenAPITools/openapi-generator
-
Issue: Bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
OpenAPITools/openapi-generator#24859 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
OpenAPITools/openapi-generator#24852 · 1 comment ·
-
[BUG][KOTLIN] Fails to compile after updating to 7.25.0 with useJackson3=false useSpringBoot4=true OpenIssue: Bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
OpenAPITools/openapi-generator#24842 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
OpenAPITools/openapi-generator#24830 ·
-
Issue: Bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
OpenAPITools/openapi-generator#24816 · 1 comment ·
All issues in OpenAPITools/openapi-generator
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
bug needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 1/5 Under an hour Newbie friendliness 94/100
objectionary/hone-maven-plugin#1061 ·
-
type:bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100