Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TypeScript-Fetch] Invalid interface definition when using additionalProperties #4839

Open
ranma42 opened this issue Feb 22, 2017 · 17 comments

Comments

@ranma42
Copy link

ranma42 commented Feb 22, 2017

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 2.2.1 (latest stable) and 2.3.0 (7aebcfa).

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.

Suggest a Fix

The Container type shows that additionalProperties are correctly handled in some cases (when used for the anonymous type of the works member), but not when they are used for a type which is basically a map. I believe it would be sufficient to emit the following type, without inheriting from any other type:

export interface GenericMap {
  [key: string]: number;
}
@wing328
Copy link
Contributor

wing328 commented Feb 23, 2017

@ranma42 thanks for reporting the issue. Can you try the latest master, which uses swagger parser 1.0.26-snapshot with better support for reference?

@ranma42
Copy link
Author

ranma42 commented Feb 23, 2017

The latest master (d11d0f8) seems to have the same problem.

@wing328
Copy link
Contributor

wing328 commented Feb 23, 2017

@ranma42 thanks for testing the latest master, may I suggest defining the map inline instead of a reference as a workaround?

@ranma42
Copy link
Author

ranma42 commented Feb 23, 2017

I am already doing that for my project ;)
I reported the issue because I was suggested to do so in the Swagger IRC channel (at first I was unsure if the spec was bad or it was just handled incorrectly).

@wing328
Copy link
Contributor

wing328 commented Feb 23, 2017

I am already doing that for my project ;)

👍

Looks like an issue that needs to be addressed in the Swagger Parser

@ranma42
Copy link
Author

ranma42 commented Feb 23, 2017

@wing328 should I close this and report against https://github.com/swagger-api/swagger-parser ?

@wing328
Copy link
Contributor

wing328 commented Feb 23, 2017

@ranma42 yes please open an issue there as well.

@thegecko
Copy link

thegecko commented Sep 4, 2017

This still seems to be an issue in the 2.2.3 release.

@baronfel
Copy link
Contributor

Same thing happens on the typescript-node templates on the latest release.

@wing328
Copy link
Contributor

wing328 commented Sep 19, 2017

@gordey4doronin
Copy link

@ranma42 @wing328 Can I ask to clarify a bit how to make the workaround you mentioned.

I suggest defining the map inline instead of a reference as a workaround

But it's already inlined, not referenced. 👇

As the issue says, I have this input yaml:

  GenericMap:
    additionalProperties:
      type: integer

And I want to have a generated result like this:

export interface GenericMap {
  [key: string]: number;
}

But getting this instead:

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

@stefanmeschke
Copy link
Contributor

Any updates here? :)

@naXa777
Copy link

naXa777 commented Sep 12, 2019

@ranma42 did you report this issue in swagger-api/swagger-parser?

@naXa777
Copy link

naXa777 commented Sep 12, 2019

I found it myself swagger-api/swagger-parser#401

@sammy-da
Copy link

Hello 👋
any updates on this?

@alois-git
Copy link

alois-git commented Jun 2, 2023

Same issue

1 similar comment
@threydor
Copy link

Same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants