@boon4681/giri 0.0.3-alpha-5 → 0.0.3-alpha-6

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/cli.js CHANGED
@@ -151,6 +151,15 @@ function buildObjectSchema(type, ctx) {
151
151
  }
152
152
  return schema;
153
153
  }
154
+ function toJsonReturnType(type, ctx) {
155
+ const symbol = ctx.checker.getPropertyOfType(type, "toJSON");
156
+ if (!symbol) {
157
+ return void 0;
158
+ }
159
+ const methodType = ctx.checker.getTypeOfSymbolAtLocation(symbol, ctx.location);
160
+ const [signature] = methodType.getCallSignatures();
161
+ return signature ? ctx.checker.getReturnTypeOfSignature(signature) : void 0;
162
+ }
154
163
  function defName(type) {
155
164
  const symbol = type.getSymbol() ?? type.aliasSymbol;
156
165
  const name = symbol?.getName();
@@ -164,6 +173,12 @@ function walkObject(type, ctx) {
164
173
  if (isDateType(type)) {
165
174
  return { type: "string", format: "date-time" };
166
175
  }
176
+ if (!checker.isArrayType(type) && !checker.isTupleType(type)) {
177
+ const jsonReturn = toJsonReturnType(type, ctx);
178
+ if (jsonReturn) {
179
+ return walkType(jsonReturn, ctx);
180
+ }
181
+ }
167
182
  if (checker.isArrayType(type)) {
168
183
  const [element] = checker.getTypeArguments(type);
169
184
  return { type: "array", items: element ? walkType(element, ctx) : {} };