Openapi-generator: [BUG] [Typescript-angular] Model not generated since it's a free-form object

Created on 10 Oct 2019  路  4Comments  路  Source: OpenAPITools/openapi-generator

Bug Report Checklist

  • [x] Have you provided a full/minimal spec to reproduce the issue?
  • [x] Have you validated the input using an OpenAPI validator (example)?
  • [x] What's the version of OpenAPI Generator used? 4.1.3
  • [x] Have you search for related issues/PRs? Not found
  • [ ] What's the actual output vs expected output?
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;
}

Bug

All 4 comments

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

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

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鈥檚 an alias for object.

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

Was this page helpful?
0 / 5 - 0 ratings