@arcteninc/core 0.0.52 → 0.0.53
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/package.json
CHANGED
|
@@ -731,18 +731,54 @@ function serializeTypeCustom(
|
|
|
731
731
|
}
|
|
732
732
|
|
|
733
733
|
// Build the schema for this type
|
|
734
|
+
// For interfaces, get properties from both the type and the declaration
|
|
734
735
|
const props = checker.getPropertiesOfType(type);
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
736
|
+
const properties: Record<string, JsonSchemaProperty> = {};
|
|
737
|
+
const required: string[] = [];
|
|
738
|
+
|
|
739
|
+
// Extract properties from the interface/type alias declaration
|
|
740
|
+
if (ts.isInterfaceDeclaration(firstDecl)) {
|
|
741
|
+
for (const member of firstDecl.members) {
|
|
742
|
+
if (ts.isPropertySignature(member) && ts.isIdentifier(member.name)) {
|
|
743
|
+
const propName = member.name.text;
|
|
744
|
+
const isOptional = member.questionToken !== undefined;
|
|
745
|
+
|
|
746
|
+
if (member.type) {
|
|
747
|
+
const propType = checker.getTypeFromTypeNode(member.type);
|
|
748
|
+
const propResult = serializeTypeCustom(propType, checker, defs, visited, depth + 1);
|
|
749
|
+
properties[propName] = propResult.schema;
|
|
750
|
+
|
|
751
|
+
if (!isOptional && !propResult.isOptional) {
|
|
752
|
+
required.push(propName);
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
} else if (ts.isTypeAliasDeclaration(firstDecl) && firstDecl.type) {
|
|
758
|
+
// For type aliases, resolve the underlying type
|
|
759
|
+
const underlyingType = checker.getTypeFromTypeNode(firstDecl.type);
|
|
760
|
+
if (underlyingType.flags & ts.TypeFlags.Object) {
|
|
761
|
+
const aliasProps = checker.getPropertiesOfType(underlyingType);
|
|
762
|
+
for (const prop of aliasProps) {
|
|
763
|
+
const propName = prop.getName();
|
|
764
|
+
const propType = checker.getTypeOfSymbolAtLocation(prop, prop.valueDeclaration || prop.declarations?.[0] || null as any);
|
|
765
|
+
const isOptional = (prop.flags & ts.SymbolFlags.Optional) !== 0;
|
|
766
|
+
|
|
767
|
+
const propResult = serializeTypeCustom(propType, checker, defs, visited, depth + 1);
|
|
768
|
+
properties[propName] = propResult.schema;
|
|
769
|
+
|
|
770
|
+
if (!isOptional && !propResult.isOptional) {
|
|
771
|
+
required.push(propName);
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
} else if (props.length > 0) {
|
|
776
|
+
// Fallback: use getPropertiesOfType if declaration parsing didn't work
|
|
740
777
|
for (const prop of props) {
|
|
741
778
|
const propName = prop.getName();
|
|
742
|
-
const propType = checker.getTypeOfSymbolAtLocation(prop, prop.valueDeclaration || prop.declarations?.[0] ||
|
|
779
|
+
const propType = checker.getTypeOfSymbolAtLocation(prop, prop.valueDeclaration || prop.declarations?.[0] || null as any);
|
|
743
780
|
const isOptional = (prop.flags & ts.SymbolFlags.Optional) !== 0;
|
|
744
781
|
|
|
745
|
-
// Recursively serialize the property type (will detect recursion via visited set)
|
|
746
782
|
const propResult = serializeTypeCustom(propType, checker, defs, visited, depth + 1);
|
|
747
783
|
properties[propName] = propResult.schema;
|
|
748
784
|
|
|
@@ -750,15 +786,15 @@ function serializeTypeCustom(
|
|
|
750
786
|
required.push(propName);
|
|
751
787
|
}
|
|
752
788
|
}
|
|
753
|
-
|
|
754
|
-
// Update the placeholder with the actual schema
|
|
755
|
-
defs[defsKey] = {
|
|
756
|
-
type: 'object',
|
|
757
|
-
properties,
|
|
758
|
-
...(required.length > 0 && { required })
|
|
759
|
-
};
|
|
760
789
|
}
|
|
761
790
|
|
|
791
|
+
// Update the placeholder with the actual schema (even if empty, to avoid infinite loops)
|
|
792
|
+
defs[defsKey] = {
|
|
793
|
+
type: 'object',
|
|
794
|
+
properties,
|
|
795
|
+
...(required.length > 0 && { required })
|
|
796
|
+
};
|
|
797
|
+
|
|
762
798
|
// Return reference
|
|
763
799
|
return { isOptional: false, schema: { $ref: `#/$defs/${defsKey}` } };
|
|
764
800
|
}
|