Comments (2)
This is by-design. The schema_for
macro generates schemas which conform to JSON Schema Draft 7, which does not allow an object with the $ref
property to contain any other properties (see https://tools.ietf.org/html/draft-handrews-json-schema-01#section-8.3). So in order to include any other properties (including description
), the $ref
is wrapped in an allOf
.
The newest JSON Schema specification (draft 2019-09) does not have this restriction. Schemars supports this, albeit in a more verbose way:
let schema = SchemaSettings::draft2019_09()
.into_generator()
.into_root_schema_for::<A>();
println!("{}", serde_json::to_string_pretty(&schema).unwrap());
Which would then output:
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"title": "A",
"type": "object",
"required": [
"name"
],
"properties": {
"name": {
"description": "doc comment",
"$ref": "#/definitions/Name"
}
},
"definitions": {
"Name": {
"type": "string"
}
}
}
from schemars.
Thanks; sorry for the noise.
from schemars.
Related Issues (20)
- Annotate a field so it is both `required` and `default` HOT 1
- schemars_derive breaks with version serde_derive_internals 0.29.0 HOT 1
- Support for humantime
- Add CI with latest dependencies
- Support `allowTrailingCommas` in schema HOT 1
- Compatibility with json-schema.org ? HOT 2
- Switch to indexmap 2 for the `preserve_order` feature HOT 1
- 0.8.18 regression - "type annotations needed" on variantless enum HOT 1
- skip_if for conditional skip
- Behavior change in 0.8.19 with `default`, `required`, and `skip_serializing_if` HOT 3
- `Option` no longer has a default of null as of v0.8.18 HOT 2
- Range for standard number types
- Expected schemars description attribute to be a string HOT 2
- expected validate path attribute to be a string: `path = "..."` HOT 1
- gen keyword is reserved in Rust 2024 HOT 2
- Check if Value satisfies RootSchema HOT 1
- Nested internally tagged enums
- bug(schemars_derive/docs): newlines get stripped in example blocks HOT 1
- flatten of `Option<Enum>` generates schema where enum is required HOT 3
- Document macro attributes HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from schemars.