OpenAPITools / OpenAPITools/openapi-generator
[BUG][typescript-fetch] Generated Code missing helpers like numberFromJSONTyped, instanceOfnumber and so forth
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
When generating the openapi code, it is failing to generate helpers (instanceOfnumber, instanceOfstring, numberFromJSONTyped, stringFromJSONTyped). It fails type checking as a result.
if (instanceOfnumber(json)) {
return numberFromJSONTyped(json, true);
}
if (instanceOfstring(json)) {
return stringFromJSONTyped(json, true);
}
openapi-generator version
On Macos M3 Sonoma using brew
openapi-generator --version
openapi-generator-cli 7.8.0
commit : 6bdc452
built : -999999999-01-01T00:00:00+18:00
source : https://github.com/openapitools/openapi-generator
docs : https://openapi-generator.tech/
OpenAPI declaration file content or url
openapi: 3.0.0
info:
title: Test
version: 1.0.22
paths: {}
components:
schemas:
Test1:
type: object
properties:
test_type:
type: string
enum:
- FOO
test_value:
oneOf:
- type: integer
required:
- test_type
- test_value
Test2:
description: test
type: object
properties:
something:
type: array
items:
oneOf:
- type: string
- type: integer
required:
- something
Config.json
{
"generateSourceCodeOnly": true
}
Generation Details
openapi-generator generate -i test.yaml -g typescript-fetch -c config.json --global-property models,modelTests=false --additional-properties enumPropertyNaming=UPPERCASE,removeEnumValuePrefix=false
Steps to reproduce
- Copy yaml to
test.yaml - Copy json to
config.json - Run the command above
- Run typescript typechecker or open file and see helper is not found.
Related issues/PRs
Didn't see anything.
Suggest a fix
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.
Research direction
Reproduce the issue using the supplied test.yaml, config.json, and openapi-generator command with the typescript-fetch generator. Run the TypeScript typechecker and inspect the generated model code for the missing helpers such as numberFromJSONTyped and instanceOfnumber. Done means the generated code includes the required helpers and passes type checking.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100