@amritk/generate-parsers 0.6.0 → 0.6.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.
- package/dist/index.js +31 -4
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -699,6 +699,31 @@ var getUnbrandedType = (schema, options = {}) => {
|
|
|
699
699
|
case "object":
|
|
700
700
|
if (schema.properties) {
|
|
701
701
|
const readonlyPrefix = options.readonly ? "readonly " : "";
|
|
702
|
+
const hasDescriptions = Object.values(schema.properties).some((p) => isSchemaObject2(p) && (typeof p.description === "string" || typeof p.$comment === "string"));
|
|
703
|
+
if (hasDescriptions) {
|
|
704
|
+
let properties2 = "";
|
|
705
|
+
let first2 = true;
|
|
706
|
+
for (const key in schema.properties) {
|
|
707
|
+
const propSchema = schema.properties[key];
|
|
708
|
+
const isRequired = schema.required?.includes(key) ?? false;
|
|
709
|
+
const optional = isRequired ? "" : "?";
|
|
710
|
+
const propType = getTypeScriptType(propSchema, options);
|
|
711
|
+
const inlineDescription = isSchemaObject2(propSchema) && typeof propSchema.description === "string" ? propSchema.description : isSchemaObject2(propSchema) && typeof propSchema.$comment === "string" ? propSchema.$comment : undefined;
|
|
712
|
+
if (!first2)
|
|
713
|
+
properties2 += `
|
|
714
|
+
`;
|
|
715
|
+
first2 = false;
|
|
716
|
+
if (inlineDescription) {
|
|
717
|
+
properties2 += " /** " + inlineDescription + ` */
|
|
718
|
+
` + readonlyPrefix + safeKey(key) + optional + ": " + propType + ";";
|
|
719
|
+
} else {
|
|
720
|
+
properties2 += " " + readonlyPrefix + safeKey(key) + optional + ": " + propType + ";";
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
return `{
|
|
724
|
+
` + properties2 + `
|
|
725
|
+
}`;
|
|
726
|
+
}
|
|
702
727
|
let properties = "";
|
|
703
728
|
let first = true;
|
|
704
729
|
for (const key in schema.properties) {
|
|
@@ -740,8 +765,9 @@ var generateTypeDefinition = (schema, typeName, options = {}) => {
|
|
|
740
765
|
if (!isObjectLikeSchema(schema)) {
|
|
741
766
|
const tsType = getTypeScriptType(schema, options);
|
|
742
767
|
let result = "";
|
|
743
|
-
|
|
744
|
-
|
|
768
|
+
const topLevelComment = isSchemaObject2(schema) && typeof schema.description === "string" && schema.description || isSchemaObject2(schema) && typeof schema.$comment === "string" && schema.$comment || undefined;
|
|
769
|
+
if (topLevelComment) {
|
|
770
|
+
result += buildJsDocBlock(typeName, topLevelComment);
|
|
745
771
|
}
|
|
746
772
|
result += `export type ${typeName} = ${tsType};`;
|
|
747
773
|
return result;
|
|
@@ -752,9 +778,10 @@ var generateTypeDefinition = (schema, typeName, options = {}) => {
|
|
|
752
778
|
const conditionalThenRef = conditionalResult?.thenRef ?? null;
|
|
753
779
|
let jsDocTitle;
|
|
754
780
|
let jsDocDescription;
|
|
755
|
-
|
|
781
|
+
const topLevelComment = isSchemaObject2(schema) && typeof schema.description === "string" && schema.description || isSchemaObject2(schema) && typeof schema.$comment === "string" && schema.$comment || undefined;
|
|
782
|
+
if (topLevelComment) {
|
|
756
783
|
jsDocTitle = typeName;
|
|
757
|
-
jsDocDescription =
|
|
784
|
+
jsDocDescription = topLevelComment;
|
|
758
785
|
}
|
|
759
786
|
const hasProperties2 = normalizedSchema.properties && Object.keys(normalizedSchema.properties).length > 0;
|
|
760
787
|
const hasAdditionalProperties2 = normalizedSchema.additionalProperties && typeof normalizedSchema.additionalProperties === "object";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amritk/generate-parsers",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "Generate TypeScript parsers and type definitions from JSON Schemas.",
|
|
5
5
|
"module": "./dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"json-schema-typed": "^8.0.1",
|
|
52
|
-
"@amritk/helpers": "0.6.
|
|
52
|
+
"@amritk/helpers": "0.6.1",
|
|
53
53
|
"@amritk/generate-markdown": "0.2.1"
|
|
54
54
|
}
|
|
55
55
|
}
|