Skip to content

Commit ec05b62

Browse files
authored
v0.1.0
2 parents 1fe6179 + 523a9ee commit ec05b62

38 files changed

+1437
-67
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ vendor
22
build
33
#A library must not provide a composer.lock file
44
composer.lock
5+
6+
features/demo_app/var/

.scrutinizer.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,14 @@ build:
1515
tests:
1616
stop_on_failure: true
1717
override:
18-
- php-scrutinizer-run --enable-security-analysis
19-
-
20-
command: make codestyle
21-
analysis:
22-
file: 'build/reports/cs-data'
23-
format: 'php-cs-checkstyle'
2418
-
2519
command: make coverage
2620
idle_timeout: 1200
2721
coverage:
2822
file: 'build/coverage/clover.xml'
2923
format: 'php-clover'
24+
- php-scrutinizer-run --enable-security-analysis
25+
- make codestyle
3026
cache:
3127
directories:
3228
- ~/.composer
@@ -39,8 +35,6 @@ build:
3935
COMPOSER_OPTIONS: '--optimize-autoloader'
4036
COVERAGE_OUTPUT_STYLE: 'clover'
4137
COVERAGE_CLOVER_FILE_PATH: 'build/coverage/clover.xml'
42-
PHPCS_REPORT_STYLE: 'checkstyle'
43-
PHPCS_REPORT_FILE: 'build/reports/cs-data'
4438
php:
4539
version: "7.1"
4640
timezone: UTC

.travis.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
language: php
22

33
php:
4-
- '7.0'
54
- '7.1'
65
- '7.2'
6+
- '7.3'
77

88
env:
99
global:
1010
CI: 'true'
1111
TEST_OUTPUT_STYLE: 'pretty'
1212
PHPCS_REPORT_STYLE: 'full'
1313
COMPOSER_OPTIONS: '--optimize-autoloader'
14+
matrix:
15+
- SYMFONY_VERSION: '~3.0'
16+
- SYMFONY_VERSION: '~4.0'
1417

1518
sudo: false
1619

@@ -19,9 +22,10 @@ matrix:
1922

2023
before_install:
2124
# remove xdebug to speed up build
22-
- phpenv config-rm xdebug.ini
25+
- phpenv config-rm xdebug.ini || true
2326

2427
install:
28+
- composer require symfony/http-kernel:$SYMFONY_VERSION symfony/dependency-injection:$SYMFONY_VERSION
2529
- make build
2630
script:
2731
- make test-technical
@@ -31,3 +35,8 @@ cache:
3135
directories:
3236
- $HOME/.composer
3337
- vendor
38+
39+
branches:
40+
except:
41+
- /.*\-dev$/
42+

Makefile

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ COVERAGE_OUTPUT_STYLE ?= html
66
BUILD_DIRECTORY ?= build
77
REPORTS_DIRECTORY ?= ${BUILD_DIRECTORY}/reports
88
COVERAGE_DIRECTORY ?= ${BUILD_DIRECTORY}/coverage
9+
BEHAT_COVERAGE_DIRECTORY ?= ${BUILD_DIRECTORY}/behat-coverage
910
COVERAGE_CLOVER_FILE_PATH ?= ${COVERAGE_DIRECTORY}/clover.xml
1011

1112
## Commands options
1213
### Composer
1314
#COMPOSER_OPTIONS=
1415
### Phpcs
1516
PHPCS_REPORT_STYLE ?= full
17+
PHPCS_DISABLE_WARNING ?= "false"
1618
#PHPCS_REPORT_FILE=
1719
#PHPCS_REPORT_FILE_OPTION=
1820

@@ -51,6 +53,11 @@ ifneq ("${PHPCS_REPORT_FILE}","")
5153
PHPCS_REPORT_FILE_OPTION ?= --report-file=${PHPCS_REPORT_FILE}
5254
endif
5355

56+
ifneq ("${PHPCS_DISABLE_WARNING}","true")
57+
PHPCS_DISABLE_WARNING_OPTION=
58+
else
59+
PHPCS_DISABLE_WARNING_OPTION=-n
60+
endif
5461

5562
## Project build (install and configure)
5663
build: install configure
@@ -76,20 +83,24 @@ test-functional:
7683
./vendor/bin/behat ${BEHAT_COLOR_OPTION} ${BEHAT_OUTPUT_STYLE_OPTION} --no-snippets
7784

7885
codestyle: create-reports-directory
79-
./vendor/bin/phpcs --standard=phpcs.xml.dist ${PHPCS_COLOR_OPTION} ${PHPCS_REPORT_FILE_OPTION} --report=${PHPCS_REPORT_STYLE}
86+
./vendor/bin/phpcs ${PHPCS_DISABLE_WARNING_OPTION} --standard=phpcs.xml.dist ${PHPCS_COLOR_OPTION} ${PHPCS_REPORT_FILE_OPTION} --report=${PHPCS_REPORT_STYLE}
8087

