@amritk/mjst 0.7.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/cli.js +31 -4
  2. package/package.json +4 -4
package/dist/cli.js CHANGED
@@ -90440,6 +90440,31 @@ var getUnbrandedType = (schema, options = {}) => {
90440
90440
  case "object":
90441
90441
  if (schema.properties) {
90442
90442
  const readonlyPrefix = options.readonly ? "readonly " : "";
90443
+ const hasDescriptions = Object.values(schema.properties).some((p) => isSchemaObject2(p) && (typeof p.description === "string" || typeof p.$comment === "string"));
90444
+ if (hasDescriptions) {
90445
+ let properties2 = "";
90446
+ let first22 = true;
90447
+ for (const key in schema.properties) {
90448
+ const propSchema = schema.properties[key];
90449
+ const isRequired = schema.required?.includes(key) ?? false;
90450
+ const optional3 = isRequired ? "" : "?";
90451
+ const propType = getTypeScriptType(propSchema, options);
90452
+ const inlineDescription = isSchemaObject2(propSchema) && typeof propSchema.description === "string" ? propSchema.description : isSchemaObject2(propSchema) && typeof propSchema.$comment === "string" ? propSchema.$comment : undefined;
90453
+ if (!first22)
90454
+ properties2 += `
90455
+ `;
90456
+ first22 = false;
90457
+ if (inlineDescription) {
90458
+ properties2 += " /** " + inlineDescription + ` */
90459
+ ` + readonlyPrefix + safeKey(key) + optional3 + ": " + propType + ";";
90460
+ } else {
90461
+ properties2 += " " + readonlyPrefix + safeKey(key) + optional3 + ": " + propType + ";";
90462
+ }
90463
+ }
90464
+ return `{
90465
+ ` + properties2 + `
90466
+ }`;
90467
+ }
90443
90468
  let properties = "";
90444
90469
  let first5 = true;
90445
90470
  for (const key in schema.properties) {
@@ -90481,8 +90506,9 @@ var generateTypeDefinition = (schema, typeName, options = {}) => {
90481
90506
  if (!isObjectLikeSchema(schema)) {
90482
90507
  const tsType = getTypeScriptType(schema, options);
90483
90508
  let result = "";
90484
- if (isSchemaObject2(schema) && schema.$comment && typeof schema.$comment === "string") {
90485
- result += buildJsDocBlock(typeName, schema.$comment);
90509
+ const topLevelComment = isSchemaObject2(schema) && typeof schema.description === "string" && schema.description || isSchemaObject2(schema) && typeof schema.$comment === "string" && schema.$comment || undefined;
90510
+ if (topLevelComment) {
90511
+ result += buildJsDocBlock(typeName, topLevelComment);
90486
90512
  }
90487
90513
  result += `export type ${typeName} = ${tsType};`;
90488
90514
  return result;
@@ -90493,9 +90519,10 @@ var generateTypeDefinition = (schema, typeName, options = {}) => {
90493
90519
  const conditionalThenRef = conditionalResult?.thenRef ?? null;
90494
90520
  let jsDocTitle;
90495
90521
  let jsDocDescription;
90496
- if (isSchemaObject2(schema) && schema.$comment && typeof schema.$comment === "string") {
90522
+ const topLevelComment = isSchemaObject2(schema) && typeof schema.description === "string" && schema.description || isSchemaObject2(schema) && typeof schema.$comment === "string" && schema.$comment || undefined;
90523
+ if (topLevelComment) {
90497
90524
  jsDocTitle = typeName;
90498
- jsDocDescription = schema.$comment;
90525
+ jsDocDescription = topLevelComment;
90499
90526
  }
90500
90527
  const hasProperties2 = normalizedSchema.properties && Object.keys(normalizedSchema.properties).length > 0;
90501
90528
  const hasAdditionalProperties2 = normalizedSchema.additionalProperties && typeof normalizedSchema.additionalProperties === "object";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amritk/mjst",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "description": "Generate TypeScript parsers and type definitions from JSON Schemas.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -42,10 +42,10 @@
42
42
  "generate-readme": "bun run ./scripts/generate-readme.ts"
43
43
  },
44
44
  "dependencies": {
45
- "@amritk/adapters": "0.2.3",
46
- "@amritk/generate-parsers": "0.6.0",
45
+ "@amritk/adapters": "0.2.4",
46
+ "@amritk/generate-parsers": "0.6.1",
47
47
  "@amritk/generate-markdown": "0.2.1",
48
- "@amritk/helpers": "0.6.0"
48
+ "@amritk/helpers": "0.6.1"
49
49
  },
50
50
  "devDependencies": {
51
51
  "json-schema-typed": "^8.0.1"