Tribe__Tickets__REST__V1__Endpoints__Base::swaggerize_args( array $args = array(), array $defaults = array() )
Converts an array of arguments suitable for the WP REST API to the Swagger format.
Contents
Parameters
- $args
-
(array) (Optional)
Default value: array()
- $defaults
-
(array) (Optional)
Default value: array()
Return
(array) The converted arguments.
Source
File: src/Tribe/REST/V1/Endpoints/Base.php
public function swaggerize_args( array $args = array(), array $defaults = array() ) {
if ( empty( $args ) ) {
return $args;
}
$no_description = __( 'No description provided', 'event-tickets' );
$defaults = array_merge( array(
'in' => 'body',
'schema' => array(
'type' => 'string',
'default' => '',
),
'description' => $no_description,
'required' => false,
'items' => array(
'type' => 'integer',
),
), $defaults );
$swaggerized = array();
foreach ( $args as $name => $info ) {
if ( isset( $info['swagger_type'] ) ) {
$type = $info['swagger_type'];
} else {
$type = isset( $info['type'] ) ? $info['type'] : false;
}
$type = is_array( $type ) ? $type : $this->convert_type( $type );
$schema = null;
if ( is_array( $type ) ) {
$schema = $type;
unset( $info['swagger_type'] );
} else {
$schema = array(
'type' => $type,
'default' => isset( $info['default'] ) ? $info['default'] : false,
);
}
$read = array(
'name' => $name,
'description' => isset( $info['description'] ) ? $info['description'] : false,
'in' => isset( $info['in'] ) ? $info['in'] : false,
'collectionFormat' => isset( $info['collectionFormat'] ) ? $info['collectionFormat'] : false,
'schema' => $schema,
'items' => isset( $info['items'] ) ? $info['items'] : false,
'required' => isset( $info['required'] ) ? $info['required'] : false,
);
if ( isset( $info['swagger_type'] ) ) {
$read['schema']['type'] = $info['swagger_type'];
}
if ( isset( $read['schema']['type'] ) && $read['schema']['type'] !== 'array' ) {
unset( $defaults['items'] );
}
$merged = array_merge( $defaults, array_filter( $read ) );
unset( $merged['type'], $merged['default'] );
$swaggerized[] = $merged;
}
return $swaggerized;
}
Changelog
| Version | Description |
|---|---|
| 4.7.5 | Introduced. |