import type { OpenApi } from "../../types" ; import * as Types from "./types" ; import { Def } from "./Walker" ; export const isReference = ( data ) : data is OpenApi . Reference => { if ( typeof data !== "object" || data === null ) { return false ; } return typeof data . $ref === "string" ; } ; export const isUnSupportSchema = ( schema ) : schema is Types . UnSupportSchema => { return Array . isArray ( schema . type ) ; } ; export const isObjectSchema = ( schema ) : schema is Types . ObjectSchema => { return schema . type === "object" ; } ; export const isHasNoMembersObject = ( schema ) : boolean => { return Object . keys ( schema ) . length === 0 ; } ; export const isArraySchema = ( schema ) : schema is Types . ArraySchema => { return schema . type === "array" ; } ; export const isPrimitiveSchema = ( schema ) : schema is Types . PrimitiveSchema => { if ( typeof schema . type !== "string" ) { return false ; } if ( schema . type === "object" ) { return false ; } if ( schema . type === "array" ) { return false ; } return true ; } ; export const isNumberArray = ( list ) : list is number [ ] => { return ! list . some ( item => typeof item !== "number" ) ; } ; export const isStringArray = ( list ) : list is string [ ] => { return ! list . some ( item => typeof item !== "string" ) ; } ; export const isObjectSchemaWithAdditionalProperties = ( schema ) : schema is Types . ObjectSchemaWithAdditionalProperties => { return ! ! schema . additionalProperties ; } ; export const isOneOfSchema = ( schema ) : schema is Types . OneOfSchema => { return ! ! schema . oneOf && typeof schema . oneOf !== "boolean" && Array . isArray ( schema . oneOf ) ; } ; export const isAllOfSchema = ( schema ) : schema is Types . AllOfSchema => { return ! ! schema . allOf && typeof schema . allOf !== "boolean" && Array . isArray ( schema . allOf ) ; } ; export const isAnyOfSchema = ( schema ) : schema is Types . AnyOfSchema => { return ! ! schema . anyOf && typeof schema . anyOf !== "boolean" && Array . isArray ( schema . anyOf ) ; } ; export const isComponentName = ( name ) : name is Def . ComponentName => { return [ "schemas" , "headers" , "responses" , "parameters" , "requestBodies" , "securitySchemes" , "pathItems" ] . includes ( name ) ; } ;