feat: add support to openapi importer for yaml
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
||||
OpenAPIV3_1 as OpenAPIV31,
|
||||
} from "openapi-types"
|
||||
import SwaggerParser from "@apidevtools/swagger-parser"
|
||||
import yaml from "js-yaml"
|
||||
import {
|
||||
FormDataKeyValue,
|
||||
HoppRESTAuth,
|
||||
@@ -28,11 +29,11 @@ import { Collection, makeCollection } from "~/newstore/collections"
|
||||
const OPENAPI_DEREF_ERROR = "openapi/deref_error" as const
|
||||
|
||||
// TODO: URL Import Support
|
||||
// TODO: YAMLLLLLLL import support!!!!!
|
||||
// TODO: Oauth!
|
||||
|
||||
const safeParseJSON = (str: string) => O.tryCatch(() => JSON.parse(str))
|
||||
|
||||
const safeParseYAML = (str: string) => O.tryCatch(() => yaml.load(str))
|
||||
|
||||
const objectHasProperty = <T extends string>(
|
||||
obj: unknown,
|
||||
propName: T
|
||||
@@ -573,13 +574,23 @@ const convertOpenApiDocToHopp = (
|
||||
])
|
||||
}
|
||||
|
||||
const parseOpenAPIDocContent = (str: string) =>
|
||||
pipe(
|
||||
str,
|
||||
safeParseJSON,
|
||||
O.match(
|
||||
() => safeParseYAML(str),
|
||||
(data) => O.of(data)
|
||||
)
|
||||
)
|
||||
|
||||
export default defineImporter({
|
||||
name: "Swagger/OpenAPI v3 Schema",
|
||||
steps: [
|
||||
step({
|
||||
stepName: "FILE_OR_URL_IMPORT",
|
||||
metadata: {
|
||||
acceptedFileTypes: "application/json",
|
||||
acceptedFileTypes: ".json, .yaml, .yml",
|
||||
},
|
||||
}),
|
||||
] as const,
|
||||
@@ -587,7 +598,7 @@ export default defineImporter({
|
||||
pipe(
|
||||
// See if we can parse JSON properly
|
||||
fileContent,
|
||||
safeParseJSON,
|
||||
parseOpenAPIDocContent,
|
||||
TE.fromOption(() => IMPORTER_INVALID_FILE_FORMAT),
|
||||
|
||||
// Try validating, else the importer is invalid file format
|
||||
|
||||
@@ -84,6 +84,7 @@
|
||||
"graphql-tag": "^2.12.6",
|
||||
"httpsnippet": "^2.0.0",
|
||||
"io-ts": "^2.2.16",
|
||||
"js-yaml": "^4.1.0",
|
||||
"json-loader": "^0.5.7",
|
||||
"lodash": "^4.17.21",
|
||||
"mustache": "^4.2.0",
|
||||
|
||||
2
pnpm-lock.yaml
generated
2
pnpm-lock.yaml
generated
@@ -138,6 +138,7 @@ importers:
|
||||
io-ts: ^2.2.16
|
||||
jest: ^27.4.5
|
||||
jest-serializer-vue: ^2.0.2
|
||||
js-yaml: ^4.1.0
|
||||
json-loader: ^0.5.7
|
||||
lodash: ^4.17.21
|
||||
mustache: ^4.2.0
|
||||
@@ -230,6 +231,7 @@ importers:
|
||||
graphql-tag: 2.12.6_graphql@15.7.2
|
||||
httpsnippet: 2.0.0
|
||||
io-ts: 2.2.16_fp-ts@2.11.5
|
||||
js-yaml: 4.1.0
|
||||
json-loader: 0.5.7
|
||||
lodash: 4.17.21
|
||||
mustache: 4.2.0
|
||||
|
||||
Reference in New Issue
Block a user