Skip to content

Commit

Permalink
schema-inference: do not mark any property as required
Browse files Browse the repository at this point in the history
  • Loading branch information
mdibaiee committed May 31, 2023
1 parent 34a62de commit c209ee2
Show file tree
Hide file tree
Showing 17 changed files with 3 additions and 103 deletions.
4 changes: 3 additions & 1 deletion crates/schema-inference/src/inference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ fn infer_object(inner: &serde_json::Map<String, JsonValue>) -> Shape {
.iter()
.map(|(key, value)| ObjProperty {
name: key.to_owned(),
is_required: true,
// We don't mark any non-key property as required since it is hard to revert requirement on a
// property if we later realise that this value can sometimes be null
is_required: false,
shape: infer_shape(value),
})
.collect();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ expression: schema
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": [
"a_null_value",
"boolean",
"number",
"string"
],
"properties": {
"a_null_value": {
"type": "null"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,12 @@ expression: schema
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": [
"a",
"b",
"c"
],
"properties": {
"a": {
"type": [
"integer",
"object"
],
"required": [
"imaginary",
"real"
],
"properties": {
"imaginary": {
"type": "integer"
Expand All @@ -37,9 +28,6 @@ expression: schema
"boolean",
"object"
],
"required": [
"truthful"
],
"properties": {
"harmless": {
"type": "string"
Expand All @@ -58,9 +46,6 @@ expression: schema
},
"c": {
"type": "object",
"required": [
"inner"
],
"properties": {
"even_more_optional": {
"type": "boolean"
Expand All @@ -71,9 +56,6 @@ expression: schema
"object",
"string"
],
"required": [
"details"
],
"properties": {
"details": {
"type": "string"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,9 @@ expression: schema
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": [
"author",
"id",
"tags",
"title"
],
"properties": {
"author": {
"type": "object",
"required": [
"contact",
"name"
],
"properties": {
"contact": {
"type": "string"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ expression: schema
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": [
"a",
"b",
"c",
"s"
],
"properties": {
"a": {
"type": "integer"
Expand All @@ -27,9 +21,6 @@ expression: schema
},
"c": {
"type": "object",
"required": [
"inner"
],
"properties": {
"inner": {
"type": [
Expand All @@ -48,9 +39,6 @@ expression: schema
"object",
"string"
],
"required": [
"sometimes"
],
"properties": {
"sometimes": {
"type": "string"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ expression: schema
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": [
"a"
],
"properties": {
"a": {
"type": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ expression: schema
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": [
"a"
],
"properties": {
"a": {
"type": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ expression: schema
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": [
"a"
],
"properties": {
"a": {
"type": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ expression: schema
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": [
"a"
],
"properties": {
"a": {
"type": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ expression: schema
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": [
"a"
],
"properties": {
"a": {
"type": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ expression: schema
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": [
"a"
],
"properties": {
"a": {
"type": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ expression: schema
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": [
"a"
],
"properties": {
"a": {
"type": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ expression: schema
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": [
"a"
],
"properties": {
"a": {
"type": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ expression: schema
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": [
"a"
],
"properties": {
"a": {
"type": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ expression: schema
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": [
"a"
],
"properties": {
"a": {
"type": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ expression: schema
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": [
"a"
],
"properties": {
"a": {
"type": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,59 +6,36 @@ expression: schema
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": [
"a",
"one"
],
"properties": {
"a": {
"type": "boolean"
},
"one": {
"type": "object",
"required": [
"b",
"two"
],
"properties": {
"b": {
"type": "integer"
},
"two": {
"type": "object",
"required": [
"c",
"three"
],
"properties": {
"c": {
"type": "number"
},
"three": {
"type": "object",
"required": [
"d",
"four"
],
"properties": {
"d": {
"type": "null"
},
"four": {
"type": "object",
"required": [
"e",
"five"
],
"properties": {
"e": {
"type": "boolean"
},
"five": {
"type": "object",
"required": [
"f"
],
"properties": {
"f": {
"type": "string"
Expand Down

0 comments on commit c209ee2

Please sign in to comment.