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

Input type with Optional field breaks Playground #782

Open
jmaness opened this issue Oct 16, 2024 · 3 comments
Open

Input type with Optional field breaks Playground #782

jmaness opened this issue Oct 16, 2024 · 3 comments

Comments

@jmaness
Copy link

jmaness commented Oct 16, 2024

If a chain has an input type containing an optional field, the Playground page fails to load (blank page), and the following error is logged in the browser console:

index-400979f0.js:150 Uncaught Error: Unknown type: {"type":"null"}
    at VC (index-400979f0.js:150:3067)
    at Object.J6 [as uiSchema] (index-400979f0.js:150:3156)
    at bh (index-400979f0.js:148:40890)
    at index-400979f0.js:150:1495
    at Array.map (<anonymous>)
    at n0 (index-400979f0.js:150:1419)
    at index-400979f0.js:255:25928
    at z$ (index-400979f0.js:38:19538)
    at Uw (index-400979f0.js:40:3139)
    at p4 (index-400979f0.js:40:2351)

Example input type:

from pydantic import BaseModel
from typing import Optional


class Question(BaseModel):
    question: str
    datasource: Optional[str]

The generated input schema looks like:

{
  "properties": {
    "question": {
      "title": "Question",
      "type": "string"
    },
    "datasource": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ],
      "default": null,
      "title": "Datasource"
    }
  },
  "required": [
    "question"
  ],
  "title": "Question",
  "type": "object"
}

and the {"type":"null"} seems to cause an issue with jsonforms.

Should the generated input schema be the following instead?

{
  "properties": {
    "question": {
      "title": "Question",
      "type": "string"
    },
    "datasource": {
      "type": "string"
      "title": "Datasource"
    }
  },
  "required": [
    "question"
  ],
  "title": "Question",
  "type": "object"
}
@jmaness
Copy link
Author

jmaness commented Oct 16, 2024

From reading through https://json-schema.org/understanding-json-schema/reference/object#required, it seems like the generated schema using anyOf and {"type":"null"} should be valid for optional properties, so perhaps this is a bug in jsonforms after all.

@tdakanalis
Copy link

Any fix or workaround on this?

@eyurtsev
Copy link
Collaborator

eyurtsev commented Nov 5, 2024

duplicate of: #777

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants