OpenAPITools / OpenAPITools/openapi-generator

[BUG] hashmap generator not implemented for typescript

Open
#20,308 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.