WPCOM_JSON_API_Endpoint::generate_documentation PHP Method

generate_documentation() public method

Echoes HTML.
    function generate_documentation()
    {
        $format = str_replace('%d', '%s', $this->path);
        $path_labeled = $format;
        if (!empty($this->path_labels)) {
            $path_labeled = vsprintf($format, array_keys($this->path_labels));
        }
        $boolean_arg = array('false', 'true');
        $naeloob_arg = array('true', 'false');
        $doc = array('description' => $this->description, 'method' => $this->method, 'path_format' => $this->path, 'path_labeled' => $path_labeled, 'group' => $this->group, 'request' => array('path' => array(), 'query' => array(), 'body' => array()), 'response' => array('body' => array()));
        foreach (array('path_labels' => 'path', 'query' => 'query', 'request_format' => 'body', 'response_format' => 'body') as $_property => $doc_item) {
            foreach ((array) $this->{$_property} as $key => $description) {
                if (is_array($description)) {
                    $description_keys = array_keys($description);
                    if ($boolean_arg === $description_keys || $naeloob_arg === $description_keys) {
                        $type = '(bool)';
                    } else {
                        $type = '(string)';
                    }
                    if ('response_format' !== $_property) {
                        // hack - don't show "(default)" in response format
                        reset($description);
                        $description_key = key($description);
                        $description[$description_key] = "(default) {$description[$description_key]}";
                    }
                } else {
                    $types = $this->parse_types($description);
                    $type = array();
                    $default = '';
                    if ('none' == $types) {
                        $types = array();
                        $types[]['type'] = 'none';
                    }
                    foreach ($types as $type_array) {
                        $type[] = $type_array['type'];
                        if (isset($type_array['default'])) {
                            $default = $type_array['default'];
                            if ('string' === $type_array['type']) {
                                $default = "'{$default}'";
                            }
                        }
                    }
                    $type = '(' . join('|', $type) . ')';
                    $noop = '';
                    // skip an index in list below
                    list($noop, $description) = explode(')', $description, 2);
                    $description = trim($description);
                    if ($default) {
                        $description .= " Default: {$default}.";
                    }
                }
                $item = compact('type', 'description');
                if ('response_format' === $_property) {
                    $doc['response'][$doc_item][$key] = $item;
                } else {
                    $doc['request'][$doc_item][$key] = $item;
                }
            }
        }
        return $doc;
    }