diff --git a/.gitignore b/.gitignore index a725465..31a0e5d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -vendor/ \ No newline at end of file +vendor/ +build/ \ No newline at end of file diff --git a/README.md b/README.md index 5d90626..7a4aa24 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,8 @@ Supports generating an OpenAPI spec in `JSON` or `yaml`. `composer require --dev dsuurlant/response2schema` +Or download the phar from the [Releases page](https://github.com/dsuurlant/response2schema/releases). + # Usage Just point Response2Schema to your input json file, and tell it where to put the output OpenAPI spec. @@ -22,6 +24,10 @@ It will automatically format it to json or yaml based on the extension of the ou `./vendor/bin/response2schema response.json openapi.yaml` +Or when using the phar: + +`./response2schema.phar response.json openapi.yaml` + # Example Given a very simple response: diff --git a/bin/response2schema b/bin/response2schema index 829fbd2..86e7e40 100755 --- a/bin/response2schema +++ b/bin/response2schema @@ -9,7 +9,7 @@ foreach ([__DIR__ . '/../../../autoload.php', __DIR__ . '/../vendor/autoload.php } } -function showHelp() { +function showHelp(int $exit) { fwrite(STDOUT, << $arg) { if ($k === 0) { continue; @@ -41,11 +54,10 @@ foreach($argv as $k => $arg) { // Input if ($k === 1) { if (!is_string($arg)) { - echo "Input file path invalid."; - exit(1); + error("Please specify an input file."); } if ($arg === 'help' || $arg === '--help') { - showHelp(); + showHelp(0); } $inputPath = $arg; } @@ -53,18 +65,21 @@ foreach($argv as $k => $arg) { // Output if ($k === 2) { if (!is_string($arg)) { - echo 'Output file path invalid.'; - exit(1); + error("Please specify an output file."); } $outputPath = $arg; } } +if ($inputPath === null || $outputPath === null) { + error("Missing input and output file arguments!"); +} + try { \DSuurlant\Response2Schema\Response2Schema::generate($inputPath, $outputPath); - fwrite(STDOUT, "Generation successful." . PHP_EOL); + success("Generation successful!"); } catch (DomainException $exception) { - fwrite(STDERR, $exception->getMessage() . PHP_EOL); + error($exception->getMessage()); } exit(0); diff --git a/composer.json b/composer.json index 17fc3d1..f1850b7 100644 --- a/composer.json +++ b/composer.json @@ -34,6 +34,6 @@ "macfja/phar-builder": "^0.2.8" }, "scripts": { - "buildphar": "vendor/bin/phar-builder package -e bin/response2schema -z --name response2schema.phar -o build" + "buildphar": "vendor/bin/phar-builder package -e bin/response2schema -z --name response2schema.phar -o build && chmod 755 build/response2schema.phar" } }