Skip to content

Commit

Permalink
updated spec generation
Browse files Browse the repository at this point in the history
  • Loading branch information
tyayers committed Mar 3, 2024
1 parent 7cbefe8 commit 9787cb7
Show file tree
Hide file tree
Showing 21 changed files with 611 additions and 187 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
node_modules
dist
proxies
output
build
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ let input: ApigeeTemplateInput = {
],
auth: [
{
type: authTypes.apikey
type: authTypes.apiKey
}
]
}
Expand Down
8 changes: 4 additions & 4 deletions cli/package-lock.json

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

4 changes: 2 additions & 2 deletions cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apigee-templater",
"version": "2.5.4",
"version": "2.6.3",
"description": "A CLI to easily template and deploy Apigee proxies.",
"homepage": "https://github.com/tyayers/apigee-templater",
"bugs": "https://github.com/tyayers/apigee-templater/issues",
Expand Down Expand Up @@ -28,7 +28,7 @@
"author": "tayers",
"license": "ISC",
"dependencies": {
"apigee-templater-module": "^2.5.4",
"apigee-templater-module": "^2.6.3",
"apigee-x-module": "^1.0.1",
"arg": "^5.0.1",
"axios": "^1.6.2",
Expand Down
55 changes: 51 additions & 4 deletions cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ import fs from 'fs'
import { performance } from 'perf_hooks'
import inquirer from 'inquirer'
import chalk from 'chalk'
import { ApigeeTemplateInput, ApigeeTemplateService, ApigeeTemplater, GenerateResult, authTypes } from 'apigee-templater-module'
import { ApigeeTemplateInput, ApigeeTemplateService, ApigeeTemplater, GenerateResult, SpecType, authTypes } from 'apigee-templater-module'
import { ApigeeService, ApiManagementInterface, EnvironmentGroup, EnvironmentGroupAttachment, ProxyDeployment, ProxyRevision } from 'apigee-x-module'

import axios from 'axios';
import { stdin } from 'process'

process.on('uncaughtException', function (e) {
if (e.message.includes("Unable to detect a Project Id in the current environment")) {
Expand Down Expand Up @@ -226,6 +227,20 @@ export class cli {
}
}

processDataSpec(): Promise<string> {
return new Promise<string>((resolve, reject) => {
let receivedData = '';
stdin.on('data', (data) => {
receivedData += data;
});
stdin.on('end', () => {
// Input will have a \n appended
// receivedData = receivedData.slice(0, -1);
resolve(receivedData);
});
});
}

/**
* Process the user inputs and generates / deploys the proxy
* @date 1/31/2022 - 8:42:28 AM
Expand All @@ -234,6 +249,34 @@ export class cli {
* @param {cliArgs} args The user input args to the process
*/
async process(args: string[]) {

if (!stdin.setRawMode) {
// We have received raw data piped in, so do our spec generation
let payloadInput = await this.processDataSpec();

console.log(args);
console.log(payloadInput);
let servers: string[] = [];
let addExamples = false;
let addDescriptions = false;
let auth = authTypes.none;
for (let argIndex=0; argIndex<args.length; argIndex++) {
if (args[argIndex] === "-s" && argIndex < (args.length - 1))
servers.push(args[argIndex + 1]);
else if (args[argIndex] === "-ad")
addDescriptions = true;
else if (args[argIndex] === "-ae")
addExamples = true;
else if (args[argIndex] === "-a")
auth = authTypes.apiKey;
}

let specResult = await this.apigeeTemplater.generateSpec(payloadInput, SpecType.Data, servers, auth, addExamples, addDescriptions);
console.log(specResult);

return;
}

let options: cliArgs = this.parseArgumentsIntoOptions(args);
if (options.verbose && fs.existsSync("apigee-templater-log.txt")) {
// Delete old log file, if it exists
Expand All @@ -247,8 +290,8 @@ export class cli {
if (options.verbose) this.logVerbose(JSON.stringify(options, null, 2), 'start:');

if (options.help) {
this.printHelp()
return
this.printHelp();
return;
}

if (options.file) {
Expand Down Expand Up @@ -316,7 +359,7 @@ export class cli {
if (options.apiKey) {
newInput.endpoints[0].auth = [
{
type: authTypes.apikey,
type: authTypes.apiKey,
parameters: {}
}
]
Expand Down Expand Up @@ -552,6 +595,10 @@ const helpCommands = [
name: '--verbose, -v',
description: 'If extra logging information should be printed during the conversion and deployment.'
},
{
name: '--datSpec, -ds',
description: 'Generates an OpenAPI spec for a data payload that is piped to the command (only GET).'
},
{
name: '--keyPath, -k',
description: 'If no GOOGLE_APPLICATION_CREDENTIALS are set to authorize the proxy deployment, this can point to a GCP service account JSON key file to use for authorization.'
Expand Down
2 changes: 1 addition & 1 deletion docs/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
"enum": [
"basic",
"oauth2",
"apikey"
"apiKey"
]
}
}
Expand Down
2 changes: 1 addition & 1 deletion module/.mocharc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extensions": ["ts"],
"spec": ["test/*.test.js"],
"spec": ["test/*.test.js", "test/*.test.ts"],
"node-option": [
"experimental-specifier-resolution=node",
"loader=ts-node/esm"
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 9787cb7

Please sign in to comment.