Skip to content

Commit

Permalink
fixed some bugs with p2o and fix + update dojah submodule SHA
Browse files Browse the repository at this point in the history
  • Loading branch information
eddiechayes committed Jul 28, 2023
1 parent c7143f8 commit daf0e05
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
2 changes: 1 addition & 1 deletion customers/dojah/dojah-sdks
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
getOperations,
Operation,
OperationParameter,
resolveRef,
Spec,
} from 'konfig-lib'
import {
Expand Down Expand Up @@ -71,6 +72,44 @@ export async function fixAdvSecuritySchemesDefined({
continue
}
}

const existingSecurity =
spec.spec.components?.securitySchemes !== undefined
? Object.entries(spec.spec.components.securitySchemes).find(
([securityName, s]) => {
const resolved = resolveRef({ refOrObject: s, $ref: spec.$ref })
if (resolved.type !== 'apiKey') return
return (
resolved.name.toLowerCase() === parameter.name.toLowerCase()
)
}
)
: undefined
if (existingSecurity !== undefined) {
const securitySchemeObject = resolveRef({
refOrObject: existingSecurity[1],
$ref: spec.$ref,
})
if (securitySchemeObject.type !== 'apiKey')
throw Error(
'unexpected security scheme type when replacing case in-sensitive parameter'
)
const securityScheme: SecuritySchemeObject = {
in: securitySchemeObject.in as any,
name: securitySchemeObject.name,
type: 'apiKey',
securityName: existingSecurity[0],
}
await removeParameterForSecurityRequirement({
spec,
name: parameter.name,
parameterIn: parameter.in,
securityScheme,
operation,
})
continue;
}

const { securityName, isSecurity } = await inquirer.prompt<{
securityName: string
isSecurity: boolean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { IFunctionResult, RulesetFunction } from '@stoplight/spectral-core'
import type { ParameterObject } from '../parseSpec'

export const disallowedHeadersRegex = /^(Content-Type|Authorization|Accept)$/
export const disallowedHeadersRegex = /^(Content-Type|Accept)$/

export async function isParameterDisallowed({
parameter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,15 +459,15 @@ function generateSecurityScheme(auth) {
const name = auth.apikey.find((obj) => obj.key === 'key')?.value
return {
type: 'apiKey',
in: where === undefined ? 'Header' : where,
in: where === undefined ? 'header' : where,
name,
}
}

/* Parse a postman auth definition */
function parsePostmanAuth(postmanAuth = {}, securitySchemes) {
const { type } = postmanAuth
if (type != null) {
if (type != null && type !== "noauth") {
securitySchemes[`${type}Auth`] = generateSecurityScheme(postmanAuth)
return {
components: { securitySchemes },
Expand All @@ -483,7 +483,7 @@ function parsePostmanAuth(postmanAuth = {}, securitySchemes) {

/* Parse Auth at operation/request level */
function parseOperationAuth(auth, securitySchemes, optsAuth) {
if (auth == null || optsAuth != null) {
if (auth == null || optsAuth != null || auth.type === "noauth") {
// In case of config auth operation auth is disabled
return {}
} else {
Expand Down

0 comments on commit daf0e05

Please sign in to comment.