protected function execute(InputInterface $input, OutputInterface $output) { $version = $input->getArgument('version') ?: '*'; $path = $input->getArgument('path'); $doc = $this->resourceListing->getDocumentation($path); if ($doc instanceof DocumentationInterface) { if ($version == '*') { $version = $doc->getLatestVersion(); } $resource = $doc->getResource($version); if (!$resource instanceof Resource) { throw new RuntimeException('Given version is not available'); } $targetNamespace = $this->config['psx_json_namespace']; $generator = new Generator\JsonSchema($targetNamespace); $output->write($generator->generate($resource)); } else { throw new RuntimeException('Invalid resource'); } }
protected function getModels(Resource $resource) { $generator = new JsonSchema($this->targetNamespace); $data = json_decode($generator->generate($resource)); $models = new \stdClass(); $properties = $data->properties; foreach ($properties as $name => $property) { $description = isset($property->description) ? $property->description : null; $required = isset($property->required) ? $property->required : null; $properties = isset($property->properties) ? $property->properties : null; $model = new Model($name, $description, $required); $model->setProperties($properties); $models->{$name} = $model; } $definitions = $data->definitions; foreach ($definitions as $name => $definition) { $description = isset($definition->description) ? $definition->description : null; $required = isset($definition->required) ? $definition->required : null; $properties = isset($definition->properties) ? $definition->properties : null; $model = new Model($name, $description, $required); $model->setProperties($properties); $models->{$name} = $model; } return $models; }