import { getResponsesFromPayload , getTypeFromPayload , getDataType , getTypeFromShape , getFilteredProperties , getValue , DEFAULT_DATA_TYPE , OBJECT_DATA_TYPE , } from "./utils" ; import { model } from "amf-client-js" ; param property returns export const getBaseUriFromDocument = ( property ) : string => { return property && property . encodes ? ( property . encodes as model . domain . WebApi ) . servers [ 0 ] . url . value ( ) : "" ; } ; param domainElement returns export const isTypeDefinition = ( domainElement ) : domainElement is model . domain . NodeShape => { return domainElement instanceof model . domain . NodeShape ; } ; param domainElement returns export const isTraitDefinition = ( domainElement ) : domainElement is model . domain . Trait => { return domainElement instanceof model . domain . Trait ; } ; param domainElement returns export const isArrayType = ( domainElement ) : domainElement is model . domain . ArrayShape => { return domainElement instanceof model . domain . ArrayShape ; } ; param operation returns export const getReturnTypeFromOperation = ( operation ) : string => { const okResponses = getResponsesFromPayload ( operation ) ; const dataTypes = [ ] ; okResponses . forEach ( ( res ) => { if ( res . payloads . length > 0 ) { dataTypes . push ( getTypeFromPayload ( res . payloads [ 0 ] ) ) ; } else { dataTypes . push ( "void" ) ; } } ) ; if ( okResponses . length === 0 ) { dataTypes . push ( "void" ) ; } return dataTypes . join ( " | " ) ; } ; param property returns export const getTypeFromProperty = ( property ) : string => { if ( property != null && property . range != null ) { return getDataType ( property . range ) ; } return DEFAULT_DATA_TYPE ; } ; param param returns export const getTypeFromParameter = ( param ) : string => { if ( param != null && param . schema != null ) { return getDataType ( param . schema ) ; } return DEFAULT_DATA_TYPE ; } ; param request returns export const getPayloadTypeFromRequest = ( request ) : string => { if ( request ?. payloads ?. length > 0 ) { const payloadSchema = request . payloads [ 0 ] . schema ; return getTypeFromShape ( payloadSchema ) ; } return OBJECT_DATA_TYPE ; } ; param node returns export const getProperties = ( node ) : model . domain . PropertyShape [ ] => { return getFilteredProperties ( node , ( propertyName ) => { return ! /^([/^]).*.$/ . test ( propertyName ) ; } ) ; } ; param property returns export const isRequiredProperty = ( property ) : boolean => { return property != null && property . minCount . value ( ) > 0 ; } ; param property returns export const isOptionalProperty = ( property ) : boolean => { return property != null && property . minCount . value ( ) == 0 ; } ; param node returns export const isAdditionalPropertiesAllowed = ( node ) : boolean => typeof node ?. closed ?. value === "function" && ! node . closed . value ( ) ; param request returns export const getMediaTypeFromRequest = ( request ) : string => request . payloads [ 0 ] . mediaType . value ( ) ; param request returns export const isRequestWithPayload = ( request ? ) : boolean => request ?. payloads [ 0 ] != null ; export { getValue , getDataType } ;