Gargoyle
Gargoyle

Reputation: 10324

Hide Restler method from swagger-ui

Using Restler 3.0.0-RC6, which internally packages swagger-ui, I have an API method defined like so:

<?php

namespace v1:

class PostgreSQL {
    public function fetchArray($sql, $args = null) {

And then all of my classes that I include via Restler's addAPIClass extend that PostgreSQL class. That means when swagger runs, every single API shows a fetchArray function. I'd like to have that method not appear in the swagger documentation as it's not really part of the API. Other 'things' on the website also use the class though so I can't change the modifier from public.

What's the proper syntax to hide that method from swagger-ui's webpage?

Upvotes: 1

Views: 993

Answers (2)

Sir Rufo
Sir Rufo

Reputation: 19096

You should not extend your API layer class from a data layer class. Just use the data layer class.

class DataLayer
{
  public function fetchArray()
  {
    return array();
  }
}

class ApiLayer
{
  private $dl;

  function __construct()
  {
    $this->dl = new DataLayer();
  }

  public function getAll()
  {
    return $this->dl->fetchArray();
  }
}

Upvotes: 0

Arul Kumaran
Arul Kumaran

Reputation: 993

There are two ways to achieve this,

One is to mark the fetchArray method as private with @access private comment. This will remove fetchArray from all api urls while keeping the fetchArray still accessible for PHP

Problem in your case is that you don't want to modify the PostgreSQL as its part of a framework that is maintained by composer. Instead of directly extending it from the base class use an intermediary class which adds the comment and then extend that class as shown below

class Base {
    public function fetchArray(){
        return array();
    }
}

class Intermediary extends Base {
    /**
     * @access private
     */
    public function fetchArray(){
        return array();
    }
}

class MyApi extends Intermediary { //instead of extends Base
    //other api methods here
    //see in the explorer to note that fetchArray is no longer listed
}

Another way is to just exclude it on Explorer with

use Luracast\Restler\Explorer;
Explorer::$excludedPaths = array('myapi/fetcharray','another/fetcharray');

Upvotes: 1

Related Questions