swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
16.74k stars 6.02k forks source link

[TypeScript] Free-Form object being generated incorrectly #9767

Open marcocunha opened 4 years ago

marcocunha commented 4 years ago
Description

I'm trying to generate the typescript models, based on the schemas defined in the YAML file, but there is a model (free-form object) that is not being properly generated and the typescript is generated like

export interface MyModel extends null<String, any> { 
  [key: string]: any;
}

while I was expecting something like:

export interface MylModel {
    [key: string]: any;
}

Is relevant to mention that this problem started happening after the migration from Swagger 2.x version to OpenAPI 3.0 and i also started using this new Swagger-codegen version

Swagger-codegen version

3.0.11

Swagger declaration file content or url
components:
  schemas:
    MyModel:
      type: object
      additionalProperties:
        type: object
      example:
        Sheet 1!A1: 0
        Sheet 1!A2: a text
Command line used for generation

mvn clean generate-resources

Steps to reproduce

Using a valid open API 3.0 YAML file, declare the schema referred above and generate the typescript model using the following pom configuration:

<plugin>
        <groupId>io.swagger.codegen.v3</groupId>
        <artifactId>swagger-codegen-maven-plugin</artifactId>
        <version>${swagger-codegen-maven-plugin.version}</version>
        <executions>
          <execution>
            <phase>generate-sources</phase>
            <goals>
              <goal>generate</goal>
            </goals>
            <configuration>
              <inputSpec>${basedir}/../schema/api.yaml</inputSpec>
              <output>${basedir}/src/app/shared/api</output>
              <language>typescript-angular</language>
              <generateApis>false</generateApis>
              <generateSupportingFiles>true</generateSupportingFiles>
              <generateModelDocumentation>false</generateModelDocumentation>
              <generateModelTests>false</generateModelTests>
              <generateSupportingFiles>false</generateSupportingFiles>
              <generateAliasAsModel>true</generateAliasAsModel>
              <modelPackage>models</modelPackage>
            </configuration>
          </execution>
        </executions>
      </plugin>
Related issues/PRs
Suggest a fix/enhancement
mateuszwinnicki commented 3 years ago

We have the same issue. +1

CapleIt commented 3 years ago

Any update on this team??

Burtan commented 3 years ago

Same issue with 3.0.25

gairon commented 3 years ago

The same problem

WWL-MikeRoberts commented 3 years ago

Can't use this library because of this issue.

andreseloysv commented 2 months ago

same issue with openapi-generator-cli 7.4.0