Add full URL to path for imported queries
This commit is contained in:
parent
b1ef2e3988
commit
d74d1d66b8
|
@ -1,7 +1,7 @@
|
|||
import { Query, QueryParameter } from "../../../../../../definitions/datasource"
|
||||
import { URL } from "url"
|
||||
|
||||
export interface ImportInfo {
|
||||
url: string
|
||||
name: string
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@ export abstract class ImportSource {
|
|||
name: string,
|
||||
method: string,
|
||||
path: string,
|
||||
url: URL,
|
||||
queryString: string,
|
||||
headers: object = {},
|
||||
parameters: QueryParameter[] = [],
|
||||
|
@ -33,6 +34,7 @@ export abstract class ImportSource {
|
|||
const transformer = "return data"
|
||||
const schema = {}
|
||||
path = this.processPath(path)
|
||||
path = `${url.origin}/${path}`
|
||||
queryString = this.processQuery(queryString)
|
||||
const requestBody = JSON.stringify(body, null, 2)
|
||||
|
||||
|
|
|
@ -60,16 +60,19 @@ export class Curl extends ImportSource {
|
|||
return true
|
||||
}
|
||||
|
||||
getUrl = (): URL => {
|
||||
return new URL(this.curl.raw_url)
|
||||
}
|
||||
|
||||
getInfo = async (): Promise<ImportInfo> => {
|
||||
const url = new URL(this.curl.url)
|
||||
const url = this.getUrl()
|
||||
return {
|
||||
url: url.origin,
|
||||
name: url.hostname,
|
||||
}
|
||||
}
|
||||
|
||||
getQueries = async (datasourceId: string): Promise<Query[]> => {
|
||||
const url = new URL(this.curl.raw_url)
|
||||
const url = this.getUrl()
|
||||
const name = url.pathname
|
||||
const path = url.pathname
|
||||
const method = this.curl.method
|
||||
|
@ -87,6 +90,7 @@ export class Curl extends ImportSource {
|
|||
name,
|
||||
method,
|
||||
path,
|
||||
url,
|
||||
queryString,
|
||||
headers,
|
||||
[],
|
||||
|
|
|
@ -2,6 +2,7 @@ import { ImportInfo } from "./base"
|
|||
import { Query, QueryParameter } from "../../../../../definitions/datasource"
|
||||
import { OpenAPIV2 } from "openapi-types"
|
||||
import { OpenAPISource } from "./base/openapi"
|
||||
import { URL } from "url"
|
||||
|
||||
const parameterNotRef = (
|
||||
param: OpenAPIV2.Parameter | OpenAPIV2.ReferenceObject
|
||||
|
@ -55,20 +56,22 @@ export class OpenAPI2 extends OpenAPISource {
|
|||
}
|
||||
}
|
||||
|
||||
getInfo = async (): Promise<ImportInfo> => {
|
||||
getUrl = (): URL => {
|
||||
const scheme = this.document.schemes?.includes("https") ? "https" : "http"
|
||||
const basePath = this.document.basePath || ""
|
||||
const host = this.document.host || "<host>"
|
||||
const url = `${scheme}://${host}${basePath}`
|
||||
const name = this.document.info.title || "Swagger Import"
|
||||
return new URL(`${scheme}://${host}${basePath}`)
|
||||
}
|
||||
|
||||
getInfo = async (): Promise<ImportInfo> => {
|
||||
const name = this.document.info.title || "Swagger Import"
|
||||
return {
|
||||
url: url,
|
||||
name: name,
|
||||
name
|
||||
}
|
||||
}
|
||||
|
||||
getQueries = async (datasourceId: string): Promise<Query[]> => {
|
||||
const url = this.getUrl()
|
||||
const queries = []
|
||||
|
||||
for (let [path, pathItem] of Object.entries(this.document.paths)) {
|
||||
|
@ -145,6 +148,7 @@ export class OpenAPI2 extends OpenAPISource {
|
|||
name,
|
||||
methodName,
|
||||
path,
|
||||
url,
|
||||
queryString,
|
||||
headers,
|
||||
parameters,
|
||||
|
|
Loading…
Reference in New Issue