Skip to content

Invalid TS models when properties are nullable #9024

Open
@TheMatrix97

Description

@TheMatrix97

Hi! It seems the openapi connector is not setting the correct TS type when setting true the nullable flag

For example, with the following JSON OpenAPI definition model:

      "TestObject": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "nullable": true,
             "default": null,
            "description": "Test property",
            "example": null
          },

It creates a model with the following property:

  @property({jsonSchema: {
  type: [
    'string',
    'null',
  ],
  default: null,
  description: 'Specific endpoint for this queue, if not specified, the generic endpoint for this service will be used',
}})
  endpoint?: string = null;

Obviously, as endpoint is set as string, it throws a TS Check error in build time:
error TS2322: Type 'null' is not assignable to type 'string | undefined'.

Why isn't setting the property type correctly, whereas in the type annotation seems to be aware of it?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Icebox

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions