Skip to content

Commit

Permalink
fix: url parser for openapi v3
Browse files Browse the repository at this point in the history
  • Loading branch information
anwarulislam committed Sep 17, 2023
1 parent dfd1bb3 commit dae5386
Showing 1 changed file with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -514,15 +514,30 @@ const parseOpenAPIAuth = (
? parseOpenAPIV3Auth(doc as OpenAPIV3.Document | OpenAPIV31.Document, op)
: parseOpenAPIV2Auth(doc as OpenAPIV2.Document, op)

const parseOpenAPIUrl = (doc: OpenAPI.Document): string => {
let url = ""
if (objectHasProperty(doc, "host")) {
url += doc.host
const parseOpenAPIUrl = (
doc: OpenAPI.Document | OpenAPIV2.Document | OpenAPIV3.Document
): string => {
/**
* OpenAPI V2 has version as a string in the document's swagger property.
* And host and basePath are in the document's host and basePath properties.
* Relevant v2 reference: https://swagger.io/specification/v2/#:~:text=to%20be%20obscured.-,Schema,-Swagger%20Object
**/

if (objectHasProperty(doc, "swagger")) {
return `${doc.host}${doc.basePath}`
}
if (objectHasProperty(doc, "basePath")) {
url += doc.basePath

/**
* OpenAPI V3 has version as a string in the document's openapi property.
* And host and basePath are in the document's servers property.
* Relevant v3 reference: https://swagger.io/specification/#server-object
**/
if (objectHasProperty(doc, "servers")) {
return doc.servers?.[0].url ?? ""
}
return url

// If the document is neither v2 nor v3 then return a env variable as placeholder
return "<<baseUrl>>"
}

const convertPathToHoppReqs = (
Expand Down

0 comments on commit dae5386

Please sign in to comment.