OpenAPITools / OpenAPITools/openapi-generator

[BUG][All] Models are not generated if "type": object and "additionalProperties": false in OAS 2

Open
#17,967 1 comment 0 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

Description

Models are not generated if "type": object "additionalProperties": false in OAS 2.
if "additionalProperties" is removed, the model will be generated correctly.
It occurs regardless of the generator.
The regression started since v7.0.0

openapi-generator version

latest - 7.4.0

OpenAPI declaration file content or url
{
   "swagger": "2.0",
   "info": {
      "title": "Test API",
      "version": "0.1"
   },
   "host": "http://test.local/api",
   "paths": {},
   "definitions": {
      "TimeSpanModel": {
         "type": "object",
         "additionalProperties": false,
         "required": [
            "totalMilliseconds"
         ],
         "properties": {
            "totalMilliseconds": {
               "type": "integer",
               "format": "int64"
            }
         }
      },
      "TimeSpanModelWithoutAdditionProperties": {
         "type": "object",
         "required": [
            "totalMilliseconds"
         ],
         "properties": {
            "totalMilliseconds": {
               "type": "integer",
               "format": "int64"
            }
         }
      },
      "OtherModel": {
         "type": "object",
         "properties": {
            "firstTimestamp": {
               "$ref": "#/definitions/TimeSpanModel"
            },
            "secondTimestamp": {
               "$ref": "#/definitions/TimeSpanModelWithoutAdditionProperties"
            }
         }
      }
   }
}
Generation Details

docker run --rm -v $PWD:/app openapitools/openapi-generator-cli generate -i /app/petstore.json -g typescript-axios -o /app/output

Steps to reproduce
Related issues/PRs

Not sure this PR is related but since it was added in 7.0.0 and contains many changes related to additionlProperties I assume it is related.
https://github.com/OpenAPITools/openapi-generator/pull/16227

Expected output vs Actual output

Actual:

/**
 * 
 * @export
 * @interface OtherModel
 */
export interface OtherModel {
    /**
     * 
     * @type {object}
     * @memberof OtherModel
     */
    'firstTimestamp'?: object;
    /**
     * 
     * @type {object}
     * @memberof OtherModel
     */
    'secondTimestamp'?: object;
    /**
     * 
     * @type {TimeSpanModelWithoutAdditionProperties}
     * @memberof OtherModel
     */
    'thirdTimestamp'?: TimeSpanModelWithoutAdditionProperties;
}
/**
 * 
 * @export
 * @interface TimeSpanModelWithoutAdditionProperties
 */
export interface TimeSpanModelWithoutAdditionProperties {
    /**
     * 
     * @type {number}
     * @memberof TimeSpanModelWithoutAdditionProperties
     */
    'totalMilliseconds': number;
}

Expected:

/**
 * 
 * @export
 * @interface OtherModel
 */
export interface OtherModel {
    /**
     * 
     * @type {TimeSpanModel}
     * @memberof OtherModel
     */
    'firstTimestamp'?: TimeSpanModel;
    /**
     * 
     * @type {TimeSpanModel}
     * @memberof OtherModel
     */
    'secondTimestamp'?: TimeSpanModel;
    /**
     * 
     * @type {TimeSpanModelWithoutAdditionProperties}
     * @memberof OtherModel
     */
    'thirdTimestamp'?: TimeSpanModelWithoutAdditionProperties;
}
/**
 * 
 * @export
 * @interface TimeSpanModel
 */
export interface TimeSpanModel {
    /**
     * 
     * @type {number}
     * @memberof TimeSpanModel
     */
    'totalMilliseconds': number;
}
/**
 * 
 * @export
 * @interface TimeSpanModelWithoutAdditionProperties
 */
export interface TimeSpanModelWithoutAdditionProperties {
    /**
     * 
     * @type {number}
     * @memberof TimeSpanModelWithoutAdditionProperties
     */
    'totalMilliseconds': number;
}

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

Reproduce the regression with the supplied OAS 2 declaration and the documented openapi-generator Docker command, comparing the generated typescript-axios output with the expected models. Start by tracing how definitions with additionalProperties: false are resolved, then add a regression test covering the declaration and verify that both referenced and standalone models are generated.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, 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.