Skip to content

Commit

Permalink
Use oneOf for enums when possible (GREsau#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahl committed Sep 26, 2021
1 parent dec8bcc commit 0a1200b
Show file tree
Hide file tree
Showing 15 changed files with 305 additions and 279 deletions.
10 changes: 5 additions & 5 deletions schemars/tests/expected/deprecated-enum.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "DeprecatedEnum",
"deprecated": true,
"anyOf": [
"oneOf": [
{
"type": "string",
"enum": [
Expand All @@ -24,13 +24,13 @@
"foo"
],
"properties": {
"foo": {
"type": "integer",
"format": "int32"
},
"deprecated_field": {
"deprecated": true,
"type": "boolean"
},
"foo": {
"type": "integer",
"format": "int32"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion schemars/tests/expected/doc_comments_enum.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "This is the enum's title",
"description": "This is the enum's description.",
"anyOf": [
"oneOf": [
{
"type": "string",
"enum": [
Expand Down
76 changes: 38 additions & 38 deletions schemars/tests/expected/enum-adjacent-tagged-duf.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Adjacent",
"anyOf": [
"oneOf": [
{
"type": "object",
"required": [
Expand All @@ -24,17 +24,17 @@
"t"
],
"properties": {
"t": {
"type": "string",
"enum": [
"StringMap"
]
},
"c": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"t": {
"type": "string",
"enum": [
"StringMap"
]
}
},
"additionalProperties": false
Expand All @@ -46,14 +46,14 @@
"t"
],
"properties": {
"c": {
"$ref": "#/definitions/UnitStruct"
},
"t": {
"type": "string",
"enum": [
"UnitStructNewType"
]
},
"c": {
"$ref": "#/definitions/UnitStruct"
}
},
"additionalProperties": false
Expand All @@ -65,14 +65,14 @@
"t"
],
"properties": {
"c": {
"$ref": "#/definitions/Struct"
},
"t": {
"type": "string",
"enum": [
"StructNewType"
]
},
"c": {
"$ref": "#/definitions/Struct"
}
},
"additionalProperties": false
Expand All @@ -84,28 +84,28 @@
"t"
],
"properties": {
"t": {
"type": "string",
"enum": [
"Struct"
]
},
"c": {
"type": "object",
"required": [
"bar",
"foo"
],
"properties": {
"bar": {
"type": "boolean"
},
"foo": {
"type": "integer",
"format": "int32"
},
"bar": {
"type": "boolean"
}
},
"additionalProperties": false
},
"t": {
"type": "string",
"enum": [
"Struct"
]
}
},
"additionalProperties": false
Expand All @@ -117,12 +117,6 @@
"t"
],
"properties": {
"t": {
"type": "string",
"enum": [
"Tuple"
]
},
"c": {
"type": "array",
"items": [
Expand All @@ -136,6 +130,12 @@
],
"maxItems": 2,
"minItems": 2
},
"t": {
"type": "string",
"enum": [
"Tuple"
]
}
},
"additionalProperties": false
Expand All @@ -162,39 +162,39 @@
"t"
],
"properties": {
"c": {
"type": "integer",
"format": "int32"
},
"t": {
"type": "string",
"enum": [
"WithInt"
]
},
"c": {
"type": "integer",
"format": "int32"
}
},
"additionalProperties": false
}
],
"definitions": {
"UnitStruct": {
"type": "null"
},
"Struct": {
"type": "object",
"required": [
"bar",
"foo"
],
"properties": {
"bar": {
"type": "boolean"
},
"foo": {
"type": "integer",
"format": "int32"
},
"bar": {
"type": "boolean"
}
}
},
"UnitStruct": {
"type": "null"
}
}
}

0 comments on commit 0a1200b

Please sign in to comment.