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

`title` in property should means a short description

Open ValeryR opened this issue 4 years ago • 5 comments

Hello, @bcherny, thank you for package 🙂 i use it and stumbled a mirror bug with title inside property. Currently title in property means name of property but in json schema draft it should means a short description. And also when i try add none english title i get a NoName alias for primitive. this is a little snippet for reproduce behavior

const json2ts = require('json-schema-to-typescript');
const fs = require('fs');

const inputData = {
  "title": "Example Schema",
  "type": "object",
  "properties": {
    "lastName": {
      "title": "Бла-бла-бла",
      "type": "string"
    },
  },
  "additionalProperties": false,
  "required": ["firstName", "lastName"]
};

(async function example() {
  const compiledModels = await json2ts.compile(inputData, '');
  fs.writeFileSync(`output.ts`, compiledModels);
})();

and after invoked i got this:

export type NoName = string;

export interface ExampleSchema {
  lastName: NoName;
}

but expect output like this:

export interface ExampleSchema {
  /**
   * Бла-бла-бла
   */
  lastName: string;
}

yeah, i know that i can use description to add description of property and it works how i want, but i need properly title behavior because i use it for transform Swagger.

if you agree with me i can try to fix it myself, thank you 🙂

ValeryR avatar Mar 09 '21 17:03 ValeryR

Hey there! This would be a backwards-incompatible change. Let's leave this issue open to collect feedback from others -- if there's enough demand, we can change the behavior.

bcherny avatar Mar 28 '21 23:03 bcherny

Hey, i run also in the same issue, i need also the title for swagger. Would be good to have a option to change the title behaviour

Nightapes avatar Jan 19 '22 19:01 Nightapes

Can't this be an option? That way backwards compatibility can be preserved

hongha912 avatar Oct 26 '22 15:10 hongha912