Example #1
0
 /**
  * Create fake json based on a swagger schema
  *
  * @param string $swaggerFile
  * @param string $path
  * @param string $operation
  * @param int $response
  * @param array $config
  * @return string
  * @throws InvalidArgumentException
  */
 public function swaggerSchema($swaggerFile, $path, $operation, $response, array $config = [])
 {
     $config = new GenerationConfig($config);
     $provider = new SchemaProvider($swaggerFile);
     $generator = new SchemaGenerator($provider, $this->generator, $config);
     $schema = $provider->getSchema($path, $operation, $response);
     if ([] === get_object_vars($schema)) {
         return null;
     }
     return $generator->generate($schema);
 }
Example #2
0
 /**
  * Get a faker formatter
  *
  * @param $schema
  * @param null $property
  * @return Callable
  * @throws InvalidArgumentException
  */
 private function getFormatter($schema, $property = null)
 {
     if ($this->provider->hasProperty($schema, 'format')) {
         $format = $this->provider->getProperty($schema, 'format');
         if (array_key_exists($format, self::$map)) {
             $format = self::$map[$format];
         }
         return $this->generator->getFormatter($format);
     }
     if (null !== $property) {
         return $this->generator->getFormatter($property);
     }
     throw new InvalidArgumentException('Formatter could not be found');
 }