fix(common): use operation title as fallback in OpenAPI import (#5950)
Co-authored-by: James George <25279263+jamesgeorge007@users.noreply.github.com>
This commit is contained in:
parent
37b06fb07e
commit
744f434698
1 changed files with 27 additions and 2 deletions
|
|
@ -120,6 +120,31 @@ type OpenAPIOperationType =
|
|||
| OpenAPIV3.OperationObject
|
||||
| OpenAPIV31.OperationObject
|
||||
|
||||
// Resolve request name: operationId > summary > title > "Untitled Request"
|
||||
const getOpenAPIOperationName = (info: OpenAPIOperationType): string => {
|
||||
const title =
|
||||
objectHasProperty(info, "title") && typeof info.title === "string"
|
||||
? info.title
|
||||
: undefined
|
||||
|
||||
const candidates: Array<string | undefined> = [
|
||||
info.operationId,
|
||||
info.summary,
|
||||
title,
|
||||
]
|
||||
|
||||
for (const candidate of candidates) {
|
||||
if (typeof candidate === "string") {
|
||||
const trimmed = candidate.trim()
|
||||
if (trimmed !== "") {
|
||||
return trimmed
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "Untitled Request"
|
||||
}
|
||||
|
||||
// Removes the OpenAPI Path Templating to the Hoppscotch Templating (<< ? >>)
|
||||
const replaceOpenApiPathTemplating = flow(
|
||||
S.replace(/{/g, "<<"),
|
||||
|
|
@ -1039,7 +1064,7 @@ const convertPathToHoppReqs = (
|
|||
}
|
||||
} = {
|
||||
request: makeRESTRequest({
|
||||
name: info.operationId ?? info.summary ?? "Untitled Request",
|
||||
name: getOpenAPIOperationName(info),
|
||||
description: info.description ?? null,
|
||||
method: method.toUpperCase(),
|
||||
endpoint,
|
||||
|
|
@ -1067,7 +1092,7 @@ const convertPathToHoppReqs = (
|
|||
doc,
|
||||
info,
|
||||
makeHoppRESTResponseOriginalRequest({
|
||||
name: info.operationId ?? info.summary ?? "Untitled Request",
|
||||
name: getOpenAPIOperationName(info),
|
||||
auth: parseOpenAPIAuth(doc, info),
|
||||
body: parseOpenAPIBody(doc, info),
|
||||
endpoint,
|
||||
|
|
|
|||
Loading…
Reference in a new issue