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)
- Opt-out of processing rustdoc comments
- Improve automatic trait bounds
- Respect `#[schemars(bound = ...)]` attributes on fields as well as containers
- Support smartstring HOT 1
- Handling of #[serde(into=...)]
- Schema customization
- Improve interop between schemars and progenitor
- Self-referencing a type ends up creating a new definition HOT 1
- Referencing External Schemas
- Use full path in json definition generation HOT 7
- numeric constraints always converted to floats
- Array's `items` being set to `true` HOT 2
- How to generate a `RootSchema` from a string? HOT 1
- Implement JsonSchema for num_bigint::*
- skip_serializing_if = "Vec::is_empty" still marked as required HOT 2
- Consider implementing JsonSchema for RootSchema
- make generic type name format configurable. HOT 1
- Could the generation be compatible with Prettier?
- How to auto generate references for enum variants HOT 1
- proposal: `#[schemars(example_value = "blabla")]`
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.