Skip to content

Nullable type support for 'anyOf' fields with two values #4843

@aringeri

Description

@aringeri

Prerequisites

What theme are you using?

shadcn

What is your question?

Hello,

I have a specific use-case where my nullable types are represented with an anyOf but do not want to render them as a drop-down with two options (null, string).

For context, I am using FastAPI to generate an OpenAPI/JSONSchema specification for my backend API. Using FastAPI, Nullable/Optional properties are generated into JSONSchema as below:

"name": {
  "anyOf": [
    {
      "type": "string"
    },
    {
      "type": "null"
    }
  ],
  "title": "Name",
  "description": "A name of a user"
}

I understand that react-jsonschema-form is expecting nullable types to use an array (in order to render a single textbox) as below:

"name": {
  "type": [ "string", "null" ],
  "title": "Name",
  "description": "A name of a user"
}

Is there any way to configure react-jsonschema-form for the first case to render only a single text box? I see this as a specific case where there are only two options in an anyOf/oneOf property, and one of those options is null.

Any help would be appreciated!

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs triageInitial label given, to be assigned correct labels and assignedquestion

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions