Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,14 @@ build:
tests:
stop_on_failure: true
override:
- php-scrutinizer-run --enable-security-analysis
-
command: make codestyle
analysis:
file: 'build/reports/cs-data'
format: 'php-cs-checkstyle'
-
command: make coverage
idle_timeout: 1200
coverage:
file: 'build/coverage/clover.xml'
format: 'php-clover'
- php-scrutinizer-run --enable-security-analysis
- make codestyle
cache:
directories:
- ~/.composer
Expand All @@ -39,8 +35,6 @@ build:
COMPOSER_OPTIONS: '--optimize-autoloader'
COVERAGE_OUTPUT_STYLE: 'clover'
COVERAGE_CLOVER_FILE_PATH: 'build/coverage/clover.xml'
PHPCS_REPORT_STYLE: 'checkstyle'
PHPCS_REPORT_FILE: 'build/reports/cs-data'
php:
version: "7.1"
timezone: UTC
Expand Down
8 changes: 6 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
language: php

php:
- '7.0'
- '7.1'
- '7.2'
- '7.3'

env:
global:
Expand All @@ -19,7 +19,7 @@ matrix:

before_install:
# remove xdebug to speed up build
- phpenv config-rm xdebug.ini
- phpenv config-rm xdebug.ini || true

install:
- make build
Expand All @@ -31,3 +31,7 @@ cache:
directories:
- $HOME/.composer
- vendor

branches:
except:
- /.*\-dev$/
18 changes: 16 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ COVERAGE_OUTPUT_STYLE ?= html
BUILD_DIRECTORY ?= build
REPORTS_DIRECTORY ?= ${BUILD_DIRECTORY}/reports
COVERAGE_DIRECTORY ?= ${BUILD_DIRECTORY}/coverage
BEHAT_COVERAGE_DIRECTORY ?= ${BUILD_DIRECTORY}/behat-coverage
COVERAGE_CLOVER_FILE_PATH ?= ${COVERAGE_DIRECTORY}/clover.xml

## Commands options
### Composer
#COMPOSER_OPTIONS=
### Phpcs
PHPCS_REPORT_STYLE ?= full
PHPCS_DISABLE_WARNING ?= "false"
#PHPCS_REPORT_FILE=
#PHPCS_REPORT_FILE_OPTION=

Expand Down Expand Up @@ -51,6 +53,12 @@ ifneq ("${PHPCS_REPORT_FILE}","")
PHPCS_REPORT_FILE_OPTION ?= --report-file=${PHPCS_REPORT_FILE}
endif

ifneq ("${PHPCS_DISABLE_WARNING}","true")
PHPCS_DISABLE_WARNING_OPTION=
else
PHPCS_DISABLE_WARNING_OPTION=-n
endif


## Project build (install and configure)
build: install configure
Expand All @@ -76,20 +84,26 @@ test-functional:
./vendor/bin/behat ${BEHAT_COLOR_OPTION} ${BEHAT_OUTPUT_STYLE_OPTION} --no-snippets

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

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

behat-coverage: create-behat-coverage-directory
composer required leanphp/behat-code-coverage
./vendor/bin/behat ${BEHAT_COLOR_OPTION} ${BEHAT_OUTPUT_STYLE_OPTION} --no-snippets --profile coverage


# Internal commands
create-coverage-directory:
mkdir -p ${COVERAGE_DIRECTORY}

create-behat-coverage-directory:
mkdir -p ${BEHAT_COVERAGE_DIRECTORY}

create-reports-directory:
mkdir -p ${REPORTS_DIRECTORY}


