Skip to content

Commit

Permalink
multi-auth: created convert and release for multi collections
Browse files Browse the repository at this point in the history
  • Loading branch information
barduinor committed Sep 9, 2023
1 parent fa74b9b commit dc78d51
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 32 deletions.
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
49 changes: 26 additions & 23 deletions src/Collection_multi.js → src/CollectionMulti.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const byPriority = (a, b) => {
/**
* Our own opinionated OpenAPI to Postman converter
*/
class Collection {
class CollectionMulti {
/**
* Accepts an OpenAPI object
*
Expand Down Expand Up @@ -148,9 +148,9 @@ class Collection {
} else {
this.createFolders()
}
// this.insertEndpoints()
// this.pruneEmptyFolders()
// this.sortVerbs()
this.insertEndpoints()
this.pruneEmptyFolders()
this.sortVerbs()
return this.folders
}

Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -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()]
// }
}

/**
Expand Down Expand Up @@ -592,4 +595,4 @@ class Collection {
}
}

module.exports = Collection
module.exports = CollectionMulti
6 changes: 3 additions & 3 deletions src/OpenAPI_multi.js → src/OpenAPIMulti.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -80,4 +80,4 @@ class OpenAPI {
}
}

module.exports = OpenAPI
module.exports = OpenAPIMulti
4 changes: 2 additions & 2 deletions src/scripts/convert_multi.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require('dotenv').config()

const OpenAPI = require('../OpenAPI')
const OpenAPI = require('../OpenAPIMulti')
const Path = require('../Path')
const Writer = require('../Writer')

Expand All @@ -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 () => {
Expand Down
5 changes: 3 additions & 2 deletions src/scripts/release_multi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })

Expand Down

0 comments on commit dc78d51

Please sign in to comment.