8188
coverage: create-coverage-directory
8289
./vendor/bin/phpunit ${PHPUNIT_COLOR_OPTION} ${PHPUNIT_OUTPUT_STYLE_OPTION} ${PHPUNIT_COVERAGE_OPTION}
8390

84-
91+
behat-coverage: create-behat-coverage-directory
92+
composer required leanphp/behat-code-coverage
93+
./vendor/bin/behat ${BEHAT_COLOR_OPTION} ${BEHAT_OUTPUT_STYLE_OPTION} --no-snippets --profile coverage
8594

8695
# Internal commands
8796
create-coverage-directory:
8897
mkdir -p ${COVERAGE_DIRECTORY}
8998

99+
create-behat-coverage-directory:
100+
mkdir -p ${BEHAT_COVERAGE_DIRECTORY}
101+
90102
create-reports-directory:
91103
mkdir -p ${REPORTS_DIRECTORY}
92104

93-
94-
.PHONY: build install configure test test-technical test-functional codestyle coverage create-coverage-directory create-reports-directory
105+
.PHONY: build install configure test test-technical test-functional codestyle coverage behat-coverage create-coverage-directory create-behat-coverage-directory create-reports-directory
95106
.DEFAULT: build

README.md

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,62 @@
11
# Symfony JSON-RPC Http server OpenAPI documentation
2+
[![License](https://img.shields.io/github/license/yoanm/symfony-jsonrpc-http-server-openapi-doc.svg)](https://github.com/yoanm/symfony-jsonrpc-http-server-openapi-doc) [![Code size](https://img.shields.io/github/languages/code-size/yoanm/symfony-jsonrpc-http-server-openapi-doc.svg)](https://github.com/yoanm/symfony-jsonrpc-http-server-openapi-doc) [![Dependencies](https://img.shields.io/librariesio/github/yoanm/symfony-jsonrpc-http-server-openapi-doc.svg)](https://libraries.io/packagist/yoanm%2Fsymfony-jsonrpc-http-server-openapi-doc)
23

3-
[![License](https://img.shields.io/github/license/yoanm/symfony-jsonrpc-http-server-openapi-doc.svg)](https://github.com/yoanm/symfony-jsonrpc-http-server-openapi-doc) [![Code size](https://img.shields.io/github/languages/code-size/yoanm/symfony-jsonrpc-http-server-openapi-doc.svg)](https://github.com/yoanm/symfony-jsonrpc-http-server-openapi-doc) [![PHP Versions](https://img.shields.io/badge/php-7.0%20%2F%207.1%20%2F%207.2-8892BF.svg)](https://php.net/)
4+
[![Scrutinizer Build Status](https://img.shields.io/scrutinizer/build/g/yoanm/symfony-jsonrpc-http-server-openapi-doc.svg?label=Scrutinizer&logo=scrutinizer)](https://scrutinizer-ci.com/g/yoanm/symfony-jsonrpc-http-server-openapi-doc/build-status/master) [![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/yoanm/symfony-jsonrpc-http-server-openapi-doc/master.svg?logo=scrutinizer)](https://scrutinizer-ci.com/g/yoanm/symfony-jsonrpc-http-server-openapi-doc/?branch=master) [![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/yoanm/symfony-jsonrpc-http-server-openapi-doc/master.svg?logo=scrutinizer)](https://scrutinizer-ci.com/g/yoanm/symfony-jsonrpc-http-server-openapi-doc/?branch=master)
45

5-
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/yoanm/symfony-jsonrpc-http-server-openapi-doc/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/yoanm/symfony-jsonrpc-http-server-openapi-doc/?branch=master) [![Build Status](https://scrutinizer-ci.com/g/yoanm/symfony-jsonrpc-http-server-openapi-doc/badges/build.png?b=master)](https://scrutinizer-ci.com/g/yoanm/symfony-jsonrpc-http-server-openapi-doc/build-status/master) [![Code Coverage](https://scrutinizer-ci.com/g/yoanm/symfony-jsonrpc-http-server-openapi-doc/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/yoanm/symfony-jsonrpc-http-server-openapi-doc/?branch=master)
6-
7-
[![Travis Build Status](https://img.shields.io/travis/yoanm/symfony-jsonrpc-http-server-openapi-doc/master.svg?label=travis)](https://travis-ci.org/yoanm/symfony-jsonrpc-http-server-openapi-doc) [![Travis PHP versions](https://img.shields.io/travis/php-v/yoanm/symfony-jsonrpc-http-server-openapi-doc.svg)](https://travis-ci.org/yoanm/symfony-jsonrpc-http-server-openapi-doc)
6+
[![Travis Build Status](https://img.shields.io/travis/com/yoanm/symfony-jsonrpc-http-server-openapi-doc/master.svg?label=Travis&logo=travis)](https://travis-ci.com/yoanm/symfony-jsonrpc-http-server-openapi-doc) [![Travis PHP versions](https://img.shields.io/travis/php-v/yoanm/symfony-jsonrpc-http-server-openapi-doc.svg?logo=travis)](https://php.net/) [![Travis Symfony Versions](https://img.shields.io/badge/Symfony-v3%20%2F%20v4-8892BF.svg?logo=travis)](https://symfony.com/)
87

98
[![Latest Stable Version](https://img.shields.io/packagist/v/yoanm/symfony-jsonrpc-http-server-openapi-doc.svg)](https://packagist.org/packages/yoanm/symfony-jsonrpc-http-server-openapi-doc) [![Packagist PHP version](https://img.shields.io/packagist/php-v/yoanm/symfony-jsonrpc-http-server-openapi-doc.svg)](https://packagist.org/packages/yoanm/symfony-jsonrpc-http-server-openapi-doc)
109

1110
Symfony bundle for easy JSON-RPC server OpenAPI 3.0.0 documentation
1211

12+
Symfony bundle for [yoanm/jsonrpc-http-server-openapi-doc-sdk](https://github.com/yoanm/php-jsonrpc-http-server-openapi-doc-sdk)
13+
1314
## How to use
14-
 
15+
16+
Once configured, your project is ready to handle HTTP `GET` request on `/doc/openapi.json` endpoint. Result will be a openapi compatible file.
17+
18+
See below how to configure it.
19+
20+
## Configuration
21+
22+
[Behat demo app configuration folders](./features/demo_app) can be used as examples.
23+
24+
- Add the bundles in your config/bundles.php file:
25+
```php
26+
// config/bundles.php
27+
return [
28+
...
29+
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
30+
Yoanm\SymfonyJsonRpcHttpServer\JsonRpcHttpServerBundle::class => ['all' => true],
31+
Yoanm\SymfonyJsonRpcHttpServerDoc\JsonRpcHttpServerDocBundle::class => ['all' => true],
32+
Yoanm\SymfonyJsonRpcHttpServerOpenAPIDoc\JsonRpcHttpServerOpenAPIDocBundle::class => ['all' => true],
33+
...
34+
];
35+
```
36+
37+
- Configure `yoanm/symfony-jsonrpc-http-server` as described on [yoanm/symfony-jsonrpc-http-server](https://github.com/yoanm/symfony-jsonrpc-http-server) documentation.
38+
39+
- Configure `yoanm/symfony-jsonrpc-http-server-doc` as described on [yoanm/symfony-jsonrpc-http-server-doc](https://github.com/yoanm/symfony-jsonrpc-http-server-doc) documentation.
40+
41+
- Query your project at `/doc/openapi.json` endpoint and you will have a OpenAPI json documentation file of your server.
42+
43+
## Event
44+
45+
You are able to enhance resulting documentation by listening on `json_rpc_http_server_openapi_doc.array_created` event.
46+
47+
See below an example of listener service configuration:
48+
```yaml
49+
method_doc_created.listener:
50+
class: Full\Namespace\DocCreatedListener # <-- replace by your class name
51+
tags:
52+
- name: 'kernel.event_listener'
53+
event: 'json_rpc_http_server_openapi_doc.array_created'
54+
method: 'enhanceMethodDoc' # <-- replace by your method name
55+
```
56+
57+
You will receive an event of type [`OpenAPIDocCreatedEvent`](./src/Event/OpenAPIDocCreatedEvent.php).
58+
59+
You can take example on Behat [`DocCreatedListener`](./features/demo_app/src/Listener/DocCreatedListener.php)  
1560

1661
## Contributing
1762
See [contributing note](./CONTRIBUTING.md)

behat.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,18 @@ default:
22
suites:
33
default:
44
contexts:
5-
- Tests\Functional\BehatContext\FeatureContext: ~
5+
- Tests\Functional\BehatContext\DemoAppContext: ~
6+
coverage:
7+
extensions:
8+
LeanPHP\Behat\CodeCoverage\Extension:
9+
drivers:
10+
- local
11+
filter:
12+
whitelist:
13+
include:
14+
directories:
15+
'src': ~
16+
report:
17+
format: html
18+
options:
19+
target: build/behat-coverage

composer.json

Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,48 @@
11
{
2-
"name": "yoanm/symfony-jsonrpc-http-server-openapi-doc",
3-
"description": "Symfony bundle for easy JSON-RPC server OpenAPI 3.0.0 documentation",
4-
"license": "MIT",
5-
"type": "library",
6-
"support": {
7-
"issues": "https://github.com/yoanm/symfony-jsonrpc-http-server-openapi-doc/issues"
8-
},
9-
"authors": [
10-
{
11-
"name": "Yoanm",
12-
"email": "[email protected]",
13-
"role": "Developer"
14-
}
15-
],
16-
"autoload": {
17-
"psr-4": {
18-
"Yoanm\\SymfonyJsonRpcHttpServerOpenAPIDoc\\": "src"
19-
}
20-
},
21-
"autoload-dev": {
22-
"psr-4": {
23-
"Tests\\": "tests",
24-
"Tests\\Functional\\BehatContext\\": "features/bootstrap"
25-
}
26-
},
27-
"require": {
28-
"php": ">=5.5",
29-
"yoanm/jsonrpc-server-doc-sdk": "dev-feature/improve",
30-
"yoanm/jsonrpc-http-server-openapi-doc-sdk": "dev-feature/improve",
31-
"yoanm/symfony-jsonrpc-http-server-doc": "dev-feature/improve",
32-
"symfony/http-foundation": "^3.0 || ^4.0",
33-
"symfony/http-kernel": "^3.0 || ^4.0",
34-
"symfony/config": "^3.0 || ^4.0",
35-
"symfony/dependency-injection": "^3.0 || ^4.0"
36-
},
37-
"require-dev": {
38-
"behat/behat": "~3.0",
39-
"squizlabs/php_codesniffer": "3.*",
40-
"phpunit/phpunit": "^6.0 || ^7.0",
41-
"matthiasnoback/symfony-dependency-injection-test": "^2.0 || ^3.0",
42-
"matthiasnoback/symfony-config-test": "^3.0 || ^4.0",
43-
"symfony/framework-bundle": "^3.4",
44-
"yoanm/php-unit-extended": "~1.0"
2+
"name": "yoanm/symfony-jsonrpc-http-server-openapi-doc",
3+
"description": "Symfony bundle for easy JSON-RPC server OpenAPI 3.0.0 documentation",
4+
"license": "MIT",
5+
"type": "library",
6+
"support": {
7+
"issues": "https://github.com/yoanm/symfony-jsonrpc-http-server-openapi-doc/issues"
8+
},
9+
"authors": [
10+
{
11+
"name": "Yoanm",
12+
"email": "[email protected]",
13+
"role": "Developer"
4514
}
15+
],
16+
"autoload": {
17+
"psr-4": {
18+
"Yoanm\\SymfonyJsonRpcHttpServerOpenAPIDoc\\": "src"
19+
}
20+
},
21+
"autoload-dev": {
22+
"psr-4": {
23+
"Tests\\": "tests",
24+
"Tests\\Functional\\BehatContext\\": "features/bootstrap",
25+
"DemoApp\\": "features/demo_app/src"
26+
}
27+
},
28+
"suggest": {
29+
"yoanm/symfony-jsonrpc-http-server": "Symfony Bundle to convert an HTTP json-rpc request into HTTP json-rpc response"
30+
},
31+
"require": {
32+
"php": ">=7.1",
33+
"yoanm/jsonrpc-server-doc-sdk": "^0.1",
34+
"yoanm/jsonrpc-http-server-openapi-doc-sdk": "^0.1",
35+
"yoanm/symfony-jsonrpc-http-server-doc": "^0.1",
36+
"symfony/http-kernel": "^3.0 || ^4.0",
37+
"symfony/dependency-injection": "^3.0 || ^4.0"
38+
},
39+
"require-dev": {
40+
"behat/behat": "~3.0",
41+
"squizlabs/php_codesniffer": "3.*",
42+
"phpunit/phpunit": "^6.0 || ^7.0",
43+
"matthiasnoback/symfony-dependency-injection-test": "^2.0 || ^3.0",
44+
"matthiasnoback/symfony-config-test": "^3.0 || ^4.0",
45+
"symfony/framework-bundle": "^3.0 || ^4.0",
46+
"yoanm/php-unit-extended": "~1.0"
47+
}
4648
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
namespace Tests\Functional\BehatContext;
3+
4+
use Behat\Behat\Context\Context;
5+
6+
class AbstractContext implements Context
7+
{
8+
protected function jsonDecode($encodedData)
9+
{
10+
$decoded = json_decode($encodedData, true);
11+
12+
if (JSON_ERROR_NONE != json_last_error()) {
13+
throw new \Exception(
14+
json_last_error_msg(),
15+
json_last_error()
16+
);
17+
}
18+
19+
return $decoded;
20+
}
21+
}

0 commit comments

Comments
 (0)