Ejemplo n.º 1
0
 /**
  * An resource can contain schema definitions which are only resolved if we
  * actual call the getDefinition method i.e. the schema is stored in an
  * database. So before we cache the documentation we must get the actual
  * definition object which we can serialize
  *
  * @param \PSX\Api\DocumentationInterface $documentation
  */
 protected function materializeDocumentation(DocumentationInterface $documentation)
 {
     $versions = $documentation->getResources();
     foreach ($versions as $version => $resource) {
         foreach ($resource as $method) {
             $request = $method->getRequest();
             if ($request) {
                 $method->setRequest(new Schema($request->getDefinition()));
             }
             $responses = $method->getResponses();
             foreach ($responses as $statusCode => $response) {
                 $method->addResponse($statusCode, new Schema($response->getDefinition()));
             }
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Returns the version which was provided by the user agent. If no version
  * was specified the latest version is used
  *
  * @param \PSX\Api\DocumentationInterface $doc
  * @return \PSX\Api\Version
  */
 protected function getVersion(DocumentationInterface $doc)
 {
     if ($doc->isVersionRequired()) {
         $version = $this->getSubmittedVersionNumber();
         if ($version !== null) {
             return new Version((int) $version);
         } else {
             // it is strongly recommended that clients specify an explicit
             // version but forcing that with an exception is not a good user
             // experience therefore we use the latest version if nothing is
             // specified
             return new Version($doc->getLatestVersion());
             //throw new StatusCode\UnsupportedMediaTypeException('Requires an Accept header containing an explicit version');
         }
     } else {
         return new Version(1);
     }
 }