OpenAPITools / OpenAPITools/openapi-generator
[BUG] hashmap generator not implemented for typescript
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?
Description
When generating a model with this stucture:
Context:
title: ApiContextVq
additionalProperties: true
the instanceOf... and ...toJSON and FromJSONTyped is not implemented instead of anymap... errormap... it just writes the type
if (instanceOf{ [key: string]: any; }(value)) {
openapi-generator version
openapi-generator7.10.0
Suggest a fix
not quite sure what the to json function actually does in javascript.
this is more of an example what the generated code might look like.
function anyHashMapToJSON(value: { [key: string]: any }) {
return value;
}
function instanceOfAnyHashMap(value: ApiResponseV1Context) {
return true;
}
function instanceOfErrorHashMap(value: ApiResponseV1Context) {
return value.every(
(item: any) =>
typeof item === "object" &&
Object.keys(item).every((key) => key === "index" || key === "errors") &&
(item.index === undefined || typeof item.index === "number") &&
(item.errors === undefined ||
(Array.isArray(item.errors) &&
item.errors.every((err: any) => typeof err === "string"))),
);
}
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 TypeScript generation for a model with additionalProperties: true and inspect the generated instanceOf..., ...toJSON, and FromJSONTyped functions. Compare the emitted type-only handling with the requested any-hashmap behavior, then verify that the generated output implements the expected conversions and checks.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100