typescript-json-schema icon indicating copy to clipboard operation
typescript-json-schema copied to clipboard

How to generate title in human readable format?

Open FreePhoenix888 opened this issue 2 years ago • 5 comments

Code

export interface Abc {
  firstName: string
}

Expected

freephoenix888@freephoenix888:~/Programming/deep/firebase-push-notification$ typescript-json-schema ./src/push-notification.ts "Abc" --titles
{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "properties": {
        "firstName": {
            "title": "First name",
            "type": "string"
        }
    },
    "type": "object"
}

Actual

freephoenix888@freephoenix888:~/Programming/deep/firebase-push-notification$ typescript-json-schema ./src/push-notification.ts "Abc" --titles
{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "properties": {
        "firstName": {
            "title": "firstName",
            "type": "string"
        }
    },
    "type": "object"
}

Additional Info

Why do I need this: I want to use this generated JSON-Schema for form generation using react-jsonschema-form

FreePhoenix888 avatar Jul 23 '23 15:07 FreePhoenix888

@YousefED

FreePhoenix888 avatar Jul 23 '23 15:07 FreePhoenix888

@domoritz

FreePhoenix888 avatar Jul 23 '23 15:07 FreePhoenix888

We can use capitalCase from https://www.npmjs.com/package/case-anything

FreePhoenix888 avatar Jul 24 '23 04:07 FreePhoenix888

Add JSDoc comment

export interface Abc {
    /**
     * First name
     */
    firstName: string;
}

leqwasd avatar Oct 11 '23 07:10 leqwasd

Remove --titles parameter from command and add @title JSDoc comment.

export interface Abc {
    /**
     * @title First name
     */
    firstName: string;
}

acollazo25 avatar Feb 24 '24 10:02 acollazo25