bcherny/json-schema-to-typescript

Description comments can't be placed on oneOf > const values

Open

#475 opened on 2022年7月29日

GitHub で見る
 (0 comments) (1 reaction) (0 assignees)TypeScript (449 forks)github user discovery
enhancementgood first issuehelp wanted

Repository metrics

Stars
 (3,302 stars)
PR merge metrics
 (30d に merged PR はありません)

説明

For simplicity's sake, I'd like to be able to declare a type that is a union of strings, not a const enum.

{
  "oneOf": [
    { "const": "a", "description": "First comment (a)." },
    { "const": "b", "description": "Second comment (b)." }
  ]
}
var { compile } = require("json-schema-to-typescript");

var schema = {
  oneOf: [
    { const: "a", description: "First comment (a)." },
    { const: "b", description: "Second comment (b)." },
  ],
};

var pendingResult = compile(schema, "example", {
  additionalProperties: false,
  bannerComment: "",
  declareExternallyReferenced: true,
});

pendingResult.then((result) => console.log(result));

Actual

export type Example = "a" | "b";

Expected

export type Example =
  /**
   * First comment (a).
   */
  | "a"
  /**
   * Second comment (b).
   */
  | "b";

Is this a reasonable request?

The context, similar to #470, is typescript-eslint rule schemas such as https://typescript-eslint.io/rules/explicit-member-accessibility where we'd like to keep the description to a simple string union, but still document them.

コントリビューターガイド