Tribe__Events__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.


Parameters

$args

(array) (Optional)

Default value: array()

$defaults

(array) (Optional)

Default value: array()


Top ↑

Return

(array) The converted arguments.


Top ↑

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', 'the-events-calendar' );
		$defaults = array_merge( array(
			'in'          => 'body',
			'type'        => 'string',
			'description' => $no_description,
			'required'    => false,
			'default'     => '',
			'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 = $this->convert_type( $type );

			$read = array(
				'name'             => $name,
				'in'               => isset( $info['in'] ) ? $info['in'] : false,
				'collectionFormat' => isset( $info['collectionFormat'] ) ? $info['collectionFormat'] : false,
				'description'      => isset( $info['description'] ) ? $info['description'] : false,
				'type'             => $type,
				'items'            => isset( $info['items'] ) ? $info['items'] : false,
				'required'         => isset( $info['required'] ) ? $info['required'] : false,
				'default'          => isset( $info['default'] ) ? $info['default'] : false,
			);

			if ( isset( $info['swagger_type'] ) ) {
				$read['type'] = $info['swagger_type'];
			}

			if ( $read['type'] !== 'array' ) {
				unset( $defaults['items'] );
			}

			$swaggerized[] = array_merge( $defaults, array_filter( $read ) );
		}

		return $swaggerized;
	}