packages/api-gateway/src/cli/create-endpoint.js
function executeCommand(parameters) {
    if (!parameters.role && parameters.roleManually) { parameters.role = parameters.roleManually; }
    if (parameters.resourcePath.charAt(0) !== '/') { parameters.resourcePath = '/' + parameters.resourcePath; }

    // We calculate the path where we will save the specification and create the directory
    // Destructuring parameters only available in node 6 :(
    // specFilePath = path.join(process.cwd(), 'endpoints', ...answers.resourcePath.split('/'));
    const pathParts = parameters.resourcePath.split('/');
    pathParts.push(parameters.httpMethod);
    pathParts.unshift(path.join(process.cwd(), plugin.config.endpointsPath));
    const specFilePath = path.join.apply(null, pathParts);

    return mkdirpAsync(specFilePath)
    .then(() => {
      // We create the endpoint Swagger/OpenAPI specification
      const spec = {
        'x-myrmex': {
          'apis': parameters.apis
        },
        summary: parameters.summary,
        consume: parameters.consume,
        produce: parameters.produce,
        responses: {
          '200': {}
        },
        'x-amazon-apigateway-auth': {
          type: parameters.auth
        },
        'x-amazon-apigateway-integration': {
          credentials: parameters.role,
          responses: {
            default: {
              statusCode: 200
            }
          }
        }
      };
      switch (parameters.integration) {
        case 'lambda-proxy':
          spec['x-amazon-apigateway-integration'].type = 'aws_proxy';
          spec['x-amazon-apigateway-integration'].contentHandling = 'CONVERT_TO_TEXT';
          spec['x-amazon-apigateway-integration'].passthroughBehavior = 'when_no_match';
          spec['x-amazon-apigateway-integration'].httpMethod = 'POST';
          break;
        case 'mock':
          spec['x-amazon-apigateway-integration'].requestTemplates = {
            'application/json': '{"statusCode": 200}'
          };
          spec['x-amazon-apigateway-integration'].type = 'mock';
          spec['x-amazon-apigateway-integration'].passthroughBehavior = 'when_no_match';
          break;
      }
      config.specModifiers.forEach(fn => { fn(spec, parameters); });

      // We save the specification in a json file
      return fs.writeFileAsync(path.join(specFilePath, 'spec.json'), JSON.stringify(spec, null, 2));
    })
    .then(() => {
      const msg = '\n  The endpoint ' + icli.format.info(parameters.httpMethod + ' ' + parameters.resourcePath) + ' has been created\n\n'
                + '  Its OpenAPI specification is available in ' + icli.format.info(specFilePath + path.sep + 'spec.json') + '\n'
                + '  You can inspect it using the command '
                + icli.format.cmd('myrmex inspect-endpoint ' + parameters.resourcePath + ' ' + parameters.httpMethod) + '\n';
      icli.print(msg);
    });
  }
function executeCommand(parameters) {
    if (!parameters.role && parameters.roleManually) { parameters.role = parameters.roleManually; }
    if (parameters.resourcePath.charAt(0) !== '/') { parameters.resourcePath = '/' + parameters.resourcePath; }

    // We calculate the path where we will save the specification and create the directory
    // Destructuring parameters only available in node 6 :(
    // specFilePath = path.join(process.cwd(), 'endpoints', ...answers.resourcePath.split('/'));
    const pathParts = parameters.resourcePath.split('/');
    pathParts.push(parameters.httpMethod);
    pathParts.unshift(path.join(process.cwd(), plugin.config.endpointsPath));
    const specFilePath = path.join.apply(null, pathParts);

    return mkdirpAsync(specFilePath)
    .then(() => {
      // We create the endpoint Swagger/OpenAPI specification
      const spec = {
        'x-myrmex': {
          'apis': parameters.apis
        },
        summary: parameters.summary,
        consume: parameters.consume,
        produce: parameters.produce,
        responses: {
          '200': {}
        },
        'x-amazon-apigateway-auth': {
          type: parameters.auth
        },
        'x-amazon-apigateway-integration': {
          credentials: parameters.role,
          responses: {
            default: {
              statusCode: 200
            }
          }
        }
      };
      switch (parameters.integration) {
        case 'lambda-proxy':
          spec['x-amazon-apigateway-integration'].type = 'aws_proxy';
          spec['x-amazon-apigateway-integration'].contentHandling = 'CONVERT_TO_TEXT';
          spec['x-amazon-apigateway-integration'].passthroughBehavior = 'when_no_match';
          spec['x-amazon-apigateway-integration'].httpMethod = 'POST';
          break;
        case 'mock':
          spec['x-amazon-apigateway-integration'].requestTemplates = {
            'application/json': '{"statusCode": 200}'
          };
          spec['x-amazon-apigateway-integration'].type = 'mock';
          spec['x-amazon-apigateway-integration'].passthroughBehavior = 'when_no_match';
          break;
      }
      config.specModifiers.forEach(fn => { fn(spec, parameters); });

      // We save the specification in a json file
      return fs.writeFileAsync(path.join(specFilePath, 'spec.json'), JSON.stringify(spec, null, 2));
    })
    .then(() => {
      const msg = '\n  The endpoint ' + icli.format.info(parameters.httpMethod + ' ' + parameters.resourcePath) + ' has been created\n\n'
                + '  Its OpenAPI specification is available in ' + icli.format.info(specFilePath + path.sep + 'spec.json') + '\n'
                + '  You can inspect it using the command '
                + icli.format.cmd('myrmex inspect-endpoint ' + parameters.resourcePath + ' ' + parameters.httpMethod) + '\n';
      icli.print(msg);
    });
  }
