Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JsDoc support parameter descriptions #2047

Open
NojusM opened this issue Aug 22, 2024 · 2 comments
Open

JsDoc support parameter descriptions #2047

NojusM opened this issue Aug 22, 2024 · 2 comments

Comments

@NojusM
Copy link

NojusM commented Aug 22, 2024

The ts-json-schema-generator currently supports comments placed above properties, converting them into the corresponding description in the schema. However, it does not support adding descriptions for properties directly in the root JsDoc or inline. It would be a significant improvement to include either of these features, as the current approach of adding comments above each property can make TypeScript types harder to read and maintain.

Current situation

Works

Root comment

/** List of favorite fruit */
export type FruitList {
  apple: number
  tomato: number
  pear: number
}

Property comment above

/** List of favorite fruit */
export type FruitList {
  apple: number
  /** It's a fruit? */
  tomato: number
  /** Must not be more than 1000 */
  pear: number
}

Doesn't work, but would be amazing if it did

Description of properties in root comment

/** 
List of favorite fruit 
@tomato It's a fruit?
@pear Must not be more than 1000
*/
export type FruitList {
  apple: number
  tomato: number
  pear: number
}

Inline comments

/** List of favorite fruit */
export type FruitList {
  apple: number
  tomato: number /** It's a fruit? */
  pear: number /** Must not be more than 1000 */
}
@arthurfiorette
Copy link
Collaborator

what you are asking is not part of the jsdoc spec.

https://jsdoc.app/

@NojusM
Copy link
Author

NojusM commented Aug 23, 2024

I'm suggesting is to use block tag syntax to assign descriptions to child types. Block tags are mostly used to describe function params, but it would be very useful to use it to describe type children and ts-json-schema-generator to parse it to child descriptions.

Example

Given this TS input

/** 
List of favorite fruit 
@tomato It's a fruit?
@pear Must not be more than 1000
*/
export type FruitList {
  apple: number
  tomato: number
  pear: number
}

Expected (desired)

...
"FruitList": {
	"description": "List of favorite fruit",
	"properties": {
		"apple": { "type": "number" },
		"tomato": { "type": "number", "description": "It's a fruit?" },
		"pear": { "type": "number", "description": "Must not be more than 1000" },
	},
	"required": ["apple", "tomato", "pear"],
	"type": "object"
},
...

Actuall (current)

...
"FruitList": {
	"description": "List of favorite fruit",
	"properties": {
		"apple": { "type": "number" },
		"tomato": { "type": "number" },
		"pear": { "type": "number" },
	},
	"required": ["apple", "tomato", "pear"],
	"type": "object"
},
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants