Skip to content

Commit

Permalink
Add #[schemars(extend("key" = value))] attribute (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
GREsau authored Jun 5, 2024
1 parent 97b70aa commit 840315b
Show file tree
Hide file tree
Showing 18 changed files with 527 additions and 26 deletions.
4 changes: 2 additions & 2 deletions schemars/tests/expected/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
"default": false
},
"my_optional_string": {
"default": null,
"type": [
"string",
"null"
]
],
"default": null
},
"my_struct2": {
"$ref": "#/$defs/MyStruct2",
Expand Down
101 changes: 101 additions & 0 deletions schemars/tests/expected/extend_enum_adjacent.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Adjacent",
"oneOf": [
{
"type": "object",
"properties": {
"t": {
"type": "string",
"enum": [
"Unit"
]
}
},
"required": [
"t"
],
"foo": "bar"
},
{
"type": "object",
"properties": {
"t": {
"type": "string",
"enum": [
"NewType"
]
},
"c": true
},
"required": [
"t",
"c"
],
"foo": "bar"
},
{
"type": "object",
"properties": {
"t": {
"type": "string",
"enum": [
"Tuple"
]
},
"c": {
"type": "array",
"prefixItems": [
{
"type": "integer",
"format": "int32"
},
{
"type": "boolean"
}
],
"minItems": 2,
"maxItems": 2
}
},
"required": [
"t",
"c"
],
"foo": "bar"
},
{
"type": "object",
"properties": {
"t": {
"type": "string",
"enum": [
"Struct"
]
},
"c": {
"type": "object",
"properties": {
"i": {
"type": "integer",
"format": "int32"
},
"b": {
"type": "boolean"
}
},
"required": [
"i",
"b"
]
}
},
"required": [
"t",
"c"
],
"foo": "bar"
}
],
"foo": "bar"
}
73 changes: 73 additions & 0 deletions schemars/tests/expected/extend_enum_external.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "External",
"oneOf": [
{
"type": "string",
"const": "Unit",
"foo": "bar"
},
{
"type": "object",
"properties": {
"NewType": true
},
"required": [
"NewType"
],
"additionalProperties": false,
"foo": "bar"
},
{
"type": "object",
"properties": {
"Tuple": {
"type": "array",
"prefixItems": [
{
"type": "integer",
"format": "int32"
},
{
"type": "boolean"
}
],
"minItems": 2,
"maxItems": 2
}
},
"required": [
"Tuple"
],
"additionalProperties": false,
"foo": "bar"
},
{
"type": "object",
"properties": {
"Struct": {
"type": "object",
"properties": {
"i": {
"type": "integer",
"format": "int32"
},
"b": {
"type": "boolean"
}
},
"required": [
"i",
"b"
]
}
},
"required": [
"Struct"
],
"additionalProperties": false,
"foo": "bar"
}
],
"foo": "bar"
}
55 changes: 55 additions & 0 deletions schemars/tests/expected/extend_enum_internal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Internal",
"oneOf": [
{
"type": "object",
"properties": {
"typeProperty": {
"type": "string",
"const": "Unit"
}
},
"required": [
"typeProperty"
],
"foo": "bar"
},
{
"type": "object",
"properties": {
"typeProperty": {
"type": "string",
"const": "NewType"
}
},
"required": [
"typeProperty"
],
"foo": "bar"
},
{
"type": "object",
"properties": {
"i": {
"type": "integer",
"format": "int32"
},
"b": {
"type": "boolean"
},
"typeProperty": {
"type": "string",
"const": "Struct"
}
},
"required": [
"typeProperty",
"i",
"b"
],
"foo": "bar"
}
],
"foo": "bar"
}
46 changes: 46 additions & 0 deletions schemars/tests/expected/extend_enum_untagged.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Untagged",
"anyOf": [
{
"type": "null",
"foo": "bar"
},
{
"foo": "bar"
},
{
"type": "array",
"prefixItems": [
{
"type": "integer",
"format": "int32"
},
{
"type": "boolean"
}
],
"minItems": 2,
"maxItems": 2,
"foo": "bar"
},
{
"type": "object",
"properties": {
"i": {
"type": "integer",
"format": "int32"
},
"b": {
"type": "boolean"
}
},
"required": [
"i",
"b"
],
"foo": "bar"
}
],
"foo": "bar"
}
27 changes: 27 additions & 0 deletions schemars/tests/expected/extend_struct.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Struct",
"type": "object",
"properties": {
"value": {
"foo": "bar"
},
"int": {
"type": "overridden",
"format": "int32"
}
},
"required": [
"value",
"int"
],
"msg": "hello world",
"obj": {
"array": [
null,
null
]
},
"3": 3.0,
"pi": 3.14
}
6 changes: 3 additions & 3 deletions schemars/tests/expected/from_value_2019_09.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
},
"my_tuple": {
"type": "array",
"minItems": 2,
"maxItems": 2,
"items": [
{
"type": "string",
Expand All @@ -44,9 +46,7 @@
{
"type": "integer"
}
],
"maxItems": 2,
"minItems": 2
]
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions schemars/tests/expected/from_value_draft07.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
},
"my_tuple": {
"type": "array",
"minItems": 2,
"maxItems": 2,
"items": [
{
"type": "string",
Expand All @@ -44,9 +46,7 @@
{
"type": "integer"
}
],
"maxItems": 2,
"minItems": 2
]
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions schemars/tests/expected/from_value_openapi3.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
},
"my_tuple": {
"type": "array",
"minItems": 2,
"maxItems": 2,
"items": [
{
"type": "string",
Expand All @@ -46,9 +48,7 @@
{
"type": "integer"
}
],
"maxItems": 2,
"minItems": 2
]
}
}
}
Expand Down
Loading

0 comments on commit 840315b

Please sign in to comment.