function executeCommand ( parameters ) { if ( ! parameters . role && parameters . roleManually ) { parameters . role = parameters . roleManually ; } if ( parameters . resourcePath . charAt ( 0 ) !== '/' ) { parameters . resourcePath = '/' + parameters . resourcePath ; } // We calculate the path where we will save the specification and create the directory // Destructuring parameters only available in node 6 :( // specFilePath = path.join(process.cwd(), 'endpoints', ...answers.resourcePath.split('/')); const pathParts = parameters . resourcePath . split ( '/' ) ; pathParts . push ( parameters . httpMethod ) ; pathParts . unshift ( path . join ( process . cwd ( ) , plugin . config . endpointsPath ) ) ; const specFilePath = path . join . apply ( null , pathParts ) ; return mkdirpAsync ( specFilePath ) . then ( ( ) => { // We create the endpoint Swagger/OpenAPI specification const spec = { 'x-myrmex' : { 'apis' : parameters . apis } , summary : parameters . summary , consume : parameters . consume , produce : parameters . produce , responses : { '200' : { } } , 'x-amazon-apigateway-auth' : { type : parameters . auth } , 'x-amazon-apigateway-integration' : { credentials : parameters . role , responses : { default : { statusCode : 200 } } } } ; switch ( parameters . integration ) { case 'lambda-proxy' : spec [ 'x-amazon-apigateway-integration' ] . type = 'aws_proxy' ; spec [ 'x-amazon-apigateway-integration' ] . contentHandling = 'CONVERT_TO_TEXT' ; spec [ 'x-amazon-apigateway-integration' ] . passthroughBehavior = 'when_no_match' ; spec [ 'x-amazon-apigateway-integration' ] . httpMethod = 'POST' ; break ; case 'mock' : spec [ 'x-amazon-apigateway-integration' ] . requestTemplates = { 'application/json' : '{"statusCode": 200}' } ; spec [ 'x-amazon-apigateway-integration' ] . type = 'mock' ; spec [ 'x-amazon-apigateway-integration' ] . passthroughBehavior = 'when_no_match' ; break ; } config . specModifiers . forEach ( fn => { fn ( spec , parameters ) ; } ) ; // We save the specification in a json file return fs . writeFileAsync ( path . join ( specFilePath , 'spec.json' ) , JSON . stringify ( spec , null , 2 ) ) ; } ) . then ( ( ) => { const msg = '\n  The endpoint ' + icli . format . info ( parameters . httpMethod + ' ' + parameters . resourcePath ) + ' has been created\n\n' + '  Its OpenAPI specification is available in ' + icli . format . info ( specFilePath + path . sep + 'spec.json' ) + '\n' + '  You can inspect it using the command ' + icli . format . cmd ( 'myrmex inspect-endpoint ' + parameters . resourcePath + ' ' + parameters . httpMethod ) + '\n' ; icli . print ( msg ) ; } ) ; }
Create the new endpoint
@param {Object} parameters - the parameters provided in the command and in the prompt
@returns {Promise<null>} - The execution stops here
Create the new endpoint