fix(common): OpenAPI response example status code bug (#4966)
Co-authored-by: jamesgeorge007 <25279263+jamesgeorge007@users.noreply.github.com>
This commit is contained in:
parent
a263113147
commit
3cf286a443
2 changed files with 18 additions and 3 deletions
|
|
@ -29,8 +29,9 @@ import * as TE from "fp-ts/TaskEither"
|
|||
import * as RA from "fp-ts/ReadonlyArray"
|
||||
import * as E from "fp-ts/Either"
|
||||
import { IMPORTER_INVALID_FILE_FORMAT } from "."
|
||||
import { cloneDeep, isNumber } from "lodash-es"
|
||||
import { cloneDeep } from "lodash-es"
|
||||
import { getStatusCodeReasonPhrase } from "~/helpers/utils/statusCodes"
|
||||
import { isNumeric } from "~/helpers/utils/number"
|
||||
|
||||
export const OPENAPI_DEREF_ERROR = "openapi/deref_error" as const
|
||||
|
||||
|
|
@ -172,7 +173,7 @@ const parseOpenAPIV3Responses = (
|
|||
|
||||
const name = response.description ?? key
|
||||
|
||||
const code = isNumber(key) ? Number(key) : 200
|
||||
const code = isNumeric(key) ? Number(key) : 200
|
||||
|
||||
const status = getStatusCodeReasonPhrase(code)
|
||||
|
||||
|
|
@ -230,7 +231,7 @@ const parseOpenAPIV2Responses = (
|
|||
|
||||
const name = response.description ?? key
|
||||
|
||||
const code = isNumber(Number(key)) ? Number(key) : 200
|
||||
const code = isNumeric(Number(key)) ? Number(key) : 200
|
||||
const status = getStatusCodeReasonPhrase(code)
|
||||
|
||||
const headers: HoppRESTHeader[] = [
|
||||
|
|
|
|||
14
packages/hoppscotch-common/src/helpers/utils/number.ts
Normal file
14
packages/hoppscotch-common/src/helpers/utils/number.ts
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
/**
|
||||
* Check if a value is numeric — either a valid number or a numeric string
|
||||
*
|
||||
* @param value - The value to check
|
||||
* @returns True if the value is numeric, false otherwise
|
||||
*/
|
||||
export const isNumeric = (value: unknown): boolean => {
|
||||
if (typeof value === "number") return !Number.isNaN(value) // handle actual numbers
|
||||
if (typeof value !== "string") return false // only process strings or numbers!
|
||||
return (
|
||||
value.trim() !== "" && // ensure strings of whitespace fail
|
||||
!isNaN(Number(value)) // use type coercion to parse the entirety of the string
|
||||
)
|
||||
}
|
||||
Loading…
Reference in a new issue