Socket
Socket
Sign inDemoInstall

@bearer/openapi-generator

Package Overview
Dependencies
10
Maintainers
4
Versions
174
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.100.1-canary.25 to 0.100.1-canary.31

2

CHANGELOG.md

@@ -46,3 +46,3 @@ # Change Log

* **openapi-generator:** fix the intent order ([#545](https://github.com/Bearer/bearer/issues/545)) ([14c1087](https://github.com/Bearer/bearer/commit/14c1087))
* **openapi-generator:** fix the func order ([#545](https://github.com/Bearer/bearer/issues/545)) ([14c1087](https://github.com/Bearer/bearer/commit/14c1087))

@@ -49,0 +49,0 @@

import ts from 'typescript';
export declare const INTENT_ACTION = "action";
export declare const FUNCTION_ACTION = "action";
declare type TOutput = {
requestBody: any;
response: any;
intentAuthType?: string;
functionAuthType?: string;
};
/**
* Convert single intent types to json schema
* Convert single func types to json schema
* This function tries to find the relevant type definitions, Params and `action` method resposne type
* and converts the types to json-schema
* @param intentPath absolute path to intent
* @param functionPath absolute path to function
* @param options compiler options
*/
export declare function intentTypesToSchemaConverter(intentPath: string, options?: ts.CompilerOptions): TOutput;
export declare function functionTypesToSchemaConverter(functionPath: string, options?: ts.CompilerOptions): TOutput;
/**
* Generate full openapi spec from intents
* @param intentsDir absolute path to intents directory
* @param intents list of intent names
* Generate full openapi spec from functions
* @param functionsDir absolute path to functions directory
* @param functions list of func names
* @param integrationUuid integration unique identifier
* @param integrationName name of the integration
*/
export default function generator({ intentsDir, intents, integrationUuid, integrationName }: {
intentsDir: string;
intents: string[];
export default function generator({ functionsDir, functions, integrationUuid, integrationName }: {
functionsDir: string;
functions: string[];
integrationUuid: string;

@@ -27,0 +27,0 @@ integrationName: string;

@@ -10,3 +10,3 @@ "use strict";

const convert_type_1 = require("./convert-type");
exports.INTENT_ACTION = 'action';
exports.FUNCTION_ACTION = 'action';
/**

@@ -18,3 +18,3 @@ * find action method in class and return relevant node

if (node.name) {
return node.name.getText() === exports.INTENT_ACTION;
return node.name.getText() === exports.FUNCTION_ACTION;
}

@@ -61,3 +61,3 @@ return false;

/**
* Find the Parameter type in intent and convert it to json-schema
* Find the Parameter type in func and convert it to json-schema
*/

@@ -79,3 +79,3 @@ function serializeParameters(sym, node, checker) {

*/
function getIntentAuthType(sym, node, checker) {
function getFunctionAuthType(sym, node, checker) {
if (sym) {

@@ -104,11 +104,11 @@ const typ = checker.getTypeOfSymbolAtLocation(sym, node);

/**
* Convert single intent types to json schema
* Convert single func types to json schema
* This function tries to find the relevant type definitions, Params and `action` method resposne type
* and converts the types to json-schema
* @param intentPath absolute path to intent
* @param functionPath absolute path to function
* @param options compiler options
*/
function intentTypesToSchemaConverter(intentPath, options = { target: typescript_1.default.ScriptTarget.ES5, module: typescript_1.default.ModuleKind.CommonJS }) {
const program = typescript_1.default.createProgram([intentPath], options);
const sourceFile = program.getSourceFile(intentPath);
function functionTypesToSchemaConverter(functionPath, options = { target: typescript_1.default.ScriptTarget.ES5, module: typescript_1.default.ModuleKind.CommonJS }) {
const program = typescript_1.default.createProgram([functionPath], options);
const sourceFile = program.getSourceFile(functionPath);
const checker = program.getTypeChecker();

@@ -135,3 +135,3 @@ const output = {

output.response = serializeBody(actionMethodNode, checker);
output.intentAuthType = getIntentAuthType(sym, parameterNode, checker);
output.functionAuthType = getFunctionAuthType(sym, parameterNode, checker);
}

@@ -145,21 +145,21 @@ }

}
exports.intentTypesToSchemaConverter = intentTypesToSchemaConverter;
exports.functionTypesToSchemaConverter = functionTypesToSchemaConverter;
/**
* Generate full openapi spec from intents
* @param intentsDir absolute path to intents directory
* @param intents list of intent names
* Generate full openapi spec from functions
* @param functionsDir absolute path to functions directory
* @param functions list of func names
* @param integrationUuid integration unique identifier
* @param integrationName name of the integration
*/
function generator({ intentsDir, intents, integrationUuid, integrationName }) {
function generator({ functionsDir, functions, integrationUuid, integrationName }) {
const doc = openapi_template_1.topOfSpec(integrationName);
const schemas = intents.sort().reduce((acc, intent) => {
const intentPath = path_1.default.join(intentsDir, `${intent}.ts`);
const typeSchema = intentTypesToSchemaConverter(intentPath);
const schemas = functions.sort().reduce((acc, func) => {
const functionPath = path_1.default.join(functionsDir, `${func}.ts`);
const typeSchema = functionTypesToSchemaConverter(functionPath);
return Object.assign(acc, openapi_template_1.specPath({
integrationUuid,
intentName: intent,
functionName: func,
response: { type: 'object', properties: typeSchema.response },
requestBody: typeSchema.requestBody,
oauth: typeSchema.intentAuthType === 'OAUTH2' || typeSchema.intentAuthType === 'OAUTH1'
oauth: typeSchema.functionAuthType === 'OAUTH2' || typeSchema.functionAuthType === 'OAUTH1'
}));

@@ -166,0 +166,0 @@ }, {});

@@ -36,5 +36,5 @@ declare type THeader = {

};
export declare function specPath({ integrationUuid, intentName, requestBody, response, oauth }: {
export declare function specPath({ integrationUuid, functionName, requestBody, response, oauth }: {
integrationUuid: string;
intentName: string;
functionName: string;
requestBody: any;

@@ -41,0 +41,0 @@ response: any;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function specPath({ integrationUuid, intentName, requestBody, response, oauth }) {
function specPath({ integrationUuid, functionName, requestBody, response, oauth }) {
return {
[`/${integrationUuid}/${intentName}`]: {
[`/${integrationUuid}/${functionName}`]: {
post: {

@@ -17,6 +17,6 @@ parameters: [

].filter(e => e !== undefined),
summary: intentName,
summary: functionName,
requestBody: { content: { 'application/json': { schema: requestBody } } },
responses: {
'200': { description: intentName, content: { 'application/json': { schema: response } } },
'200': { description: functionName, content: { 'application/json': { schema: response } } },
'401': {

@@ -62,3 +62,3 @@ description: 'Access forbidden',

},
servers: [{ url: 'https://int.bearer.sh/api/v2/intents/backend/' }],
servers: [{ url: 'https://int.bearer.sh/api/v2/functions/backend/' }],
tags: [

@@ -65,0 +65,0 @@ {

{
"name": "@bearer/openapi-generator",
"version": "0.100.1-canary.25+f940327d",
"description": "Intent openapi spec generator",
"version": "0.100.1-canary.31+3bc23db0",
"description": "Function openapi spec generator",
"main": "lib/index.js",

@@ -32,6 +32,6 @@ "repository": "Bearer/bearer",

"dependencies": {
"@bearer/intents": "^0.99.0",
"@bearer/functions": "^0.100.1-canary.31+3bc23db0",
"lodash.merge": "^4.6.1"
},
"gitHead": "f940327ddcfb8d1956bc3ca20aa2b420e95ed9aa"
"gitHead": "3bc23db0fb71154243e0b72f7943c9e0c4d174ce"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc