• Resolved Gerald

    (@gerital)


    I have troubles finding the a way to add certain elements as described in the OpenAPi specification to the swagger API documentation.

    For example, I would like to define a summary and a description to the API methods, but can’t find out how.

    Also I need to add geojson as an additional response content type. I tried to add it directly to the args parameter of register_rest_route, but without success:

    `register_rest_route( ‘xrcb/v1’, ‘/radios/(?P<id>\d+)’, array(
    ‘methods’ => ‘GET’,
    ‘summary’ => ‘Find radio by ID.’,
    ‘description’ => ‘Returns a single radio.’,
    ‘produces’ => ‘application/vnd.geo+json’,
    ‘callback’ => ‘xrcbapi_radios_api_endpoint’,
    ‘args’ => array(
    ‘id’ => array(
    ‘description’ => esc_html__( ‘ID of radio to return’, ‘xrcb’ ),
    ‘type’ => ‘integer’,
    ‘prop_format’ => ‘int64’,
    ‘validate_callback’ => function($param, $request, $key) {
    return is_numeric( $param );
    }
    ),
    ),
    ));`

    A complete example of register_rest_route would be great.

Viewing 1 replies (of 1 total)
  • Plugin Author agussuroyo

    (@agussuroyo)

    Hi @gerital

    Thanks for the info about this, could you please update the plugin to the latest version, it should be can put your summary, description, and produces parameters into Swagger UI display (produces parameter should be in Array format)

    those custom parameter is not mandatory, since it’s not correct format for parameter that supported by WordPress API, it’s for Swagger UI display only

    Sorry I can’t give you full example since it’s not correct format to build rest api in WordPress and just for Swagger UI display purpose only,

    but this is few line sample about how to use summary, description and produces parameter in Array:

    
    'summary' => 'Summary of current endpoint',
    'description' => 'Description of current endpoint',
    'produces' => ['application/vnd.geo+json']
    

    basically your code is almost correct, just change produces parameter into Array format

    Thanks

Viewing 1 replies (of 1 total)
  • The topic ‘Complete example for register_rest_route’ is closed to new replies.