Skip to content

Commit

Permalink
fix: don't silently drop properties from httpRequest
Browse files Browse the repository at this point in the history
Ticket: VL-1836
  • Loading branch information
bitgopatmcl committed May 9, 2024
1 parent b2a76ee commit ae0b7ce
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
22 changes: 15 additions & 7 deletions packages/openapi-generator/src/codec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as swc from '@swc/core';
import * as E from 'fp-ts/Either';
import { pipe } from 'fp-ts/lib/function';

import { leadingComment } from './comments';
import type { Object, Schema } from './ir';
Expand Down Expand Up @@ -376,12 +375,21 @@ export function parseCodecInitializer(
return parsePlainInitializer(project, source, expression);
});

return pipe(
args,
E.sequenceArray,
E.chain((args) => pipe(args.map(deref), E.sequenceArray)),
E.chain((args) => identifier.schema(deref, ...args)),
);
const dereferencedArgs: Schema[] = [];
for (const argE of args) {
if (E.isLeft(argE)) {
return argE;
}
const arg = argE.right;

const dereferencedArgE = deref(arg);
if (E.isLeft(dereferencedArgE)) {
return dereferencedArgE;
}
dereferencedArgs.push(dereferencedArgE.right);
}
const schema = identifier.schema(deref, ...dereferencedArgs);
return schema;
} else {
return E.left(`Unimplemented initializer type ${init.type}`);
}
Expand Down
11 changes: 6 additions & 5 deletions packages/openapi-generator/src/knownImports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,14 @@ export const KNOWN_IMPORTS: KnownImports = {
if (schema.type !== 'object') {
return E.left('httpRoute parameter must be object');
}
const props = Object.entries(schema.properties).reduce((acc, [key, prop]) => {
const derefedE = deref(prop);
const props: Record<string, Schema> = {};
for (const [key, value] of Object.entries(schema.properties)) {
const derefedE = deref(value);
if (E.isLeft(derefedE)) {
return acc;
return derefedE;
}
return { ...acc, [key]: derefedE.right };
}, {});
props[key] = derefedE.right;
}
return E.right({
type: 'object',
properties: props,
Expand Down

0 comments on commit ae0b7ce

Please sign in to comment.