fix(common): OpenAPI response example status code bug (#4966)

Co-authored-by: jamesgeorge007 <25279263+jamesgeorge007@users.noreply.github.com>
This commit is contained in:
Nivedin 2025-04-08 14:46:29 +05:30 committed by GitHub
parent a263113147
commit 3cf286a443
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 3 deletions

View file

@ -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[] = [

View 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
)
}