Skip to content

Commit 3a9392e

Browse files
committed
fix: make computed property support more robust
1 parent dd2c671 commit 3a9392e

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

packages/openapi-generator/src/codec.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -239,26 +239,26 @@ function parseObjectExpression(
239239

240240
let name: string = '';
241241
if (property.key.type === 'Computed') {
242-
if (property.key.expression.type !== 'Identifier') {
243-
return errorLeft(
244-
`Unimplemented computed property value type ${property.value.type}`,
245-
);
246-
}
247-
248-
const initE = findSymbolInitializer(
249-
project,
250-
source,
251-
property.key.expression.value,
252-
);
253-
if (E.isLeft(initE)) {
254-
return initE;
255-
}
256-
const [newSourceFile, init] = initE.right;
257-
const valueE = parsePlainInitializer(project, newSourceFile, init);
242+
const valueE = parseCodecInitializer(project, source, property.key.expression);
258243
if (E.isLeft(valueE)) {
259244
return valueE;
260245
}
261-
const schema = valueE.right;
246+
let schema = valueE.right;
247+
if (schema.type === 'ref') {
248+
const realInitE = findSymbolInitializer(project, source, schema.name);
249+
if (E.isLeft(realInitE)) {
250+
return realInitE;
251+
}
252+
const schemaE = parsePlainInitializer(
253+
project,
254+
realInitE.right[0],
255+
realInitE.right[1],
256+
);
257+
if (E.isLeft(schemaE)) {
258+
return schemaE;
259+
}
260+
schema = schemaE.right;
261+
}
262262
if (
263263
(schema.type === 'string' || schema.type === 'number') &&
264264
schema.enum !== undefined

0 commit comments

Comments
 (0)