OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.24k stars 6.43k forks source link

[BUG] [Typescript-angular] Model not generated since it's a free-form object #4119

Open marcocunha opened 4 years ago

marcocunha commented 4 years ago

Bug Report Checklist

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 generated and according to the log:

[INFO] Model MyModel not generated since it's a free-form object

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 openapi-generator version

openapi-generator version

4.1.3

OpenAPI 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>org.openapitools</groupId>
        <artifactId>openapi-generator-maven-plugin</artifactId>
        <version>${openapi-generator-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>
              <generatorName>typescript-angular</generatorName>
              <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

I was expecting a typescript similar to:

export interface MyModel {
    [key: string]: any;
}
macjohnny commented 4 years ago

I guess this is not specific to the typescript-angular generator but a general issue. @marcocunha would you like to implement a fix?

syndic8myles commented 4 years ago

I can confirm this is a general typescript wide issue. My guess is somewhere in the DefaultCodegen class file

bodograumann commented 4 years ago

It is actually true for all templates: https://github.com/OpenAPITools/openapi-generator/blob/3adfdfafea183dfc4a1edf9a8df42f68657f662c/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java#L448-L450

Not sure what the intention was, but maybe this should also be handled with generateAliasAsModel, as it’s an alias for object.

bohndthi commented 4 years ago

I would love to see a soltution for the bug! Any Progress so far?

benmoeARZ commented 3 years ago

We are facing the same issue. any news?

bodograumann commented 3 years ago

The example in the original post seems invalid. I have created a working example here: https://github.com/bodograumann/openapi-generator-issue-4119 As you can see there are no models generated.

Unfortunately I can currently not develop on openapi-generator due to #8455.

spacether commented 3 years ago

@bodograumann this happens when your java version is 10. Can you switch your java version to v11?

protoEvangelion commented 10 months ago

I was still getting the same free-form error as of openapi 3.0 and generator-cli 6.2 with typescript-fetch. Adding this option to the generator caused the model to be extracted for me:

--additional-properties=generateAliasAsModel=true