sinclairzx81 / typebox

Json Schema Type Builder with Static Type Resolution for TypeScript
Other
4.77k stars 152 forks source link

Setting Description #767

Closed ingalls closed 6 months ago

ingalls commented 6 months ago

Context

I am switching from AJV/JSON Schema files to TypeBox via a custom middleware around express. The Middleware also generates OpenAPI definitions for every route it manages. Ref: https://github.com/openaddresses/batch-schema

As part of the generation it would use the description field from the JSON Schema to populate human readable parameters/queries/bodies in the OpenAPI definition. Now that I've switched to using typebox in place of the schema it's been working perfectly expcept for the loss of the ability to set the description field on typebox defined types.

I've searched the code and readme and I'm not seeing an ability to do something like below.

Type.Object{
    username: Type.String({ "description": "The username of the user")
}, {
    "description": "An object containing user information"
})

Would generate

{
    "type": "object",
    "description": "An object containing user information",
    "required": ["username"],
    "properties": {
        "username": {
            "type": "string",
            "description": "An object containing user information"
        }
    }
}

If this doesn't exist would it be something the community would find useful and if it does would folks be able to point me in the right direction of a code sample.

cc @sinclairzx81

ingalls commented 6 months ago

Playing around with the workbench it seems like this already exists just doesn't have an example in the documentation.