Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
orenklein opened this issue Feb 26, 2024 · 1 comment

Comments

@orenklein
Copy link

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.
#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;
}
@martin-mfg
Copy link
Contributor

martin-mfg commented Mar 25, 2024

Thanks for the report!
This problem is caused by #15644, specifically by this change. I don't know what was the reason for this change. Do you remember, @wing328?

PS: Although I guess it's correct that the generated model should not be a MapSchema. We just need to ensure that it is still being generated at all.

The problem seems to be that the parser returns an instance of MapSchema, but we don't want to treat the schema as map.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants