amzn / selling-partner-api-models

This repository contains OpenAPI models for developers to use when developing software to call Selling Partner APIs.
Apache License 2.0
596 stars 730 forks source link

Product Type Schema Attribute Field Required Issue #4030

Closed abc1978785513 closed 2 months ago

abc1978785513 commented 3 months ago

How to parse the complex relationships in JSON following anyOf, allOf, if then? Is there an official tool for this?

chapmanjw commented 2 months ago

@abc1978785513 What are you trying to accomplish? For handling the complex conditional logic in the JSON Schemas, we typically recommend using open-source libraries for validation or rendering: https://json-schema.org/implementations. Reverse engineering JSON Schema for custom mappings, etc., to custom code is a bit of a pain. Though, as long as you follow whats defined in the JSON Schema specification, it's doable.

For use-cases where developers are mapping JSON Schema rules to their own data models, we are exploring alternative representations of schema rules that are easier to write code against. However, pursuing those would diverge from following the JSON Schema specification. Understanding your use-case may help us better to understand what you're trying to accomplish and what representation of these rules may be easiest to integrate with.

abc1978785513 commented 2 months ago

@chapmanjw I want to implement dynamic loading. I need to figure out the relationships so that when certain attribute fields are selected, other related fields will be set as required.

chapmanjw commented 2 months ago

@abc1978785513 I believe some of the open source form libraries use validation to trigger showing conditional attributes (like https://rjsf-team.github.io/react-jsonschema-form/). One option could be to follow a similar approach, where you run the schema validator and map certain error conditions to displaying an attribute field as required in your application conditionally.

Another option could be to to parse the JSON Schema conditionals for the "then" statements containing "required" statements, marking anything that is referenced in those as "conditionally required" in your UI.