Skip to content

Commit 707405c

Browse files
committed
Docs: update with rfl::Deprecated
1 parent b91fd65 commit 707405c

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ struct Person {
367367
std::vector<Person>>
368368
children;
369369
float salary;
370+
rfl::Deprecated<"Use Salary Instead", "Wage in dollars", int> wage;
370371
};
371372

372373
const std::string json_schema = rfl::json::to_schema<Person>();

docs/json_schema.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,56 @@ const std::string json_schema = rfl::json::to_schema<
192192
}
193193
}
194194
```
195+
196+
## Indicating deprecated fields
197+
198+
You can mark fields as deprecated in the JSON schema using `rfl::Deprecated`. This adds `"deprecated": true` and a `"deprecationMessage"` to the generated schema, along with a description.
199+
200+
`rfl::Deprecated` takes three template parameters: a deprecation message, a description, and the underlying type:
201+
202+
```cpp
203+
struct Person {
204+
rfl::Deprecated<"Use 'full_name' instead.", "The person's first name", std::string>
205+
first_name;
206+
rfl::Description<"The person's full name", std::string> full_name;
207+
float salary;
208+
};
209+
```
210+
211+
```cpp
212+
const std::string json_schema = rfl::json::to_schema<Person>(rfl::json::pretty);
213+
```
214+
215+
```json
216+
{
217+
"$schema": "https://json-schema.org/draft/2020-12/schema",
218+
"$ref": "#/$defs/Person",
219+
"$defs": {
220+
"Person": {
221+
"type": "object",
222+
"properties": {
223+
"first_name": {
224+
"type": "string",
225+
"description": "The person's first name",
226+
"deprecated": true,
227+
"deprecationMessage": "Use 'full_name' instead."
228+
},
229+
"full_name": {
230+
"type": "string",
231+
"description": "The person's full name"
232+
},
233+
"salary": {
234+
"type": "number"
235+
}
236+
},
237+
"required": [
238+
"first_name",
239+
"full_name",
240+
"salary"
241+
]
242+
}
243+
}
244+
}
245+
```
246+
247+
`rfl::Deprecated` behaves like a thin wrapper around the underlying type, just like `rfl::Description`. You can access the underlying value using `.get()`, `.value()`, `operator()()`, or the assignment operator.

0 commit comments

Comments
 (0)