Merge pull request #4943 from Budibase/fix/oapi3-server-path

Fix base path in server url for openapi3 import
This commit is contained in:
Rory Powell 2022-03-18 09:50:34 +00:00 committed by GitHub
commit 4684098b6c
3 changed files with 19 additions and 8 deletions

View File

@ -7,7 +7,6 @@
Layout, Layout,
Tabs, Tabs,
Tab, Tab,
Input,
Heading, Heading,
TextArea, TextArea,
Dropzone, Dropzone,
@ -98,15 +97,16 @@
<Body size="XS" <Body size="XS"
>Import your rest collection using one of the options below</Body >Import your rest collection using one of the options below</Body
> >
<Tabs selected="Link"> <Tabs selected="File">
<Tab title="Link"> <!-- Commenting until nginx csp issue resolved -->
<!-- <Tab title="Link">
<Input <Input
bind:value={$data.url} bind:value={$data.url}
on:change={() => (lastTouched = "url")} on:change={() => (lastTouched = "url")}
label="Enter a URL" label="Enter a URL"
placeholder="e.g. https://petstore.swagger.io/v2/swagger.json" placeholder="e.g. https://petstore.swagger.io/v2/swagger.json"
/> />
</Tab> </Tab> -->
<Tab title="File"> <Tab title="File">
<Dropzone <Dropzone
gallery={false} gallery={false}
@ -115,7 +115,14 @@
$data.file = e.detail?.[0] $data.file = e.detail?.[0]
lastTouched = "file" lastTouched = "file"
}} }}
fileTags={["OpenAPI 2.0", "Swagger 2.0", "cURL", "YAML", "JSON"]} fileTags={[
"OpenAPI 3.0",
"OpenAPI 2.0",
"Swagger 2.0",
"cURL",
"YAML",
"JSON",
]}
maximum={1} maximum={1}
/> />
</Tab> </Tab>

View File

@ -38,7 +38,11 @@ export abstract class ImportSource {
if (typeof url === "string") { if (typeof url === "string") {
path = `${url}/${path}` path = `${url}/${path}`
} else { } else {
path = `${url.origin}/${path}` let href = url.href
if (href.endsWith("/")) {
href = href.slice(0, -1)
}
path = `${href}/${path}`
} }
} }
queryString = this.processQuery(queryString) queryString = this.processQuery(queryString)

View File

@ -74,7 +74,7 @@ export class Curl extends ImportSource {
getQueries = async (datasourceId: string): Promise<Query[]> => { getQueries = async (datasourceId: string): Promise<Query[]> => {
const url = this.getUrl() const url = this.getUrl()
const name = url.pathname const name = url.pathname
const path = url.pathname const path = url.origin + url.pathname
const method = this.curl.method const method = this.curl.method
const queryString = url.search const queryString = url.search
const headers = this.curl.headers const headers = this.curl.headers
@ -90,7 +90,7 @@ export class Curl extends ImportSource {
name, name,
method, method,
path, path,
url, undefined,
queryString, queryString,
headers, headers,
[], [],