Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: missing baseurl on import openapi #3323

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type HoppImporterDefinition<T, Y, E> = {
export const defineImporter = <ReturnType, StepType, Errors>(input: {
id: string
name: string
icon: Component
icon: object | Component
importer: HoppImporter<ReturnType, StepType, Errors>
applicableTo: HoppImporterApplicableTo
steps: StepType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,32 @@ const parseOpenAPIAuth = (
? parseOpenAPIV3Auth(doc as OpenAPIV3.Document | OpenAPIV31.Document, op)
: parseOpenAPIV2Auth(doc as OpenAPIV2.Document, op)

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}`
}

/**
* 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 ?? "<<baseUrl>>"
}

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

const convertPathToHoppReqs = (
doc: OpenAPI.Document,
pathName: string,
Expand All @@ -535,7 +561,9 @@ const convertPathToHoppReqs = (
makeRESTRequest({
name: info.operationId ?? info.summary ?? "Untitled Request",
method: method.toUpperCase(),
endpoint: `<<baseUrl>>${replaceOpenApiPathTemplating(pathName)}`, // TODO: Make this proper
endpoint: `${parseOpenAPIUrl(doc)}${replaceOpenApiPathTemplating(
pathName
)}`,

// We don't need to worry about reference types as the Dereferencing pass should remove them
params: parseOpenAPIParams(
Expand Down