From dc78d51c8fc75234a7bb8ee96137984913b23598 Mon Sep 17 00:00:00 2001 From: Barduino Date: Sat, 9 Sep 2023 15:13:27 -0400 Subject: [PATCH] multi-auth: created convert and release for multi collections --- package.json | 8 ++- ...Collection_multi.js => CollectionMulti.js} | 49 ++++++++++--------- src/{OpenAPI_multi.js => OpenAPIMulti.js} | 6 +-- src/scripts/convert_multi.js | 4 +- src/scripts/release_multi.js | 5 +- 5 files changed, 40 insertions(+), 32 deletions(-) rename src/{Collection_multi.js => CollectionMulti.js} (94%) rename src/{OpenAPI_multi.js => OpenAPIMulti.js} (95%) diff --git a/package.json b/package.json index e7e6775..bcff795 100644 --- a/package.json +++ b/package.json @@ -50,8 +50,12 @@ "pretest": "yarn lint", "test": "jest", "lint": "standard --env jest", - "prerelease_multi_small": "node -e 'require(\"./src/scripts/convert.js\").convert()' multi small", - "release_multi_small": "node -e 'require(\"./src/scripts/release.js\").release()' multi small" + "//": "==============================", + "//": "multi auth collection scripts", + "//": "------------------------------", + "convert_multi": "node -e 'require(\"./src/scripts/convert_multi.js\").convert()'", + "release_multi": "node -e 'require(\"./src/scripts/release_multi.js\").release()'", + "//": "------------------------------" }, "private": true } \ No newline at end of file diff --git a/src/Collection_multi.js b/src/CollectionMulti.js similarity index 94% rename from src/Collection_multi.js rename to src/CollectionMulti.js index 1a96d61..9e85d16 100644 --- a/src/Collection_multi.js +++ b/src/CollectionMulti.js @@ -97,7 +97,7 @@ const byPriority = (a, b) => { /** * Our own opinionated OpenAPI to Postman converter */ -class Collection { +class CollectionMulti { /** * Accepts an OpenAPI object * @@ -148,9 +148,9 @@ class Collection { } else { this.createFolders() } - // this.insertEndpoints() - // this.pruneEmptyFolders() - // this.sortVerbs() + this.insertEndpoints() + this.pruneEmptyFolders() + this.sortVerbs() return this.folders } @@ -360,19 +360,21 @@ class Collection { authForEndPoint (endpoint) { // RB: if multi then inherit security from parent collection - if (this.LOCALE === 'MULTI') { return null } - if (endpoint.security && endpoint.security.length === 0) { - return { - type: 'noauth' - } - } else { - return this.defaultAuth() - } + return null + // if (this.LOCALE === 'MULTI') { return null } + // if (endpoint.security && endpoint.security.length === 0) { + // return { + // type: 'noauth' + // } + // } else { + // return this.defaultAuth() + // } } defaultAuth () { // RB: if multi the collection has bearer token - if (this.LOCALE === 'MULTI') { return this.authBearerToken() } else { return this.authOAuth() } + return this.authBearerToken() + // if (this.LOCALE === 'MULTI') { return this.authBearerToken() } else { return this.authOAuth() } } authBearerToken () { @@ -538,15 +540,16 @@ class Collection { */ getItemEvents (endpoint) { // RB: Dont add a script for endpoints if multi collection - if (this.LOCALE === 'MULTI') { return [] } - // Don't add a script for endpoints without auth - if (endpoint.operationId === 'post_oauth2_token#refresh') { - return [this.testUpdateAccessToken()] - } else if (endpoint.security && endpoint.security.length === 0) { - return [] - } else { - return [this.prerequestRefreshAccessToken()] - } + return [] + // if (this.LOCALE === 'MULTI') { return [] } + // // Don't add a script for endpoints without auth + // if (endpoint.operationId === 'post_oauth2_token#refresh') { + // return [this.testUpdateAccessToken()] + // } else if (endpoint.security && endpoint.security.length === 0) { + // return [] + // } else { + // return [this.prerequestRefreshAccessToken()] + // } } /** @@ -592,4 +595,4 @@ class Collection { } } -module.exports = Collection +module.exports = CollectionMulti diff --git a/src/OpenAPI_multi.js b/src/OpenAPIMulti.js similarity index 95% rename from src/OpenAPI_multi.js rename to src/OpenAPIMulti.js index e09c043..443c8b4 100644 --- a/src/OpenAPI_multi.js +++ b/src/OpenAPIMulti.js @@ -3,9 +3,9 @@ const deepmerge = require('deepmerge') const { Resolver } = require('@stoplight/json-ref-resolver') const { JSONPath } = require('jsonpath-plus') -const Collection = require('./Collection') +const Collection = require('./CollectionMulti') -class OpenAPI { +class OpenAPIMulti { constructor (filename, locale, small = false) { this.filename = filename this.openapi = null @@ -80,4 +80,4 @@ class OpenAPI { } } -module.exports = OpenAPI +module.exports = OpenAPIMulti diff --git a/src/scripts/convert_multi.js b/src/scripts/convert_multi.js index e024f5e..90d0c15 100644 --- a/src/scripts/convert_multi.js +++ b/src/scripts/convert_multi.js @@ -1,6 +1,6 @@ require('dotenv').config() -const OpenAPI = require('../OpenAPI') +const OpenAPI = require('../OpenAPIMulti') const Path = require('../Path') const Writer = require('../Writer') @@ -17,7 +17,7 @@ const convert = async (locale = process.argv[1], small = process.argv[2]) => { const collection = await openapi.convert() const writer = new Writer(collection) - writer.dump(OUTPUT_FOLDER, `collection.${locale}.json`) + writer.dump(OUTPUT_FOLDER, `collection.multi.${locale}.json`) } const convertAll = async () => { diff --git a/src/scripts/release_multi.js b/src/scripts/release_multi.js index c10f283..417e791 100644 --- a/src/scripts/release_multi.js +++ b/src/scripts/release_multi.js @@ -8,13 +8,14 @@ const axios = require('axios') const OUTPUT_FOLDER = './compiled' const release = async (locale = process.argv[1]) => { - const collection = JSON.parse(fs.readFileSync(`${OUTPUT_FOLDER}/collection.${locale}.json`).toString()) - const collectionId = process.env[`${locale.toUpperCase()}_POSTMAN_COLLECTION_ID`] + const collection = JSON.parse(fs.readFileSync(`${OUTPUT_FOLDER}/collection.multi.${locale}.json`).toString()) + const collectionId = process.env[`${locale.toUpperCase()}_POSTMAN_COLLECTION_MULTI_ID`] // prevent old folders from remaining in place by first removing all items const emptyCollection = { ...collection } emptyCollection.item = [] console.log('UUID v5 AAAAA:', uuid.v5('AAAAA', NAMESPACE)) + console.log('Collectio ID: ', collectionId) // console.log('Empty Collection:',{ collection: emptyCollection })