Skip to content

[BUG] nullable types not applied to isNullable #2488

@CynicalBusiness

Description

@CynicalBusiness

Describe the bug.

The interpreter is currently, as far as I can tell, ignoring nullable properties on schemas, and therefor not updating isNullable on the resulting model.

My knowledge of the codebase is limtied, but the offending method appears to be interpretSchemaObject.

As a workaround, adding the following code to this function resolves the issue:

        if (schema.nullable) {
            model.addTypes('null');
        }

Though, I am unsure if this is the correct way to do it, so I haven't opened a PR with it directly.

This affects versions ^4.0.0 and ^5.0.0

Expected behavior

Properties whose schema has nullable: true should generated the corresponding nullable model type.

Screenshots

Example of incorrect TypeScript model generation:

    ServerEventsSubscriptionPayload:
      type: object
      properties:
        # ...
        visaToken:
          type: string
          nullable: true
      title: ServerEventsSubscriptionPayload
  export interface ServerEventsSubscriptionPayload {
    // ...
    visaToken?: string;
  }

And after the above fix is applied:

  export interface ServerEventsSubscriptionPayload {
    // ...
    visaToken?: string | null;
  }

How to Reproduce

  1. Generate TypeScript models from an asyncapi.yaml that includes a nullable: true property on a component.
  2. Observe missing | null

🖥️ Device Information [optional]

  • Operating System (OS): Windows 11
  • Browser: N/A
  • Browser Version: N/A

👀 Have you checked for similar open issues?

  • I checked and didn't find similar issue

🏢 Have you read the Contributing Guidelines?

Are you willing to work on this issue ?

Yes I am willing to submit a PR!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions