Skip to content

Commit

Permalink
Merge pull request #52 from lifeomic/router
Browse files Browse the repository at this point in the history
feat: introduce OneSchemaRouter as a simpler approach
  • Loading branch information
swain authored Jan 17, 2023
2 parents 92ad28e + 02b09df commit e05742d
Show file tree
Hide file tree
Showing 6 changed files with 619 additions and 2 deletions.
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
"js-yaml": "^4.1.0",
"json-schema-to-typescript": "^10.1.5",
"openapi-types": "^11.0.1",
"yargs": "^17.5.1"
"yargs": "^17.5.1",
"zod-to-json-schema": "^3.20.2",
"zod-validation-error": "^0.3.0"
},
"devDependencies": {
"@koa/router": "^12.0.0",
Expand Down Expand Up @@ -52,6 +54,7 @@
"tmp": "^0.2.1",
"ts-jest": "^28.0.3",
"ts-node": "^10.8.0",
"typescript": "^4.7.2"
"typescript": "^4.7.2",
"zod": "^3.20.2"
}
}
80 changes: 80 additions & 0 deletions src/__snapshots__/router.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`introspection introspecting + generating a client 1`] = `
"/* eslint-disable */
import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from \\"axios\\";
export type Endpoints = {
\\"POST /items\\": {
Request: {
message: string;
};
PathParams: {};
Response: {
id: string;
message: string;
};
};
\\"GET /items/:id\\": {
Request: {
filter: string;
};
PathParams: {
id: string;
};
Response: {
id: string;
message: string;
};
};
};
export declare class Client {
constructor(client: AxiosInstance);
/**
* Executes the \`POST /items\` endpoint.
*
* @param data The request data.
* @param config The Axios request overrides for the request.
*
* @returns An AxiosResponse object representing the response.
*/
createItem(
data: Endpoints[\\"POST /items\\"][\\"Request\\"] &
Endpoints[\\"POST /items\\"][\\"PathParams\\"],
config?: AxiosRequestConfig
): Promise<AxiosResponse<Endpoints[\\"POST /items\\"][\\"Response\\"]>>;
/**
* Executes the \`GET /items/:id\` endpoint.
*
* @param data The request data.
* @param config The Axios request overrides for the request.
*
* @returns An AxiosResponse object representing the response.
*/
getItem(
data: Endpoints[\\"GET /items/:id\\"][\\"Request\\"] &
Endpoints[\\"GET /items/:id\\"][\\"PathParams\\"],
config?: AxiosRequestConfig
): Promise<AxiosResponse<Endpoints[\\"GET /items/:id\\"][\\"Response\\"]>>;
/**
* Paginates exhaustively through the provided \`request\`, using the specified
* \`data\`. A \`pageSize\` can be specified in the \`data\` to customize the
* page size for pagination.
*/
paginate<T extends { nextPageToken?: string; pageSize?: string }, Item>(
request: (
data: T,
config?: AxiosRequestConfig
) => Promise<
AxiosResponse<{ items: Item[]; links: { self: string; next?: string } }>
>,
data: T,
config?: AxiosRequestConfig
): Promise<Item[]>;
}
"
`;
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './koa';
export * from './types';
export * from './router';

// We intentionally avoid exposing codegen-related modules here,
// so that consumers don't unnecessarily bundle codegen logic
Expand Down
Loading

0 comments on commit e05742d

Please sign in to comment.