swagger-api / swagger-parser

Swagger Spec to Java POJOs
http://swagger.io
Apache License 2.0
778 stars 525 forks source link

Bad interaction between additionalProperties and $ref #401

Open ranma42 opened 7 years ago

ranma42 commented 7 years ago
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.

webron commented 7 years ago

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"
ranma42 commented 7 years ago

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

webron commented 7 years ago

Thanks for checking.

naXa777 commented 4 years ago

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

BrandonWalker88 commented 3 years ago

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

twistedpair commented 2 years ago

Still broken on Codegen v3.0.31.

SchiessMax commented 2 years ago

Tried it on v3.0.34 and the problem still occurs

mohammedSlimani commented 1 year ago

Same issue for the version v3.0.36

rofenix2 commented 1 year ago

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

alois-git commented 1 year ago

Any news about this ?

skizocell commented 10 months ago

Same issue for the version v3.0.44

skizocell commented 10 months ago

Same issue for the version v3.0.50

threydor commented 1 month ago

Still broken for the version v3.0.58