OpenAPITools / OpenAPITools/openapi-generator

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

Open
#4,119 8 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used? 4.1.3
  • 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;
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the typescript-angular generator and reproduce the issue using the supplied MyModel schema and Maven configuration with mvn clean generate-resources. Check how the generator handles free-form objects with additionalProperties; done means the generated output includes a MyModel interface with the expected string index signature.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, typescript
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.