.PHONY: build install configure test test-technical test-functional codestyle coverage create-coverage-directory create-reports-directory
.PHONY: build install configure test test-technical test-functional codestyle coverage behat-coverage create-coverage-directory create-behat-coverage-directory create-reports-directory
.DEFAULT: build
65 changes: 62 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,75 @@
# JSON-RPC Http server OpenAPI documentation
[![License](https://img.shields.io/github/license/yoanm/php-jsonrpc-http-server-openapi-doc-sdk.svg)](https://github.com/yoanm/php-jsonrpc-http-server-openapi-doc-sdk) [![Code size](https://img.shields.io/github/languages/code-size/yoanm/php-jsonrpc-http-server-openapi-doc-sdk.svg)](https://github.com/yoanm/php-jsonrpc-http-server-openapi-doc-sdk) [![PHP Versions](https://img.shields.io/badge/php-7.0%20%2F%207.1%20%2F%207.2-8892BF.svg)](https://php.net/)
[![License](https://img.shields.io/github/license/yoanm/php-jsonrpc-http-server-openapi-doc-sdk.svg)](https://github.com/yoanm/php-jsonrpc-http-server-openapi-doc-sdk) [![Code size](https://img.shields.io/github/languages/code-size/yoanm/php-jsonrpc-http-server-openapi-doc-sdk.svg)](https://github.com/yoanm/php-jsonrpc-http-server-openapi-doc-sdk) [![Dependencies](https://img.shields.io/librariesio/github/yoanm/php-jsonrpc-http-server-openapi-doc-sdk.svg)](https://libraries.io/packagist/yoanm%2Fjsonrpc-http-server-openapi-doc-sdk)

[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/yoanm/php-jsonrpc-http-server-openapi-doc-sdk/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/yoanm/php-jsonrpc-http-server-openapi-doc-sdk/?branch=master) [![Build Status](https://scrutinizer-ci.com/g/yoanm/php-jsonrpc-http-server-openapi-doc-sdk/badges/build.png?b=master)](https://scrutinizer-ci.com/g/yoanm/php-jsonrpc-http-server-openapi-doc-sdk/build-status/master) [![Code Coverage](https://scrutinizer-ci.com/g/yoanm/php-jsonrpc-http-server-openapi-doc-sdk/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/yoanm/php-jsonrpc-http-server-openapi-doc-sdk/?branch=master)
[![Scrutinizer Build Status](https://img.shields.io/scrutinizer/build/g/yoanm/php-jsonrpc-http-server-openapi-doc-sdk.svg?label=Scrutinizer&logo=scrutinizer)](https://scrutinizer-ci.com/g/yoanm/php-jsonrpc-http-server-openapi-doc-sdk/build-status/master) [![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/yoanm/php-jsonrpc-http-server-openapi-doc-sdk/master.svg?logo=scrutinizer)](https://scrutinizer-ci.com/g/yoanm/php-jsonrpc-http-server-openapi-doc-sdk/?branch=master) [![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/yoanm/php-jsonrpc-http-server-openapi-doc-sdk/master.svg?logo=scrutinizer)](https://scrutinizer-ci.com/g/yoanm/php-jsonrpc-http-server-openapi-doc-sdk/?branch=master)

[![Travis Build Status](https://img.shields.io/travis/yoanm/php-jsonrpc-http-server-openapi-doc-sdk/master.svg?label=travis)](https://travis-ci.org/yoanm/php-jsonrpc-http-server-openapi-doc-sdk) [![Travis PHP versions](https://img.shields.io/travis/php-v/yoanm/php-jsonrpc-http-server-openapi-doc-sdk.svg)](https://travis-ci.org/yoanm/php-jsonrpc-http-server-openapi-doc-sdk)
[![Travis Build Status](https://img.shields.io/travis/com/yoanm/php-jsonrpc-http-server-openapi-doc-sdk/master.svg?label=Travis&logo=travis)](https://travis-ci.com/yoanm/php-jsonrpc-http-server-openapi-doc-sdk) [![Travis PHP versions](https://img.shields.io/travis/php-v/yoanm/php-jsonrpc-http-server-openapi-doc-sdk.svg?logo=travis)](https://php.net/)

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

SDK to generate Http JSON-RPC server documentation for OpenAPI v3.0.0

See [`yoanm/symfony-jsonrpc-http-server-openapi-doc`](https://github.com/yoanm/symfony-jsonrpc-http-server-openapi-doc) for automatic dependency injection.

## How to use

Create the normalizer :
```php
use Yoanm\JsonRpcHttpServerOpenAPIDoc\App\Normalizer\Component\ErrorDocNormalizer;
use Yoanm\JsonRpcHttpServerOpenAPIDoc\App\Normalizer\Component\ExternalSchemaListDocNormalizer;
use Yoanm\JsonRpcHttpServerOpenAPIDoc\App\Normalizer\Component\OperationDocNormalizer;
use Yoanm\JsonRpcHttpServerOpenAPIDoc\App\Normalizer\Component\RequestDocNormalizer;
use Yoanm\JsonRpcHttpServerOpenAPIDoc\App\Normalizer\Component\ResponseDocNormalizer;
use Yoanm\JsonRpcHttpServerOpenAPIDoc\App\Normalizer\Component\SchemaTypeNormalizer;
use Yoanm\JsonRpcHttpServerOpenAPIDoc\App\Normalizer\Component\ShapeNormalizer;
use Yoanm\JsonRpcHttpServerOpenAPIDoc\App\Normalizer\Component\TypeDocNormalizer;
use Yoanm\JsonRpcHttpServerOpenAPIDoc\App\Resolver\DefinitionRefResolver;
use Yoanm\JsonRpcHttpServerOpenAPIDoc\Infra\Normalizer\DocNormalizer;

$shapeNormalizer = new ShapeNormalizer();
$definitionRefResolver = new DefinitionRefResolver();
$typeDocNormalizer = new TypeDocNormalizer(
new SchemaTypeNormalizer()
);

$normalizer = new DocNormalizer(
new ExternalSchemaListDocNormalizer(
$definitionRefResolver,
$typeDocNormalizer,
new ErrorDocNormalizer(
$typeDocNormalizer,
$shapeNormalizer
)
),
new OperationDocNormalizer(
$definitionRefResolver,
new RequestDocNormalizer(
$definitionRefResolver,
$shapeNormalizer
),
new ResponseDocNormalizer(
$definitionRefResolver,
$shapeNormalizer
)
)
);
```

Then you can convert `ServerDoc` or `HttpServerDoc` by doing :
```php
use Yoanm\JsonRpcServerDoc\Domain\Model\ServerDoc;

$serverDoc = new ServerDoc();
// Configure server doc
...
// Add methods documentation
...
// Then normalize
/** @var array $openAPIDoc */
$openAPIDoc = $normalizer->normalize($serverDoc);
```



## Contributing
See [contributing note](./CONTRIBUTING.md)
16 changes: 15 additions & 1 deletion behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,18 @@ default:
suites:
default:
contexts:
- Tests\Functional\BehatContext\FeatureContext: ~
- Tests\Functional\BehatContext\DocNormalizerContext: ~
coverage:
extensions:
LeanPHP\Behat\CodeCoverage\Extension:
drivers:
- local
filter:
whitelist:
include:
directories:
'src': ~
report:
format: html
options:
target: build/behat-coverage
74 changes: 40 additions & 34 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,43 @@
{
"name": "yoanm/jsonrpc-http-server-openapi-doc-sdk",
"description": "SDK to generate Http JSON-RPC server documentation for OpenAPI v3.0.0",
"license": "MIT",
"type": "library",
"support": {
"issues": "https://github.com/yoanm/php-jsonrpc-http-server-openapi-doc-sdk/issues"
},
"authors": [
{
"name": "Yoanm",
"email": "yoanm@users.noreply.github.com",
"role": "Developer"
}
],
"autoload": {
"psr-4": {
"Yoanm\\JsonRpcHttpServerOpenAPIDoc\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests",
"Tests\\Functional\\BehatContext\\": "features/bootstrap"
}
},
"require": {
"php": ">5.5",
"yoanm/jsonrpc-server-doc-sdk": "dev-feature/improve"
},
"require-dev": {
"behat/behat": "~3.0",
"squizlabs/php_codesniffer": "3.*",
"phpunit/phpunit": "^6.0 || ^7.0",
"yoanm/php-unit-extended": "~1.0"
"name": "yoanm/jsonrpc-http-server-openapi-doc-sdk",
"description": "SDK to generate Http JSON-RPC server documentation for OpenAPI v3.0.0",
"license": "MIT",
"type": "library",
"support": {
"issues": "https://github.com/yoanm/php-jsonrpc-http-server-openapi-doc-sdk/issues"
},
"authors": [
{
"name": "Yoanm",
"email": "yoanm@users.noreply.github.com",
"role": "Developer"
}
],
"autoload": {
"psr-4": {
"Yoanm\\JsonRpcHttpServerOpenAPIDoc\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests",
"Tests\\Functional\\BehatContext\\": "features/bootstrap"
}
},
"suggest": {
"yoanm/symfony-jsonrpc-http-server-openapi-doc": "Symfony bundle for easy JSON-RPC server OpenAPI 3.0.0 documentation",
"yoanm/symfony-jsonrpc-http-server-doc": "Symfony bundle for easy JSON-RPC server documentation",
"yoanm/symfony-jsonrpc-http-server": "Symfony Bundle to convert an HTTP json-rpc request into HTTP json-rpc response"
},
"require": {
"php": ">=7.1",
"yoanm/jsonrpc-server-doc-sdk": "v0.1.0"
},
"require-dev": {
"ext-json": "*",
"behat/behat": "~3.0",
"squizlabs/php_codesniffer": "3.*",
"phpunit/phpunit": "^6.0 || ^7.0",
"yoanm/php-unit-extended": "~1.0"
}
}
35 changes: 35 additions & 0 deletions features/bootstrap/AbstractContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
namespace Tests\Functional\BehatContext;

use Behat\Behat\Context\Context;

class AbstractContext implements Context
{
protected function jsonDecode($encodedData)
{
$decoded = json_decode($encodedData, true);

if (JSON_ERROR_NONE != json_last_error()) {
throw new \Exception(
json_last_error_msg(),
json_last_error()
);
}

return $decoded;
}

/**
* @param object $object
* @param array $decodedMethodCalls
*/
protected function callMethods($object, array $decodedMethodCalls)
{
foreach ($decodedMethodCalls as $decodedMethodCall) {
call_user_func_array(
[$object, $decodedMethodCall['method']],
$decodedMethodCall['arguments'] ?? []
);
}
}
}
Loading