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

Improving Nullable Field Handling for Better Developer Experience #4421

Open
4 tasks done
aress31 opened this issue Dec 18, 2024 · 1 comment
Open
4 tasks done

Improving Nullable Field Handling for Better Developer Experience #4421

aress31 opened this issue Dec 18, 2024 · 1 comment
Labels
bug needs triage Initial label given, to be assigned correct labels and assigned

Comments

@aress31
Copy link

aress31 commented Dec 18, 2024

Prerequisites

What theme are you using?

mui

Version

5.x

Current Behavior

Currently, to allow properties to accept null values, it is necessary to explicitly add null to the type. However, the required option already ensures that a non-null value is provided.

In my case, I pass null values through my form because the data is pulled directly from the database, and some columns are nullable.

At the moment, the process forces me to manually add null to the type for every field, which creates a poor developer experience (DX).

I suggest reversing the logic: make all fields nullable by default, and only fields that should not accept null values would need a not-null option.

Additionally, based on my tests, the required option still enforces a value even if the field allows null.

I would like to see a rework of the nullable logic to improve the developer experience.

Expected Behavior

No response

Steps To Reproduce

https://rjsf-team.github.io/react-jsonschema-form/#eyJmb3JtRGF0YSI6eyJpZCI6IjRlZTk4ZjI2LTg3MDItNGU2MC1iNjA1LTJlNTFhMTFlOWEwZCIsInN0YXR1cyI6bnVsbCwic3RhcnQiOm51bGwsImVuZCI6bnVsbH0sInNjaGVtYSI6eyJ0eXBlIjoib2JqZWN0IiwiZGVmaW5pdGlvbnMiOnsic3RhdHVzIjp7ImVudW0iOlsiYWN0aXZlIiwiY2FuY2VsbGVkIiwiY29tcGxldGVkIiwiaW5hY3RpdmUiLCJwZW5kaW5nIl19fSwicHJvcGVydGllcyI6eyJpZCI6eyJ0eXBlIjoic3RyaW5nIn0sInN0YXR1cyI6eyJ0eXBlIjpbInN0cmluZyIsbnVsbF0sIiRyZWYiOiIjL2RlZmluaXRpb25zL3N0YXR1cyJ9LCJzdGFydCI6eyJ0eXBlIjoic3RyaW5nIiwiZm9ybWF0IjoiZGF0ZSJ9LCJlbmQiOnsidHlwZSI6InN0cmluZyIsImZvcm1hdCI6ImRhdGUtdGltZSJ9fX0sInVpU2NoZW1hIjp7fSwidGhlbWUiOiJkZWZhdWx0IiwibGl2ZVNldHRpbmdzIjp7InNob3dFcnJvckxpc3QiOiJ0b3AiLCJ2YWxpZGF0ZSI6ZmFsc2UsImRpc2FibGVkIjpmYWxzZSwibm9IdG1sNVZhbGlkYXRlIjpmYWxzZSwicmVhZG9ubHkiOmZhbHNlLCJvbWl0RXh0cmFEYXRhIjpmYWxzZSwibGl2ZU9taXQiOmZhbHNlLCJleHBlcmltZW50YWxfZGVmYXVsdEZvcm1TdGF0ZUJlaGF2aW9yIjp7ImFycmF5TWluSXRlbXMiOiJwb3B1bGF0ZSIsImFsbE9mIjoic2tpcERlZmF1bHRzIiwiY29uc3RBc0RlZmF1bHRzIjoiYWx3YXlzIiwiZW1wdHlPYmplY3RGaWVsZHMiOiJwb3B1bGF0ZUFsbERlZmF1bHRzIiwibWVyZ2VEZWZhdWx0c0ludG9Gb3JtRGF0YSI6InVzZUZvcm1EYXRhSWZQcmVzZW50In0sImxpdmVWYWxpZGF0ZSI6dHJ1ZX19

Environment

Latest everything.

Anything else?

No response

@aress31 aress31 added bug needs triage Initial label given, to be assigned correct labels and assigned labels Dec 18, 2024
@kuhlaid
Copy link

kuhlaid commented Dec 20, 2024

@aress31, your schema should probably look like (note the null enum for status and the quoted "null" types):

{
  "type": "object",
  "definitions": {
    "status": {
      "enum": [
        null,
        "active",
        "cancelled",
        "completed",
        "inactive",
        "pending"
      ]
    }
  },
  "properties": {
    "id": {
      "type": "string"
    },
    "status": {
      "type": [
        "string",
        "null"
      ],
      "$ref": "#/definitions/status"
    },
    "start": {
      "type": [
        "string",
        "null"
      ],
      "format": "date"
    },
    "end": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug needs triage Initial label given, to be assigned correct labels and assigned
Projects
None yet
Development

No branches or pull requests

2 participants