GithubHelp home page GithubHelp logo

Comments (2)

GREsau avatar GREsau commented on May 11, 2024

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.

ahl avatar ahl commented on May 11, 2024

Thanks; sorry for the noise.

from schemars.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.