pratikpakhale / fieldactivity-parser

A parser for the JSON schema in the PEcAn fieldactivity app
https://fieldobservatory.org/fieldapp
0 stars 0 forks source link

Inconsistencies in JSON Schema #1

Open pratikpakhale opened 4 months ago

pratikpakhale commented 4 months ago

I have found the following inconsistensies in the JSON schema which throws errors while parsing it. I have conditional renders and fallbacks for now, but we need to fix them before moving forward -

  1. Issue - Choosing a subfield oneOf select box is rendered seperately but a type element is also present in the properties. We need to link this type element with the oneOf field in the schema somehow. so that we can prevent multiple renders. Where it is - eg. #fertilizer, fertilizer_type property and external oneOf field . It is possible that this occurs at other places Possible solution - Remove this external oneOf and replace it with fertilizer_type

  2. Issue - Some titles are missing to elements Where it is - At fertilizer_applic_method and many more

  3. Issue - The elements are not inside the properties field Where it is - soil amendment in #fertilizer>oneOf

  4. Issue - Select multiple options from the select box and render a data table to get inputs. Where is is expected - harvested items in #harvest>properties if multiple crops are selected, then display a data table to get inputs for all the crops Solution - Add one more field which will tell where a selec box is to be chosen multiple and the data input also must be referenced to this field of harvest items so that it will be generated for multiple elements

  5. Issue - Lack of titles for dropdown choices Where it is - #grazing

olli4 commented 2 months ago
  1. Issue - Choosing a subfield oneOf select box is rendered seperately but a type element is also present in the properties.

I don't see the problem here. For example in #fertilizer the type of the fertilizer_type property resides only in properties/fertilizer_type/type. Then depending on the choice of the value of "fertilizer_type", there may be different additional properties. These reside in properties in each #fertilizer/oneOf where properties/fertilizer_type/const is used to choose the right element of the oneOf. The fertilizer_type property has the role of the discriminator object of OpenAPI based on which additional properties are introduced.

  1. Issue - Some titles are missing to elements

Whenever this is the case, the property key can be used as a fall-back title for a property, and value of the const can be used as a fall-back title for the title of a choice. When a title translation is missing, the english title can be used as a fallback.

As to your example however, in #fertilizer/fertilizer_applic_method the title is not missing as it resides in its allOf[0]. This is the title for the property, and the tiles in the elements of #/$defs/fertilizer_applic_method/oneOf are for the choices.

  1. Issue - The elements are not inside the properties field

Right, I have now moved fertilizer_material and fertilizer_material_source into properties.

  1. Issue - Select multiple options from the select box and render a data table to get inputs.

The harvest_list propety of #harvest is of type array and its elements are objects that have properties. The type array should be enough to determine that there may be multiple harvested crops. I don't think it is necessary to treat a single harvested crop (an array of length 1) differently than multiple harvested crops (an array of length more than 1). I am not sure what is the best UI approach for adding or removing elements to/from the array, and whether any translated text (maybe to be put to an x-ui) is needed for these actions.

  1. Issue - Lack of titles for dropdown choices

Elements of "#grazing/properties/grazing_species_age_group/oneOf" are indeed missing titles. See my comment about fallbacks under issue 2. However, I have now added the english titles for convenience.

pratikpakhale commented 2 months ago
  1. I don't see the problem here. For example in #fertilizer the type of the fertilizer_type property resides only in properties/fertilizer_type/type. Then depending on the choice of the value of "fertilizer_type", there may be different additional properties. These reside in properties in each #fertilizer/oneOf where properties/fertilizer_type/const is used to choose the right element of the oneOf. The fertilizer_type property has the role of the discriminator object of OpenAPI based on which additional properties are introduced.

Yes, this makes sense. However can we have something to bind the discriminator to the oneOf which will let us know if the current element is the discriminator for parent oneOf. Let's discuss this in today's meeting.

  1. Whenever this is the case, the property key can be used as a fall-back title for a property, and value of the const can be used as a fall-back title for the title of a choice. When a title translation is missing, the english title can be used as a fallback. As to your example however, in #fertilizer/fertilizer_applic_method the title is not missing as it resides in its allOf[0]. This is the title for the property, and the tiles in the elements of #/$defs/fertilizer_applic_method/oneOf are for the choices.

Yes, currently my fallback works in more or less the same way. Also thanks for pointing out that [0] of allOf holds the title for the element.

  1. Right, I have now moved fertilizer_material and fertilizer_material_source into properties.

Thank you!

  1. Issue - Select multiple options from the select box and render a data table to get inputs.

The harvest_list propety of #harvest is of type array and its elements are objects that have properties. The type array should be enough to determine that there may be multiple harvested crops. I don't think it is necessary to treat a single harvested crop (an array of length 1) differently than multiple harvested crops (an array of length more than 1). I am not sure what is the best UI approach for adding or removing elements to/from the array, and whether any translated text (maybe to be put to an x-ui) is needed for these actions.

Yes, this we have to discuss once how are we going to proceed with data of such format.

  1. Issue - Lack of titles for dropdown choices Elements of "#grazing/properties/grazing_species_age_group/oneOf" are indeed missing titles. See my comment about fallbacks under issue 2. However, I have now added the english titles for convenience.

Thanks! Done.

olli4 commented 2 months ago

I have now updated the schema with new x-ui properties total_of_list and total_of_property in each total, for example:

"harvest_yield_harvest_dw_total": {
    "title": "yield, total dry weight (kg/ha)",
    "title2": "total yield, dry weight (kg/ha)",
    "title_fi": "sato, kuivapaino yhteensä (kg/ha)",
    "title2_fi": "kokonaissato, kuivapaino (kg/ha)",
    "title_sv": "totala skörden, torrvikt (kg/ha)",
    "type": "number",
    "minimum": 0,
    "x-ui": {
        "unit": "kg/ha",
        "unitless_title": "yield, total dry weight",
        "unitless_title2": "total yield, dry weight",
        "unitless_title_fi": "sato, kuivapaino yhteensä",
        "unitless_title2_fi": "kokonaissato, kuivapaino",
        "unitless_title_sv": "totala skörden, torrvikt",
        "total_of_list": "harvest_list",
        "total_of_property": "harvest_yield_harvest_dw"
    }
},