Skip to content

Commit

Permalink
Merge pull request #76 from lifeomic/ep/pull-in-dep-typefix
Browse files Browse the repository at this point in the history
Pull in type bug fix
Shawn Zhu authored Jul 17, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 8b27ce7 + 7b1e2bc commit 1d70320
Showing 3 changed files with 38 additions and 38 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@
"axios": "^0.27.2",
"js-yaml": "^4.1.0",
"json-schema-to-typescript": "^10.1.5",
"openapi-types": "^11.0.1",
"openapi-types": "^12.1.3",
"yargs": "^17.5.1",
"zod-to-json-schema": "^3.20.2",
"zod-validation-error": "^0.3.0"
@@ -47,13 +47,13 @@
"jest": "^28.1.0",
"koa": "^2.13.4",
"koa-bodyparser": "^4.3.0",
"openapi-schema-validator": "^11.0.1",
"openapi-schema-validator": "^12.1.3",
"prettier": "^2.6.2",
"semantic-release": "^19.0.3",
"tmp": "^0.2.1",
"ts-jest": "^28.0.3",
"ts-node": "^10.8.0",
"typescript": "^4.7.2",
"typescript": "^5.1.6",
"uuid": "^9.0.0",
"zod": "^3.20.2"
}
44 changes: 22 additions & 22 deletions src/koa.ts
Original file line number Diff line number Diff line change
@@ -70,27 +70,6 @@ export type ImplementationConfig<

const ajv = new Ajv();

const defaultParse: ImplementationConfig<any, any>['parse'] = (
ctx,
{ endpoint, data, schema },
) => {
if (!ajv.validate(schema, data)) {
const method = (endpoint as string).split(' ')[0];
const dataVar = ['GET', 'DELETE'].includes(method)
? 'query parameters'
: 'payload';

return ctx.throw(
400,
`The request did not conform to the required schema: ${ajv.errorsText(
undefined,
{ dataVar },
)}`,
);
}
return data as any;
};

/**
* Implements the specified `schema` on the provided router object.
*
@@ -113,12 +92,33 @@ export const implementSchema = <
addIntrospection(introspection, () => schema, router);
}

const defaultParse: ImplementationConfig<Schema, RouterType>['parse'] = (
ctx,
{ endpoint, data, schema },
) => {
if (!ajv.validate(schema, data)) {
const method = (endpoint as string).split(' ')[0];
const dataVar = ['GET', 'DELETE'].includes(method)
? 'query parameters'
: 'payload';

return ctx.throw(
400,
`The request did not conform to the required schema: ${ajv.errorsText(
undefined,
{ dataVar },
)}`,
);
}
return data;
};

// Iterate through every handler, and add a route for it based on
// the key/route description.
for (const endpoint in implementation) {
const routeHandler = implementation[endpoint];

const parser: typeof parse = parse ?? defaultParse;
const parser = parse ?? defaultParse;

implementRoute(
endpoint,
26 changes: 13 additions & 13 deletions yarn.lock
Original file line number Diff line number Diff line change
@@ -5894,20 +5894,20 @@ only@~0.0.2:
resolved "https://registry.yarnpkg.com/only/-/only-0.0.2.tgz#2afde84d03e50b9a8edc444e30610a70295edfb4"
integrity sha1-Kv3oTQPlC5qO3EROMGEKcCle37Q=

openapi-schema-validator@^11.0.1:
version "11.0.1"
resolved "https://registry.yarnpkg.com/openapi-schema-validator/-/openapi-schema-validator-11.0.1.tgz#430ca95e02b79f9750b57f51051a1f97af30248c"
integrity sha512-c2+6qqsIZ2rX5CrxrW7QjsDYNw/fA1XPMBq/dMeU+k/I1y6GSbl64jutbLaLhEORd2coavga16eeYx3GtmkWKQ==
openapi-schema-validator@^12.1.3:
version "12.1.3"
resolved "https://registry.yarnpkg.com/openapi-schema-validator/-/openapi-schema-validator-12.1.3.tgz#c9234af67b00cdbbecfdd4eb546d7006bacfe518"
integrity sha512-xTHOmxU/VQGUgo7Cm0jhwbklOKobXby+/237EG967+3TQEYJztMgX9Q5UE2taZKwyKPUq0j11dngpGjUuxz1hQ==
dependencies:
ajv "^8.1.0"
ajv-formats "^2.0.2"
lodash.merge "^4.6.1"
openapi-types "^11.0.1"
openapi-types "^12.1.3"

openapi-types@^11.0.1:
version "11.0.1"
resolved "https://registry.yarnpkg.com/openapi-types/-/openapi-types-11.0.1.tgz#7e1cee2c9b8cb16787d14f2b0f433c5ba0e32e96"
integrity sha512-P2pGRlHFXgP8z6vrp5P/MtftOXYtlIY1A+V0VmioOoo85NN6RSPgGbEprRAUNMIsbfRjnCPdx/r8mi8QRR7grQ==
openapi-types@^12.1.3:
version "12.1.3"
resolved "https://registry.yarnpkg.com/openapi-types/-/openapi-types-12.1.3.tgz#471995eb26c4b97b7bd356aacf7b91b73e777dd3"
integrity sha512-N4YtSYJqghVu4iek2ZUvcN/0aqH1kRDuNqzcycDxhOUpg7GdvLa2F3DgS6yBNhInhv2r/6I0Flkn7CqL8+nIcw==

opener@^1.5.2:
version "1.5.2"
@@ -7143,10 +7143,10 @@ type@^2.5.0:
resolved "https://registry.yarnpkg.com/type/-/type-2.6.0.tgz#3ca6099af5981d36ca86b78442973694278a219f"
integrity sha512-eiDBDOmkih5pMbo9OqsqPRGMljLodLcwd5XD5JbtNB0o89xZAwynY9EdCDsJU7LtcVCClu9DvM7/0Ep1hYX3EQ==

typescript@^4.7.2:
version "4.7.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.7.2.tgz#1f9aa2ceb9af87cca227813b4310fff0b51593c4"
integrity sha512-Mamb1iX2FDUpcTRzltPxgWMKy3fhg0TN378ylbktPGPK/99KbDtMQ4W1hwgsbPAsG3a0xKa1vmw4VKZQbkvz5A==
typescript@^5.1.6:
version "5.1.6"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.1.6.tgz#02f8ac202b6dad2c0dd5e0913745b47a37998274"
integrity sha512-zaWCozRZ6DLEWAWFrVDz1H6FVXzUSfTy5FUMWsQlU8Ym5JP9eO4xkTIROFCQvhQf61z6O/G6ugw3SgAnvvm+HA==

uglify-js@^3.1.4:
version "3.15.5"

0 comments on commit 1d70320

Please sign in to comment.