Skip to content

Commit

Permalink
refactor(builds): improve the builds
Browse files Browse the repository at this point in the history
  • Loading branch information
nfroidure committed Apr 5, 2020
1 parent 82fec46 commit bd0f39b
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 79 deletions.
15 changes: 15 additions & 0 deletions packages/whook-example/src/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ Object {
Array [
"💿 - Loading getOpenAPIWrapped initializer from /home/whoiam/projects/whook/packages/whook-example/src/handlers/getOpenAPI.ts.",
],
Array [
"💿 - Loading getParametersWrapped initializer from /home/whoiam/projects/whook/packages/whook-example/src/handlers/getParameters.ts.",
],
Array [
"💿 - Loading getPingWrapped initializer from /home/whoiam/projects/whook/dist/handlers/getPing.js.",
],
Expand Down Expand Up @@ -252,6 +255,9 @@ Object {
Array [
"💿 - Service \\"getOpenAPIWrapped\\" found in: /home/whoiam/projects/whook/packages/whook-example/src/handlers/getOpenAPI.ts",
],
Array [
"💿 - Service \\"getParametersWrapped\\" found in: /home/whoiam/projects/whook/packages/whook-example/src/handlers/getParameters.ts",
],
Array [
"💿 - Service \\"getPingWrapped\\" found in: /home/whoiam/projects/whook/dist/handlers/getPing.js",
],
Expand All @@ -276,6 +282,9 @@ Object {
Array [
"🔐 - Initializing the authorization wrapper for \\"getOpenAPI\\".",
],
Array [
"🔐 - Initializing the authorization wrapper for \\"getParameters\\".",
],
Array [
"🔐 - Initializing the authorization wrapper for \\"getPing\\".",
],
Expand Down Expand Up @@ -669,6 +678,12 @@ Object {
Array [
"🛂 - Dynamic import of: /home/whoiam/projects/whook/packages/whook-example/src/handlers/getOpenAPI.ts",
],
Array [
"🛂 - Dynamic import of: /home/whoiam/projects/whook/packages/whook-example/src/handlers/getParameters.ts",
],
Array [
"🛂 - Dynamic import of: /home/whoiam/projects/whook/packages/whook-example/src/handlers/getParameters.ts",
],
Array [
"🛂 - Dynamic import of: /home/whoiam/projects/whook/packages/whook-example/src/handlers/getTime.ts",
],
Expand Down
96 changes: 96 additions & 0 deletions packages/whook-example/src/handlers/getParameters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { autoHandler } from 'knifecycle';
import type {
WhookResponse,
WhookAPIHandlerDefinition,
WhookAPIParameterDefinition,
WhookHandlerFunction,
} from '@whook/whook';
import type { DelayService } from 'common-services';

export const pathParam1Parameter: WhookAPIParameterDefinition = {
name: 'pathParam1',
parameter: {
in: 'path',
name: 'pathParam1',
required: true,
description: 'Duration in milliseconds',
schema: {
type: 'number',
},
},
};
export const pathParam2Parameter: WhookAPIParameterDefinition = {
name: 'pathParam2',
parameter: {
in: 'path',
name: 'pathParam2',
required: true,
description: 'Duration in milliseconds',
schema: {
type: 'array',
items: {
type: 'string',
},
},
},
};

export const definition: WhookAPIHandlerDefinition = {
path: `/{${pathParam1Parameter.parameter.name}}/{${pathParam2Parameter.parameter.name}}`,
method: 'get',
operation: {
operationId: 'getParameters',
summary: 'An handler intended to test parameters.',
tags: ['example'],
parameters: [
{
$ref: `#/components/parameters/${pathParam1Parameter.name}`,
},
{
$ref: `#/components/parameters/${pathParam2Parameter.name}`,
},
{
in: 'header',
name: 'aHeader',
schema: {
type: 'boolean',
},
},
],
responses: {
204: {
description: 'Delay expired',
},
},
},
};

async function getParameters(
_,
{
aHeader,
pathParam1,
pathParam2,
}: {
aHeader: boolean;
pathParam1: number;
pathParam2: string[];
},
): Promise<
WhookResponse<
200,
{},
{ aHeader: boolean; pathParam1: number; pathParam2: string[] }
>
> {
return {
status: 200,
body: {
aHeader,
pathParam1,
pathParam2,
},
};
}

export default autoHandler(getParameters);
1 change: 1 addition & 0 deletions packages/whook-example/src/handlers/putEcho.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const definition: WhookAPIHandlerDefinition = {
tags: ['example'],
requestBody: {
description: 'The input sentence',
required: true,
content: {
'application/json': {
schema: echoSchema,
Expand Down
81 changes: 81 additions & 0 deletions packages/whook-example/src/services/__snapshots__/API.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Array [
"get /openAPI",
"get /ping",
"get /time",
"get /{pathParam1}/{pathParam2}",
"put /echo",
]
`;
Expand All @@ -25,12 +26,14 @@ Array [
"get /delay",
"get /ping",
"get /time",
"get /{pathParam1}/{pathParam2}",
"options /delay",
"options /diag",
"options /echo",
"options /openAPI",
"options /ping",
"options /time",
"options /{pathParam1}/{pathParam2}",
"put /echo",
]
`;
Expand All @@ -48,6 +51,7 @@ Array [
"get /openAPI",
"get /ping",
"get /time",
"get /{pathParam1}/{pathParam2}",
"put /echo",
]
`;
Expand All @@ -74,6 +78,27 @@ Object {
"type": "number",
},
},
"pathParam1": Object {
"description": "Duration in milliseconds",
"in": "path",
"name": "pathParam1",
"required": true,
"schema": Object {
"type": "number",
},
},
"pathParam2": Object {
"description": "Duration in milliseconds",
"in": "path",
"name": "pathParam2",
"required": true,
"schema": Object {
"items": Object {
"type": "string",
},
"type": "array",
},
},
},
"schemas": Object {
"TimeSchema": Object {
Expand Down Expand Up @@ -250,6 +275,7 @@ Object {
},
},
"description": "The input sentence",
"required": true,
},
"responses": Object {
"200": Object {
Expand Down Expand Up @@ -427,6 +453,61 @@ Object {
},
},
},
"/{pathParam1}/{pathParam2}": Object {
"get": Object {
"operationId": "getParameters",
"parameters": Array [
Object {
"$ref": "#/components/parameters/pathParam1",
},
Object {
"$ref": "#/components/parameters/pathParam2",
},
Object {
"in": "header",
"name": "aHeader",
"schema": Object {
"type": "boolean",
},
},
],
"responses": Object {
"204": Object {
"description": "Delay expired",
},
},
"summary": "An handler intended to test parameters.",
"tags": Array [
"example",
],
},
"options": Object {
"operationId": "optionsWithCORS",
"parameters": Array [
Object {
"$ref": "#/components/parameters/pathParam1",
},
Object {
"$ref": "#/components/parameters/pathParam2",
},
],
"responses": Object {
"200": Object {
"description": "CORS sent.",
},
},
"summary": "Enable OPTIONS for CORS",
"tags": Array [
"CORS",
],
"x-whook": Object {
"private": true,
"sourceOperationId": "getParameters",
"suffix": "CORS",
"type": "http",
},
},
},
},
"servers": Array [
Object {
Expand Down
10 changes: 6 additions & 4 deletions packages/whook-gcp-functions/src/commands/testHTTPFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ async function initTestHTTPLambdaCommand({
throw new YError('E_OPERATION_NOT_FOUND');
}

const hasBody = !!OPERATION.requestBody;
const parameters = JSON.parse(rawParameters);
const search = ((OPERATION.parameters || []) as OpenAPIV3.ParameterObject[])
.filter((p) => p.in === 'query')
.reduce((accSearch, p) => {
Expand Down Expand Up @@ -118,8 +120,6 @@ async function initTestHTTPLambdaCommand({
return part;
})
.join(PATH_SEPARATOR);
const hasBody = !!OPERATION.requestBody;
const parameters = JSON.parse(rawParameters);
const gcpfRequest = {
method: OPERATION.method,
originalUrl: path + (search ? SEARCH_SEPARATOR + search : ''),
Expand All @@ -132,8 +132,10 @@ async function initTestHTTPLambdaCommand({
rawBody: Buffer.from(
hasBody
? contentType === 'application/json'
? JSON.stringify(parameters.body)
: parameters.body
? parameters.body
? JSON.stringify(parameters.body)
: ''
: parameters.body || ''
: '',
),
};
Expand Down
Loading

0 comments on commit bd0f39b

Please sign in to comment.