bcherny/json-schema-to-typescript

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

Open

#475 aperta il 29 lug 2022

Vedi su GitHub
 (0 commenti) (1 reazione) (0 assegnatari)TypeScript (449 fork)github user discovery
enhancementgood first issuehelp wanted

Metriche repository

Star
 (3302 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

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.

Guida contributor