Skip to content

Commit

Permalink
feat: wso2-api tested and working
Browse files Browse the repository at this point in the history
  • Loading branch information
flaviostutz committed Jan 26, 2024
1 parent 9d9b629 commit 7eb3238
Show file tree
Hide file tree
Showing 12 changed files with 394 additions and 30 deletions.
2 changes: 1 addition & 1 deletion examples/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"@types/aws-lambda": "^8.10.131",
"@types/jest": "^29.4.0",
"@types/lodash.clonedeep": "^4.5.9",
"@types/lodash.isequal": "^4.5.8",
"@types/node": "18.11.18",
"@types/npm-which": "^3.0.3",
"@types/qs": "^6.9.11",
Expand Down
9 changes: 0 additions & 9 deletions lib/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

255 changes: 255 additions & 0 deletions lib/src/wso2/wso2-api/__tests__/petstore-wso2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,255 @@
import { OpenAPIObject } from 'openapi3-ts/oas30';

/**
* Wso2 openapi doc returned by WSO2 when we submit the "petstore" version
*/
export const petstoreOpenapiReturnedWso2v1: OpenAPIObject = {
openapi: '3.0.0',
info: {
title: 'Swagger Petstore',
license: {
name: 'MIT',
},
version: 'v1',
},
servers: [
{
url: 'http://petstore.swagger.io/v1',
},
],
security: [
{
default: [],
},
],
paths: {
'/pets': {
get: {
tags: ['pets'],
summary: 'List all pets',
operationId: 'listPets',
parameters: [
{
name: 'limit',
in: 'query',
description: 'How many items to return at one time (max 100)',
required: false,
style: 'form',
explode: true,
schema: {
type: 'integer',
format: 'int32',
},
},
],
responses: {
'200': {
description: 'A paged array of pets',
headers: {
'x-next': {
description: 'A link to the next page of responses',
style: 'simple',
explode: false,
schema: {
type: 'string',
},
},
},
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/Pets',
},
},
},
},
default: {
description: 'unexpected error',
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/Error',
},
},
},
},
},
security: [
{
default: [],
},
],
'x-throttling-tier': 'Unlimited',
'x-wso2-application-security': {
'security-types': ['oauth2'],
optional: false,
},
},
post: {
tags: ['pets'],
summary: 'Create a pet',
operationId: 'createPets',
requestBody: {
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/Pet',
},
},
},
required: true,
},
responses: {
'201': {
description: 'Null response',
},
default: {
description: 'unexpected error',
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/Error',
},
},
},
},
},
security: [
{
default: [],
},
],
'x-throttling-tier': 'Unlimited',
'x-wso2-application-security': {
'security-types': ['oauth2'],
optional: false,
},
},
},
'/pets/{petId}': {
get: {
tags: ['pets'],
summary: 'Info for a specific pet',
operationId: 'showPetById',
parameters: [
{
name: 'petId',
in: 'path',
description: 'The id of the pet to retrieve',
required: true,
style: 'simple',
explode: false,
schema: {
type: 'string',
},
},
],
responses: {
'200': {
description: 'Expected response to a valid request',
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/Pet',
},
},
},
},
default: {
description: 'unexpected error',
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/Error',
},
},
},
},
},
security: [
{
default: [],
},
],
'x-throttling-tier': 'Unlimited',
'x-wso2-application-security': {
'security-types': ['oauth2'],
optional: false,
},
},
},
},
components: {
schemas: {
Pets: {
type: 'array',
items: {
$ref: '#/components/schemas/Pet',
},
},
Error: {
required: ['code', 'message'],
type: 'object',
properties: {
code: {
type: 'integer',
format: 'int32',
},
message: {
type: 'string',
},
},
},
Pet: {
required: ['id', 'name'],
type: 'object',
properties: {
name: {
type: 'string',
},
id: {
type: 'integer',
format: 'int64',
},
tag: {
type: 'string',
},
},
},
},
securitySchemes: {
default: {
type: 'oauth2',
flows: {
implicit: {
authorizationUrl: 'https://test.com',
scopes: {},
},
},
},
},
},
'x-throttling-tier': 'Unlimited',
'x-wso2-cors': {
corsConfigurationEnabled: true,
accessControlAllowOrigins: ['testwebsite.com'],
accessControlAllowCredentials: false,
accessControlAllowHeaders: [
'Authorization',
'Access-Control-Allow-Origin',
'Content-Type',
'SOAPAction',
],
accessControlAllowMethods: ['GET', 'PUT', 'POST', 'DELETE', 'PATCH', 'OPTIONS'],
},
'x-wso2-production-endpoints': {
urls: ['http://serverabc.com'],
type: 'http',
},
'x-wso2-basePath': '/t/nn.nl/petstore/v1',
'x-wso2-transports': ['https'],
'x-wso2-response-cache': {
enabled: false,
cacheTimeoutInSeconds: 300,
},
};
2 changes: 1 addition & 1 deletion lib/src/wso2/wso2-api/__tests__/petstore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { OpenAPIObject } from 'openapi3-ts/oas30';
export const petstoreOpenapi: OpenAPIObject = {
openapi: '3.0.0',
info: {
version: '1.0.0',
version: 'v1',
title: 'Swagger Petstore',
license: {
name: 'MIT',
Expand Down
4 changes: 2 additions & 2 deletions lib/src/wso2/wso2-api/handler/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('wso2 custom resource lambda', () => {
beforeEach(() => {
nock.cleanAll();
// silence verbose console logs. comment this for debugging
console.log = (): void => {};
// console.log = (): void => {};
});
afterEach(() => {
console.log = originalConsoleLog;
Expand Down Expand Up @@ -336,7 +336,7 @@ describe('wso2 custom resource lambda', () => {
id: apiDefs.id ?? 'INVALID',
context: apiDefs.context,
name: apiDefs.name,
status: apiDefs.lifeCycleStatus ?? 'INVALID',
lifeCycleStatus: apiDefs.lifeCycleStatus ?? 'INVALID',
version: apiDefs.version,
provider: apiDefs.provider,
type: apiDefs.type,
Expand Down
8 changes: 4 additions & 4 deletions lib/src/wso2/wso2-api/handler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const handler = async (
if (err.stack) {
console.log(err.stack);
}
throw error;
throw new Error(truncateStr(`${error}`, 1000));
}
};

Expand Down Expand Up @@ -187,6 +187,6 @@ const applyRetryDefaults = (retryOptions?: RetryOptions): RetryOptions => {
return ropts;
};

// const truncateStr = (str: string, size: number): string => {
// return str.substring(0, Math.min(str.length, size));
// };
const truncateStr = (str: string, size: number): string => {
return str.substring(0, Math.min(str.length, size));
};
48 changes: 48 additions & 0 deletions lib/src/wso2/wso2-api/handler/utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* eslint-disable no-undefined */
import { areAttributeNamesEqual } from './utils';

describe('areAttributeNamesEqual', () => {
it('should return true for objects with the same attribute names', () => {
const objA = { name: 'John', age: 30, city: 'New York' };
const objB = { age: 30, name: 'John', city: 'New York' };

const result = areAttributeNamesEqual(objA, objB);

expect(result).toBe(true);
});

it('should return false for objects with different attribute names', () => {
const objA = { name: 'John', age: 30, city: 'New York' };
const objB = { age: 30, country: 'USA', city: 'New York' };

const result = areAttributeNamesEqual(objA, objB);

expect(result).toBe(false);
});

it('should return true for both undefined objects', () => {
const objA = undefined;
const objB = undefined;

const result = areAttributeNamesEqual(objA, objB);

expect(result).toBe(true);
});
it('should return false if only one of the objects are undefined', () => {
const objA = undefined;
const objB = { test: 'SOMETHING' };

const result = areAttributeNamesEqual(objA, objB);

expect(result).toBe(false);
});

it('should return false for one undefined object', () => {
const objA = { name: 'John', age: 30, city: 'New York' };
const objB = undefined;

const result = areAttributeNamesEqual(objA, objB);

expect(result).toBe(false);
});
});
Loading

0 comments on commit 7eb3238

Please sign in to comment.