Skip to content

feature: generate schema from class #140

@christophmayrhofer

Description

@christophmayrhofer

I see that it is possible to use a json schema to validate against.
Is it also possible to generate the schema from the class?

I am currently using simpl-schema which has a great ecosystem (e,g, auto generating forms)
However, I want to move away from json based schemas towards a more modern approach (i.e. class-validator package), but now I would need to define everything twice (decorators & json schema).
Generating the schema from decorators would prevent a lot of duplicate code.

I don't really care about the syntax/structure of the generated json schema since I can just write a transformer to generate the simpl-schema syntax from it.

I also don't mind contributing if you can point me into the right direction. I would need some way to get all validator types and their arguments:

schema = {}
properties.forEach(property => {
    property.validators.forEach(validator => {
            schema[property.name][validator.name] = validator.value
    })
})

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions