bcherny/json-schema-to-typescript

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

Open

#475 opened on Jul 29, 2022

View on 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
 (No merged PRs in 30d)

Description

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.

Contributor guide