swagger-api / swagger-api/swagger-parser

Bad interaction between additionalProperties and $ref

Open
#401 13 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
867
Forks
560
Avg merge
2d 21h
Merged PRs (30d)
7

Description

Description

Compiling the following spec into a TypeScript-Fetch client results in invalid code.
Specifically, the generated code contains

export interface GenericMap extends null<String, number> {
}

which the TypeScript compiler rejects.

Swagger-codegen version

I tested it on swagger-codegen 2.2.1 (latest stable), 2.3.0 (7aebcfa) and master (d11d0f8).

Swagger declaration file content or url
...
definitions:
  GenericMap:
    additionalProperties:
      type: integer
  Container:
    type: object
    properties:
      works:
        type: object
        additionalProperties:
          type: string
      breaks:
        $ref: "#/definitions/GenericMap"
Command line used for generation

swagger-codegen generate -i test.yaml -l typescript-fetch

Steps to reproduce

Compile a swagger API containing the definitions mentioned above into a typescript-fetch client.

Further data

This was originally reported as https://github.com/swagger-api/swagger-codegen/issues/4839
@wing328 suggested to report the issue here as it is likely related to some problems with the resolution of the reference.

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 supplied YAML definition and run swagger-codegen generate -i test.yaml -l typescript-fetch against the reported versions or master. Trace how the $ref to GenericMap is resolved alongside additionalProperties; done means the generated TypeScript-Fetch client no longer contains invalid extends null<String, number> code.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, typescript
Domain
api
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.