Forms & Parsing #181
Closed
ShubhranshuSanjeev
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
We are facing a lot of issues related to parsing of values given in form inputs, primarily reasons being,
I have tried to document most of what is required from our end to know about the JSON schema while handling the parsing/construction of context and overrides.
Additionally I have tried to come up with a way to solve the code fragmentation issue.
How a JSON schema looks (the part which is important)?
type
, can either be a string or an array of stringsAllowed values for
type
:SchemaType enum
Parsing (when type is known)
Steps:
Implementation
boolean, integer, number, null, string
: These can be directly parsed usingarray, object
:Impl for SchemaType enum
Which operators we are supporting?
Additional operators to be added:
has
Operators:
Operator enum (current version)
Bits on Json logic ()
===
: Only two operands<=
: 3 operandsin
: 2 operandshas
: 2 operandsContext Parsing (with operator as an additional parameter)
Get the Operator and the possible types
=== / has:
<=:
in:
JSON to Form input
These should work.
Form Trait
Implementation Overview
Creating new wrapper types for forms we have
Forms Types
NOTE: Implement
Form
trait for above mentioned typesImplement
TryFrom
trait for above mentioned types-
impl TryFrom<Context> for ContextForm
-
impl TryFrom<Override> for OverrideForm
(We don't have any concrete type for Override, Map<String, Value> is used)-
impl TryFrom<Variant> for VariantForm
-
impl TryFrom<Experiment> for ExperimentForm
Context -> ContextForm
Structure of JSON logic in Context
Information required from above JSON for ContextForm
Using how each operator dictates the data to be organized in JSON logic [mentioned above in Bits on JSON Logic] we can extract the required information i.e. operator, dimension name, dimension value
NOTE: We can look into restricting conditions written using JSON logic
Override -> OverrideForm
Trivial Map to Vector of key value entries conversion
Variant -> VariantForm and Experiment -> ExperimentForm, will build on top of Context and Override coversions
ContextForm's
parse
SchemaSpec
will beDimension
, we can find the required dimension's type from this.ParseOutput
can beVec<(String, Operator, serde_json::Value)>
Details[Context Parsing (with operator as an additional parameter)]
OverrideForm's
parse
SchemaSpec
will beDefaultConfig
, we can find the required config_key's type from this.ParseOutput
can beVec<(String, serde_json::Value)>
Details [Parsing (when type is known)]
VariantForm's
parse
Reuses OverrideForm's parse
ExperimentForm's
parse
Reuses ContextForm's and VariantForm's parse
Beta Was this translation helpful? Give feedback.
All reactions