swagger-api / swagger-api/swagger-codegen

[typescript-angular] schema with only additionalProperties wrongly typed as Map

Open
#8,854 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

When a schema is a object with only additionalProperties, the created model is typed as Map instead of any.

Swagger-codegen version

3.0.2

Swagger declaration file content or url
openapi: 3.0.0
info:
  title: TestApi
  version: 1.0.0
paths:
  /test:
    get:
      summary: Test
      operationId: testApi
      responses:
        "200":
          description: Ok
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Response"
components:
  schemas:
    Response:
      type: object
      additionalProperties:
        type: string
Command line used for generation

docker run --rm -v ${PWD}:/local swaggerapi/swagger-codegen-cli-v3:3.0.2 generate -i /local/swagger.yaml -l typescript-angular -o /local/ts-angular

Steps to reproduce
Suggest a fix/enhancement

The generated model is:

export type Response = Map;

and its invalid. It should be

export type Response = any;

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

Start with the provided OpenAPI schema in swagger.yaml and the typescript-angular generator path used by the Docker command; inspect how an object containing only additionalProperties becomes the Response model. Confirm the generated type is any rather than Map, and add or update a regression test if the generator's existing test structure supports it.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, typescript
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.