Skip to content

Commit bc65c5f

Browse files
committed
fix: don't silently drop properties from httpRequest
1 parent b2a76ee commit bc65c5f

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

packages/openapi-generator/src/knownImports.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,14 @@ export const KNOWN_IMPORTS: KnownImports = {
206206
if (schema.type !== 'object') {
207207
return E.left('httpRoute parameter must be object');
208208
}
209-
const props = Object.entries(schema.properties).reduce((acc, [key, prop]) => {
210-
const derefedE = deref(prop);
209+
const props: Record<string, Schema> = {};
210+
for (const [key, value] of Object.entries(schema.properties)) {
211+
const derefedE = deref(value);
211212
if (E.isLeft(derefedE)) {
212-
return acc;
213+
return derefedE;
213214
}
214-
return { ...acc, [key]: derefedE.right };
215-
}, {});
215+
props[key] = derefedE.right;
216+
}
216217
return E.right({
217218
type: 'object',
218219
properties: props,

packages/openapi-generator/test/apiSpec.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,28 @@ test('api spec comment parser', async () => {
265265

266266
assert(commentParsed);
267267
});
268+
269+
const MISSING_REFERENCE = {
270+
'/index.ts': `
271+
import * as t from 'io-ts';
272+
import * as h from '@api-ts/io-ts-http';
273+
274+
import { Foo } from 'foo';
275+
276+
export const test = h.apiSpec({
277+
'api.test': {
278+
get: h.httpRoute({
279+
path: '/test',
280+
method: 'GET',
281+
request: Foo,
282+
response: {
283+
200: t.string,
284+
},
285+
})
286+
}
287+
});`,
288+
};
289+
290+
testCase('missing reference', MISSING_REFERENCE, '/index.ts', {}, [
291+
"Cannot find 'Foo' from 'foo'",
292+
]);

0 commit comments

Comments
 (0)