Skip to content

Commit

Permalink
fix: don't silently drop properties from httpRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
bitgopatmcl committed May 9, 2024
1 parent b2a76ee commit bc65c5f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
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
25 changes: 25 additions & 0 deletions packages/openapi-generator/test/apiSpec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,28 @@ test('api spec comment parser', async () => {

assert(commentParsed);
});

const MISSING_REFERENCE = {
'/index.ts': `
import * as t from 'io-ts';
import * as h from '@api-ts/io-ts-http';
import { Foo } from 'foo';
export const test = h.apiSpec({
'api.test': {
get: h.httpRoute({
path: '/test',
method: 'GET',
request: Foo,
response: {
200: t.string,
},
})
}
});`,
};

testCase('missing reference', MISSING_REFERENCE, '/index.ts', {}, [
"Cannot find 'Foo' from 'foo'",
]);

0 comments on commit bc65c5f

Please sign in to comment.