Skip to content

Commit

Permalink
Apply casing to auth variable (#668)
Browse files Browse the repository at this point in the history
  • Loading branch information
thim81 authored Oct 26, 2024
1 parent 1343877 commit 23f8a0e
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/application/CollectionWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import { GlobalConfig, PortmanConfig, PortmanOptions } from '../types'
import { isEmptyObject } from '../utils'
import { writeCollectionTestScripts } from './globals/writeCollectionTestScripts'
import { changeCase } from 'openapi-format'

export class CollectionWriter {
public collection: CollectionDefinition
Expand All @@ -38,11 +39,33 @@ export class CollectionWriter {
valueReplacements = {},
rawReplacements = [],
orderOfOperations = [],
orderOfFolders = []
orderOfFolders = [],
variableCasing
} = globals as GlobalConfig

let collection = this.collection

// --- Portman - Apply casing to auth variable
if (collection.auth && variableCasing) {
if (collection.auth.bearer) {
collection.auth.bearer = collection.auth.bearer.map(el =>
el.key === 'token' && el.value.includes('{{') && el.value.includes('}}')
? { ...el, value: '{{' + changeCase(el.value, variableCasing ?? 'camelCase') + '}}' }
: el
)
}

if (collection.auth.apikey) {
collection.auth.apikey = collection.auth.apikey.map(el =>
(el.key === 'key' || el.key === 'in' || el.key === 'value') &&
el.value.includes('{{') &&
el.value.includes('}}')
? { ...el, value: '{{' + changeCase(el.value, variableCasing ?? 'camelCase') + '}}' }
: el
)
}
}

// --- Portman - Set Postman collection variables
if (collectionVariables && Object.keys(collectionVariables).length > 0) {
collection = writeCollectionVariables(collection, collectionVariables)
Expand Down

0 comments on commit 23f8a0e

Please sign in to comment.