-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
feat: console error messages and better names for requests imported from openapi #3948
Open
sawa-ko
wants to merge
1
commit into
hoppscotch:main
Choose a base branch
from
sawa-ko:feat/show-error-message-in-console-openapi-import
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,32 @@ | ||
import { | ||
OpenAPI, | ||
OpenAPIV2, | ||
OpenAPIV3, | ||
OpenAPIV3_1 as OpenAPIV31, | ||
} from "openapi-types" | ||
import SwaggerParser from "@apidevtools/swagger-parser" | ||
import yaml from "js-yaml" | ||
import { | ||
FormDataKeyValue, | ||
HoppCollection, | ||
HoppRESTAuth, | ||
HoppRESTHeader, | ||
HoppRESTParam, | ||
HoppRESTReqBody, | ||
HoppRESTRequest, | ||
HoppRESTRequestVariable, | ||
knownContentTypes, | ||
makeRESTRequest, | ||
HoppCollection, | ||
makeCollection, | ||
HoppRESTRequestVariable, | ||
HoppRESTRequest, | ||
makeRESTRequest, | ||
} from "@hoppscotch/data" | ||
import { pipe, flow } from "fp-ts/function" | ||
import * as A from "fp-ts/Array" | ||
import * as S from "fp-ts/string" | ||
import * as O from "fp-ts/Option" | ||
import * as TE from "fp-ts/TaskEither" | ||
import * as RA from "fp-ts/ReadonlyArray" | ||
import { IMPORTER_INVALID_FILE_FORMAT } from "." | ||
import * as TE from "fp-ts/TaskEither" | ||
import { flow, pipe } from "fp-ts/function" | ||
import * as S from "fp-ts/string" | ||
import yaml from "js-yaml" | ||
import { cloneDeep } from "lodash-es" | ||
import { | ||
OpenAPI, | ||
OpenAPIV2, | ||
OpenAPIV3, | ||
OpenAPIV3_1 as OpenAPIV31, | ||
} from "openapi-types" | ||
import { IMPORTER_INVALID_FILE_FORMAT } from "." | ||
|
||
export const OPENAPI_DEREF_ERROR = "openapi/deref_error" as const | ||
|
||
|
@@ -627,14 +627,27 @@ const convertPathToHoppReqs = ( | |
? openAPIUrl + openAPIPath.slice(1) | ||
: openAPIUrl + openAPIPath | ||
|
||
let defaultRequestName = "Untitled Request" | ||
|
||
if (info.tags?.length) { | ||
const pathStartIndex = | ||
openAPIPath.indexOf(info.tags[0]) + info.tags[0].length | ||
|
||
if (pathStartIndex > 0) { | ||
defaultRequestName = | ||
openAPIPath.slice(pathStartIndex).split("/")?.[1] ?? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when naming the request, here it seems we're considering the first value after the tag only, eg: the current logic will name |
||
defaultRequestName | ||
} | ||
} | ||
|
||
const res: { | ||
request: HoppRESTRequest | ||
metadata: { | ||
tags: string[] | ||
} | ||
} = { | ||
request: makeRESTRequest({ | ||
name: info.operationId ?? info.summary ?? "Untitled Request", | ||
name: info.operationId ?? info.summary ?? defaultRequestName, | ||
method: method.toUpperCase(), | ||
endpoint, | ||
|
||
|
@@ -753,7 +766,14 @@ export const hoppOpenAPIImporter = (fileContents: string[]) => | |
|
||
return resultDoc | ||
}, | ||
() => IMPORTER_INVALID_FILE_FORMAT | ||
(e) => { | ||
console.error( | ||
(e as { message?: string })?.message ?? | ||
"An unexpected error occurred while parsing the OpenApi file." | ||
) | ||
|
||
return IMPORTER_INVALID_FILE_FORMAT | ||
} | ||
) | ||
) | ||
}), | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here this logic will miss some edge cases,
i belive you're assuming that the tag will always be present in the path, but that won't always be the case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. If it does not have a tag then the condition is not met and is saved as a request without a title. What I can do is save it with the name of the controller in the request in case it don't have tags.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I quoted the wrong lines actually. the comment is meant for the next line.
and i didn't mean when the tag is not present, i meant when a tag is present but it is not in the url.
like this,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been thinking about it, and I can't find a way to know from which text index to parse the url as name, any idea? My initial motivation for using the tags was because normally people generate the openapi specs automatically based on the code in their apis, but with the point that the first tag may not be the controller itself, I can't think of another idea.