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

Handling of JSON Schema oneOf #373

Closed
MrSaints opened this issue Dec 13, 2017 · 10 comments
Closed

Handling of JSON Schema oneOf #373

MrSaints opened this issue Dec 13, 2017 · 10 comments
Assignees
Labels
Type: Feature New features and feature requests

Comments

@MrSaints
Copy link
Contributor

MrSaints commented Dec 13, 2017

In terms of UI, I take it that currently, only the first 'type' is shown in a oneOf, is that right?

If so, are there any plans to display multiple types? I can imagine having a switch that determines which type is shown in the UI.

@radekmie radekmie self-assigned this Dec 13, 2017
@radekmie radekmie added the Type: Feature New features and feature requests label Dec 13, 2017
@radekmie
Copy link
Contributor

Hi @MrSaints. You mean SimoleSchema or JSON Schema? I’m not sure as title and link are a bit misleading.

@MrSaints
Copy link
Contributor Author

MrSaints commented Dec 13, 2017

@radekmie, JSON Schema. But I take it that it behaves in the frontend similar to how Simple Schema behaves (because they're just adapters) ?

@radekmie
Copy link
Contributor

Yep, true - I just wanted to be sure.

I think it'll work with specified fields - <AutoField /> definitely won't know about it automatically. Simply try it and let me know, how it worked. Another option is to try <AutoField fieldType={Number} /> or another type, because that's the way how the field component is determined.

@MrSaints
Copy link
Contributor Author

@radekmie Ah OK! Yeah, I tried it, and it only returns the first "object" in a JSON schema oneOf. There's no option to switch between several types.

@radekmie
Copy link
Contributor

radekmie commented Dec 13, 2017

So you have multiple types of objects, not completely different types?

EDIT: Could you post an example of how you've tested it?

@MrSaints
Copy link
Contributor Author

@radekmie Something like below:

{
    "description": "Test Description",
    "properties": {
        "test": {
            "oneOf": [
                {
                    "properties": {
                        "test_1": {
                            "title": "Test 1",
                            "type": "string"
                        }
                    },
                    "required": [],
                    "title": "Type 1 Properties",
                    "type": "object"
                },
                {
                    "properties": {
                        "test_2": {
                            "title": "Test 2",
                            "type": "string"
                        }
                    },
                    "required": [],
                    "title": "Type 2 Properties",
                    "type": "object"
                }
            ]
        }
    },
    "title": "Test Title",
    "type": "object"
}

When rendered using uniforms, only fields for Type 1 Properties are displayed.

@radekmie
Copy link
Contributor

radekmie commented Dec 13, 2017

Well, this one will be tricker. The one solution I see right now is to create a custom field. Example:

const NthTypeObjectField = props =>
  <AutoFields fields={Object.keys(props.field.oneOf[props.N].properties)} />
;

<NthTypeObjectField name="test" N={0} />

EDIT: I didn't test it.

@radekmie
Copy link
Contributor

@MrSaints?

@radekmie
Copy link
Contributor

No response so far; I assume it's working. I'm closing but if it's not working - we'll continue digging in.

@MrSaints
Copy link
Contributor Author

MrSaints commented Jan 1, 2018

Sorry for the late response. I didn't give it a try yet, but I'm sure if I tinkered with the low-level components, I could get something out of it. I was just wondering if it was already there out-of-the-box. Thanks anyway.

@Monteth Monteth added this to Closed in Open Source (migrated) Jun 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature New features and feature requests
Projects
Archived in project
Development

No branches or pull requests

3 participants
@MrSaints @radekmie and others