Skip to content

Instantly share code, notes, and snippets.

function checkNameSpace(parent, nested) {
nested = nested || '';
return typeof parent === 'object' &&
typeof nested === 'string' &&
typeof nested
.split(/[\.\["'\]]/)
.filter(function(el) {
return el;
})
.reduce(function(acc, nested) {
function splitBy (by, str) {
return (function splitByFourAux (input, index, acc, string) {
return index > input.length -1 ?
(string ? acc.concat(string) : acc) :
index % by === by - 1 ?
splitByFourAux(input, index + 1, acc.concat(string.concat(input.charAt(index))), '') :
splitByFourAux(input, index + 1, acc, string.concat(input.charAt(index)));
})(str, 0, [], '');
}
function compressString (str) {
return (function compressAux(str, index, acc) {
return index > str.length -1 ?
'' :
str.charAt(index) === str.charAt(index + 1) ?
compressAux(str, ++index, ++acc) :
str.charAt(index) + (acc !== 1 ? acc : '') + compressAux(str, ++index, 1);
})(str, 0, 1);
}
function _get(parent, nested) {
return typeof nested === 'string' ?
(typeof parent === 'object' &&
nested
.split(/[\.\["'\]]/)
.filter(Boolean)
.reduce(function(acc, current) {
return acc && acc[current]
}, parent)) :
parent;
var puntillo = (function () {
function get(parent, nested, defValue) {
return splitMy(nested)
.reduce(function(acc, current) {
return acc ? acc[current] : defValue;
}, parent);
}
function set(parent, nested, defValue) {
return splitMy(nested)
plugins:
- serverless-s3-sync
custom:
s3Sync:
- bucketName: swagger-site-${opt:stage, 'dev'}
localDir: swagger-ui-dist
deleteRemoved: true # optional, indicates whether sync deletes files no longer present in localDir. Defaults to 'true'
acl: public-read # optional
followSymlinks: true # optional
defaultContentType: text/html # optional
resources:
Resources:
ApiGatewayRestApi:
Type: AWS::ApiGateway::RestApi
Description: Gateway to the s3 Swagger site
Properties:
Name: swagger-${opt:stage, 'dev'}
EndpointConfiguration:
Types:
- REGIONAL
ApiGatewayMethodGetRoot:
Type: AWS::ApiGateway::Method
Description: Located at root resource to proxy to S3 bucket website
Properties:
HttpMethod: GET
ResourceId:
Fn::GetAtt: [ApiGatewayRestApi, RootResourceId]
RestApiId: !Ref ApiGatewayRestApi
ApiKeyRequired: false
AuthorizationType: NONE
ApiGatewayResourceItem:
Type: AWS::ApiGateway::Resource
Properties:
ParentId:
Fn::GetAtt: [ApiGatewayRestApi, RootResourceId]
PathPart: '{item}'
RestApiId: !Ref ApiGatewayRestApi
ApiGatewayMethodGetItem:
Type: AWS::ApiGateway::Method
Description: Located at {item} resource to get items from S3 bucket
GatewayRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- apigateway.amazonaws.com