swagger-parser icon indicating copy to clipboard operation
swagger-parser copied to clipboard

Bad interaction between additionalProperties and $ref

Open ranma42 opened this issue 8 years ago • 13 comments
trafficstars

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.

ranma42 avatar Feb 23 '17 10:02 ranma42

Can you try changing your definition to the following and see if it helps?

...
definitions:
  GenericMap:
    type: object
    additionalProperties:
      type: integer
  Container:
    type: object
    properties:
      works:
        type: object
        additionalProperties:
          type: string
      breaks:
        $ref: "#/definitions/GenericMap"

webron avatar Feb 23 '17 19:02 webron

On each of the three versions of swagger-codegen I had tested, it generates the very same output as the original spec.

ranma42 avatar Feb 23 '17 20:02 ranma42

Thanks for checking.

webron avatar Feb 23 '17 20:02 webron

is it resolved in the current version of swagger-parser and swagger-codegen?

naXa777 avatar Sep 12 '19 13:09 naXa777

Has anyone found a solution for this? I'm having the same issue with the typescript-axios vs.

BrandonWalker88 avatar May 19 '21 12:05 BrandonWalker88

Still broken on Codegen v3.0.31.

twistedpair avatar Jan 09 '22 19:01 twistedpair

Tried it on v3.0.34 and the problem still occurs

SchiessMax avatar May 23 '22 07:05 SchiessMax

Same issue for the version v3.0.36

mohammedSlimani avatar Jan 05 '23 10:01 mohammedSlimani

So is anybody managing this project or what?. People been complaining about this since 2019 and still no answer?.

rofenix2 avatar Jan 16 '23 03:01 rofenix2

Any news about this ?

alois-git avatar Jun 02 '23 13:06 alois-git

Same issue for the version v3.0.44

skizocell avatar Oct 27 '23 13:10 skizocell

Same issue for the version v3.0.50

skizocell avatar Oct 27 '23 14:10 skizocell