Skip to content

Wrong ? (optional) in generated models for schemas with inline object declaration #395

@GiacomoDM

Description

@GiacomoDM

In my OpenApi I have some components schemas with required properties that refers to properties inside an inline declaration, in some of the allOf list.
These required properties are wrongly ignored and the generated model will add the optional ? to the typescript interface.

Example component schema:

"BigDecimalInclusionAttributeFilter": {
        "required": ["name", "operator", "values"],
        "type": "object",
        "allOf": [
          {
            "$ref": "#/components/schemas/IFilter"
          },
          {
            "type": "object",
            "properties": {
              "name": {
                "type": "string"
              },
              "operator": {
                "type": "string",
                "enum": ["IN", "NOT_IN"]
              },
              "values": {
                "type": "array",
                "items": {
                  "type": "number"
                }
              }
            }
          }
        ]
      },

Will generate the following model:

import { IFilter } from '../models/i-filter';
export type BigDecimalInclusionAttributeFilter = IFilter & {
'name'?: string;
'operator'?: 'IN' | 'NOT_IN';
'values'?: Array<number>;
};

The "required": ["name", "operator", "values"] are ignored, probably because the required properties are not in the properties of the object, but are inside one of the allOf objects.

I would expect the required properties to be respected and the resulting type to be something like this:

import { IFilter } from '../models/i-filter';
export type BigDecimalInclusionAttributeFilter = IFilter & {
'name': string;
'operator': 'IN' | 'NOT_IN';
'values': Array<number>;
};

Am I missing somethig?
Do you need something more?

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions