Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions fixtures/allow_additional_props.json
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,17 @@
},
"type": "array"
},
"deprecated_field": {
"type": "string",
"deprecated": true
},
"deprecated_slice": {
"items": {
"type": "string"
},
"type": "array",
"deprecated": true
},
"anything": true,
"raw": true
},
Expand All @@ -222,6 +233,8 @@
"Baz",
"color",
"roles",
"deprecated_field",
"deprecated_slice",
"raw"
]
}
Expand Down
13 changes: 13 additions & 0 deletions fixtures/defaults_expanded_toplevel.json
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,17 @@
},
"type": "array"
},
"deprecated_field": {
"type": "string",
"deprecated": true
},
"deprecated_slice": {
"items": {
"type": "string"
},
"type": "array",
"deprecated": true
},
"anything": true,
"raw": true
},
Expand All @@ -223,6 +234,8 @@
"Baz",
"color",
"roles",
"deprecated_field",
"deprecated_slice",
"raw"
]
}
13 changes: 13 additions & 0 deletions fixtures/ignore_type.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,17 @@
},
"type": "array"
},
"deprecated_field": {
"type": "string",
"deprecated": true
},
"deprecated_slice": {
"items": {
"type": "string"
},
"type": "array",
"deprecated": true
},
"anything": true,
"raw": true
},
Expand All @@ -217,6 +228,8 @@
"Baz",
"color",
"roles",
"deprecated_field",
"deprecated_slice",
"raw"
]
}
Expand Down
13 changes: 13 additions & 0 deletions fixtures/no_reference.json
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,17 @@
},
"type": "array"
},
"deprecated_field": {
"type": "string",
"deprecated": true
},
"deprecated_slice": {
"items": {
"type": "string"
},
"type": "array",
"deprecated": true
},
"anything": true,
"raw": true
},
Expand All @@ -212,6 +223,8 @@
"Baz",
"color",
"roles",
"deprecated_field",
"deprecated_slice",
"raw"
]
}
13 changes: 13 additions & 0 deletions fixtures/no_reference_anchor.json
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,17 @@
},
"type": "array"
},
"deprecated_field": {
"type": "string",
"deprecated": true
},
"deprecated_slice": {
"items": {
"type": "string"
},
"type": "array",
"deprecated": true
},
"anything": true,
"raw": true
},
Expand All @@ -214,6 +225,8 @@
"Baz",
"color",
"roles",
"deprecated_field",
"deprecated_slice",
"raw"
]
}
11 changes: 11 additions & 0 deletions fixtures/required_from_jsontags.json
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,17 @@
},
"type": "array"
},
"deprecated_field": {
"type": "string",
"deprecated": true
},
"deprecated_slice": {
"items": {
"type": "string"
},
"type": "array",
"deprecated": true
},
"anything": true,
"raw": true
},
Expand Down
13 changes: 13 additions & 0 deletions fixtures/test_user.json
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,17 @@
},
"type": "array"
},
"deprecated_field": {
"type": "string",
"deprecated": true
},
"deprecated_slice": {
"items": {
"type": "string"
},
"type": "array",
"deprecated": true
},
"anything": true,
"raw": true
},
Expand All @@ -224,6 +235,8 @@
"Baz",
"color",
"roles",
"deprecated_field",
"deprecated_slice",
"raw"
]
}
Expand Down
13 changes: 13 additions & 0 deletions fixtures/test_user_assign_anchor.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,17 @@
},
"type": "array"
},
"deprecated_field": {
"type": "string",
"deprecated": true
},
"deprecated_slice": {
"items": {
"type": "string"
},
"type": "array",
"deprecated": true
},
"anything": true,
"raw": true
},
Expand All @@ -226,6 +237,8 @@
"Baz",
"color",
"roles",
"deprecated_field",
"deprecated_slice",
"raw"
]
}
Expand Down
4 changes: 4 additions & 0 deletions reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,8 @@ func (t *Schema) genericKeywords(tags []string, parent *Schema, propertyName str
Type: ty,
})
}
case "deprecated":
t.Deprecated, _ = strconv.ParseBool(val)
default:
unprocessed = append(unprocessed, tag)
}
Expand Down Expand Up @@ -861,6 +863,8 @@ func (t *Schema) arrayKeywords(tags []string) {
t.Items.Format = val
case "pattern":
t.Items.Pattern = val
case "deprecated":
t.Deprecated, _ = strconv.ParseBool(val)
default:
unprocessed = append(unprocessed, tag) // left for further processing by underlying type
}
Expand Down
4 changes: 4 additions & 0 deletions reflect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ type TestUser struct {
Priorities []int `json:"priorities,omitempty" jsonschema:"enum=-1,enum=0,enum=1,enun=2"`
Offsets []float64 `json:"offsets,omitempty" jsonschema:"enum=1.570796,enum=3.141592,enum=6.283185"`

// Tests for deprecated
DeprecatedField string `json:"deprecated_field" jsonschema:"deprecated=true"`
DeprecatedSlice []string `json:"deprecated_slice" jsonschema:"deprecated=true"`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find it surprising that you have to add =true here. When would anybody ever set this to false? I would have expected that you just say jsonschema:"deprecated", like you do e.g. for json:"omitempty".


// Test for raw JSON
Anything any `json:"anything,omitempty"`
Raw json.RawMessage `json:"raw"`
Expand Down