Coder Social home page Coder Social logo

Comments (2)

juiceo avatar juiceo commented on September 21, 2024

I know there's this section in the docs:

Alternatively JSONSchema can take a function of type (existingSchema: SchemaObject, options: IOptions) => SchemaObject. The return value of this function is then not automatically merged into existing schema (i.e. the one derived from class-validator decorators). Instead you can handle merging yourself in whichever way is preferred, the idea being that removal of existing keywords and other more complex overwrite scenarios can be implemented here.

However I'm a bit lost regarding how to actually use this, if you can help at all. Would be great to have a code example of this functionality in the docs as well.

from class-validator-jsonschema.

epiphone avatar epiphone commented on September 21, 2024

The example you posted doesn't contain any inheritance so the problem probably lies somewhere else.

Can you post the exact JSON Schema you're getting in your use case? My guess is that in your example case we end up with a Product schema of something like

{
  "properties": {
    "name": {
      "$ref": "<ref to LocalizedString schema>",
      "description": "The name of the product and its translations."
    }
  }
}

And since earlier JSON Schema drafts ignore all other than $ref properties in a reference schema (source), description gets dropped.

OpenAPI's reference objects likewise cannot be extended with additional properties and any properties added SHALL be ignored. https://swagger.io/specification/#reference-object

If that's the case, the solution is to either try some of the creative workarounds mentioned here https://stackoverflow.com/questions/33565090/json-schema-property-description-and-ref-usage or to introduce some sort of complex duplication logic into the library. Or we could wait for OpenAPI v3.1.0 which will finally support the latest JSON Schema draft in its entirety 🙂

from class-validator-jsonschema.

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.