Same enum / oneof used in several

my form contains several time dropdown list with same enumerations
for example, the form ask for your birth country, the birth country of your mother, the birth country of your father…
the country list has 195 items : I’d like to to have to repeat that each time in the schema.json (to easily be able to update the list)
what i the most efficient way (in term of display overhead and easy to implement) to do that ?
should I use a custom renderer ? in this case, how to populate the enum ?
should I use a kind of include in the schema.json ?

Thanks !

[i’ll have different basic questions during the following days to be sure to use in the best way jsonforms. I’ve prefer to ask them separately ; as is, other persons will be more easily be able to reuse the replies !]

Hi @clysss,

For this you can use $ref within the JSON Schema, see here.

Ah great ! can’t be more easy !
Thx

Hello,
I used this schema :
“Certification”: {
“title”: “Certification/Trusted 3rd party pledge”,
“type”: “object”,
“required”: [“t01”, “t02”, “t03”, “t04”, “t06”, “t07”, “t08”],
“properties”: {
“t01”: {
“title”: “Are the design team certification or audit?”,
“type”: “string”,
“$ref”: “#/definitions/ynu”,
“pt”: “2”,
“ve”: “1”
},
[…]

“definitions”: {
“ynu”: {
“enum”: [“yes”, “no”, “?unknown”]
},

the renderer component is correctly displayed with the enum list BUT the label is not correctly displayed : T 01 is displayed instead of the title
Should I open a bug in github?

Hi @clysss,

It’s more of a missing feature. In older JSON Schema specs $ref was defined to exclusively link to subschemas and no other properties were allowed next to it.

That changed at some point, but our code mostly did not. So whenever we encounter a $ref we usually just resolve it and don’t keep the “caller” context. That’s the case here too which is why the title is lost.

If you or someone else is interested, we would welcome contributions to implement some form of resolving context resolution.

Ok. I’ll have a look to compare with my own component who is working ““correctly””

when I use

    "type": "array",
      "items": {
        "type": "string",
        "$ref": "#/definitions/countries"
      },

the context is correctly passed but not when I’m using type:string
Could you point me where is the 2 codes that I should compare ?
Thx

?

if yes couldn’t we use lodash merge? or resolveAndMakeSchemaSelfContained like in jsonforms-react-material-tree-renderer/src/services/property.util.ts at b0fa4d65e6e976a72c8001508e62fdfa8743ab00 · eclipsesource/jsonforms-react-material-tree-renderer · GitHub

not sure to understand the line 96…

You linked to a special resolving case which we no longer use. findAllRefs is only there for backward compatibility and will be removed at some point.

Here you can find our generic $ref resolver. It just follows the pointer without considering any overriding mechanism.

To enable the use case of overriding properties via $ref I see two potential approaches:

  • Instead of just returning the pointed to schema, we could use a merge approach as you suggested. However the returned schema is then no longer part of the original schema handed in. This will break in cases where object identity is expected.
  • Alternatively we could return a tuple instead of just the resolved schema, e.g. the schema and a context containing all the overriding properties, or the resolved schema and a “projectedSchema”

Perhaps we could have a third approach in this case. (Not sure to have integrally understood so don’t hesitate to tell that what I’m saying is just stupid!!)

As it seems that when it’s an array, everything is ok, I understand this situation like when we want to have a $ref parsed as a subschema with override properties, we could use a new keyword like “sub” in the schema?

Not sure how to explain that!
I don’t understand why array is correctly passing enum but not oneof for example as both are subschema…

Hi @clysss,

Maybe I’m just missing something.

Can you explain in more detail what you are referring to? What do you mean by context and what is and what is not working.

Next Time, I’ll give you access to my brain, it will be easier!! Before that, I can give you a codesandbox link!!

To resume, I’ve a multi select component (the code I’ve provided on another message here) " compatible" with uniqueItems
And with this, the ref is working correctly inside array

in other terms, context is for me title and other params including my own ones
so with :slight_smile:
“v09”: {
“title”: “Is the VENDOR currently member of the following professional organization ?”,
“description”: “if you’re member of others organisations’ section”,
“qU”: “member of :”,
“type”: “array”,
“uniqueItems”: true,
“items”: {
“type”: “string”,
“$ref”: “#/definitions/cyberOrg”
},

the title and description are correctly received by my (custom) component (and it’s seems ok with the default uniqueitems also)

if I replace array with oneOf (and remove uniqueItems), I’ve not been able to make it work