forked from janephp/open-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit merging all library into one repository
- Loading branch information
0 parents
commit e6b2043
Showing
288 changed files
with
25,266 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.idea | ||
vendor/ | ||
composer.lock | ||
tests/fixtures/*/generated | ||
.php_cs.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
return [ | ||
'json-schema-file' => 'swagger-spec.json', | ||
'root-class' => 'OpenApi', | ||
'namespace' => 'Joli\Jane\OpenApi', | ||
'directory' => __DIR__ . '/generated', | ||
'reference' => true, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
use SLLH\StyleCIBridge\ConfigBridge; | ||
|
||
return ConfigBridge::create(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
filter: | ||
paths: [src/*] | ||
|
||
checks: | ||
php: | ||
code_rating: true | ||
duplication: true | ||
|
||
tools: | ||
external_code_coverage: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
preset: symfony | ||
|
||
enabled: | ||
- short_array_syntax | ||
|
||
|
||
finder: | ||
exclude: | ||
- "tests/fixtures" | ||
- "tests/fixtures-boilerplate" | ||
- "generated" | ||
- "bin" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
language: php | ||
cache: | ||
directories: | ||
- ~/.composer/cache/files | ||
|
||
php: | ||
- 7.0 | ||
- 7.1 | ||
- 7.2 | ||
|
||
env: | ||
global: | ||
- TEST_COMMAND="composer test" | ||
|
||
matrix: | ||
fast_finish: true | ||
include: | ||
- php: 7.0 | ||
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" COVERAGE=true TEST_COMMAND="composer test-ci" | ||
|
||
before_install: | ||
- travis_retry composer self-update | ||
|
||
install: | ||
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction | ||
|
||
script: | ||
- travis_wait $TEST_COMMAND | ||
|
||
after_success: | ||
- if [[ "$COVERAGE" = true ]]; then wget https://scrutinizer-ci.com/ocular.phar; fi | ||
- if [[ "$COVERAGE" = true ]]; then php ocular.phar code-coverage:upload --format=php-clover build/coverage.xml; fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Joli\Jane\OpenApi; | ||
|
||
use Joli\Jane\OpenApi\Command\GenerateCommand; | ||
use Symfony\Component\Console\Application as BaseApplication; | ||
|
||
class Application extends BaseApplication | ||
{ | ||
/** | ||
* Constructor. | ||
*/ | ||
public function __construct() | ||
{ | ||
parent::__construct('Jane OpenApi', JaneOpenApi::VERSION); | ||
|
||
$this->add(new GenerateCommand()); | ||
} | ||
|
||
public function getLongVersion() | ||
{ | ||
$version = parent::getLongVersion(); | ||
$commit = '@git-commit@'; | ||
|
||
if ('@'.'git-commit@' !== $commit) { | ||
$version .= ' ('.substr($commit, 0, 7).')'; | ||
} | ||
|
||
return $version; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Contributing | ||
|
||
First, thank you! | ||
|
||
Here are a few rules to follow in order to ease code reviews, and discussions before maintainers accept and merge your work. | ||
|
||
* You **MUST** follow the [PSR-1](http://www.php-fig.org/psr/1/) and [PSR-2](http://www.php-fig.org/psr/2/). | ||
* You **MUST** run the test suite. | ||
* You **MUST** write (or update) unit tests. | ||
* You **SHOULD** write documentation. | ||
|
||
Please, write [commit messages that make sense](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html), | ||
and [rebase your branch](http://git-scm.com/book/en/Git-Branching-Rebasing) before submitting your Pull Request. | ||
|
||
One may ask you to [squash your commits](http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html) too. | ||
This is used to "clean" your Pull Request before merging it (we don't want commits such as `fix tests`, `fix 2`, `fix 3`, etc.). | ||
|
||
Also, when creating your Pull Request on GitHub, you **MUST** write a description which gives the context and/or explains why you are creating it. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace Joli\Jane\OpenApi\Client; | ||
|
||
@trigger_error('QueryParam is deprecated since 1.3 and will be removed in 2.0, please use Joli\Jane\OpenApi\Runtime\Client\QueryParam instead.', E_USER_DEPRECATED); | ||
|
||
/** | ||
* @deprecated QueryParam is deprecated since 1.3 and will be removed in 2.0, please use Joli\Jane\OpenApi\Runtime\Client\QueryParam instead. | ||
*/ | ||
class QueryParam extends \Joli\Jane\OpenApi\Runtime\Client\QueryParam | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace Joli\Jane\OpenApi\Client; | ||
|
||
@trigger_error('Resource is deprecated since 1.3 and will be removed in 2.0, please use Joli\Jane\OpenApi\Runtime\Client\Resource instead.', E_USER_DEPRECATED); | ||
|
||
/** | ||
* @deprecated Resource is deprecated since 1.3 and will be removed in 2.0, please use Joli\Jane\OpenApi\Runtime\Client\Resource instead. | ||
*/ | ||
class Resource extends \Joli\Jane\OpenApi\Runtime\Client\Resource | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
<?php | ||
|
||
namespace Joli\Jane\OpenApi\Command; | ||
|
||
use Joli\Jane\OpenApi\JaneOpenApi; | ||
use Joli\Jane\Registry; | ||
use Joli\Jane\Schema; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
|
||
class GenerateCommand extends Command | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function configure() | ||
{ | ||
$this->setName('generate'); | ||
$this->setDescription('Generate an api client: class, normalizers and resources given a specific Json OpenApi file'); | ||
$this->addOption('config-file', 'c', InputOption::VALUE_OPTIONAL, 'File to use for Jane OpenAPI configuration'); | ||
$this->addOption('reference', null, InputOption::VALUE_NONE, 'Use the JSON Reference specification in your generated library'); | ||
$this->addOption('date-format', 'd', InputOption::VALUE_OPTIONAL, 'Date time format to use for date time field'); | ||
$this->addArgument('openapi-file', InputArgument::OPTIONAL, 'Location of the OpenApi (Swagger) Schema file'); | ||
$this->addArgument('namespace', InputArgument::OPTIONAL, 'Namespace prefix to use for generated files'); | ||
$this->addArgument('directory', InputArgument::OPTIONAL, 'Directory where to generate files'); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$options = []; | ||
|
||
$configFile = null; | ||
|
||
if (!$input->hasOption('config-file') && file_exists('.jane-openapi')) { | ||
$configFile = '.jane-openapi'; | ||
} elseif($input->hasOption('config-file') && null !== $input->getOption('config-file')) { | ||
$configFile = $input->getOption('config-file'); | ||
} | ||
|
||
if ($configFile) { | ||
$configFile = $input->getOption('config-file'); | ||
|
||
if (!file_exists($configFile)) { | ||
throw new \RuntimeException(sprintf('Config file %s does not exist', $configFile)); | ||
} | ||
|
||
$options = require $configFile; | ||
|
||
if (!is_array($options)) { | ||
throw new \RuntimeException(sprintf('Invalid config file specified or invalid return type in file %s', $configFile)); | ||
} | ||
} else { | ||
if ($input->hasArgument('openapi-file') && null !== $input->getArgument('openapi-file')) { | ||
$options['openapi-file'] = $input->getArgument('openapi-file'); | ||
} | ||
|
||
if ($input->hasArgument('namespace') && null !== $input->getArgument('namespace')) { | ||
$options['namespace'] = $input->getArgument('namespace'); | ||
} | ||
|
||
if ($input->hasArgument('directory') && null !== $input->getArgument('directory')) { | ||
$options['directory'] = $input->getArgument('directory'); | ||
} | ||
|
||
if ($input->hasOption('date-format') && null !== $input->getOption('date-format')) { | ||
$options['date-format'] = $input->getOption('date-format'); | ||
} | ||
|
||
if ($input->hasOption('no-reference') && null !== $input->getOption('no-reference')) { | ||
$options['reference'] = $input->getOption('reference'); | ||
} | ||
} | ||
|
||
$options = $this->resolveConfiguration($options); | ||
$registry = new Registry(); | ||
|
||
if (array_key_exists('openapi-file', $options)) { | ||
$registry->addSchema($this->resolveSchema($options['openapi-file'], $options)); | ||
} else { | ||
foreach ($options['mapping'] as $schema => $schemaOptions) { | ||
$registry->addSchema($this->resolveSchema($schema, $schemaOptions)); | ||
} | ||
} | ||
|
||
$janeOpenApi = JaneOpenApi::build($options); | ||
$files = $janeOpenApi->generate($registry); | ||
$janeOpenApi->printFiles($files, $registry); | ||
|
||
foreach ($files as $file) { | ||
$output->writeln(sprintf("Generate %s", $file->getFilename())); | ||
} | ||
} | ||
|
||
protected function resolveConfiguration(array $options = []) | ||
{ | ||
$optionsResolver = new OptionsResolver(); | ||
$optionsResolver->setDefaults([ | ||
'reference' => false, | ||
'date-format' => \DateTime::RFC3339, | ||
]); | ||
|
||
if (array_key_exists('openapi-file', $options)) { | ||
$optionsResolver->setRequired([ | ||
'openapi-file', | ||
'namespace', | ||
'directory', | ||
]); | ||
} else { | ||
$optionsResolver->setRequired([ | ||
'mapping' | ||
]); | ||
} | ||
|
||
return $optionsResolver->resolve($options); | ||
} | ||
|
||
protected function resolveSchema($schema, array $options = []) | ||
{ | ||
$optionsResolver = new OptionsResolver(); | ||
|
||
// To support old schema | ||
$optionsResolver->setDefined([ | ||
'openapi-file', | ||
'reference', | ||
'date-format', | ||
]); | ||
|
||
$optionsResolver->setRequired([ | ||
'namespace', | ||
'directory', | ||
]); | ||
|
||
$options = $optionsResolver->resolve($options); | ||
|
||
return new Schema($schema, $options['namespace'], $options['directory'], ''); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace Joli\Jane\OpenApi\Exception; | ||
|
||
use Exception; | ||
use UnexpectedValueException; | ||
|
||
class ParseFailureException extends UnexpectedValueException | ||
{ | ||
/** | ||
* @var Exception | ||
*/ | ||
private $previousYaml; | ||
|
||
/** | ||
* Construct the exception. | ||
* | ||
* @param string $message [optional] The Exception message to throw. | ||
* @param int $code [optional] The Exception code. | ||
* @param Exception $previousJson [optional] The previous exception from the Json serialisation attempt | ||
* @param Exception $previousYaml [optional] The previous exception from the Yaml serialisation attempt | ||
*/ | ||
public function __construct( | ||
$message = "", | ||
$code = 0, | ||
Exception $previousJson = null, | ||
Exception $previousYaml = null | ||
) { | ||
parent::__construct($message, $code, $previousJson); | ||
$this->previousYaml = $previousYaml; | ||
} | ||
|
||
/** | ||
* Get the previous exception from the Yaml serialisation attempt | ||
* | ||
* @return Exception | ||
*/ | ||
final public function getPreviousYaml() | ||
{ | ||
return $this->previousYaml; | ||
} | ||
|
||
/** | ||
* Get the previous exception from the Json serialisation attempt | ||
* | ||
* @return Exception | ||
*/ | ||
final public function getPreviousJson() | ||
{ | ||
return $this->getPrevious(); | ||
} | ||
} |
Oops, something went wrong.