Skip to content

Commit

Permalink
Merge pull request #3 from hendrikmaus/update-to-drafter-2
Browse files Browse the repository at this point in the history
Update to drafter 2
  • Loading branch information
hendrikmaus committed Mar 31, 2016
2 parents bc2038e + b29bfba commit 2c19f70
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 215 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ The change log itself is written the way that [keepachangelog.com](http://keepac

## [Unreleased]

## [3.0.0] - 2016-03-31
## Changed
- Updated drafter dependency to v2.2.0 in composer.json and readme [BC]
- Implemented new behavior of the sourcemap argument [BC]
- Begin namespace with vendor name `Hmaus` [BC]

## [2.0.0] - 2015-11-07
## Changed
- Increased min required PHP version to >=5.6 [BC]
Expand Down
243 changes: 58 additions & 185 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,15 @@ If you do not already have, add a `scripts` section to your root composer.json:
"scripts": {
"post-install-cmd": [
"if ! [[ -d ext/drafter ]]; then echo \"### Installing drafter to ./ext; drafter bin to ./vendor/bin/ ###\"; fi",
"if ! [[ -d ext/drafter ]]; then git clone --recursive https://github.com/apiaryio/drafter.git ext/drafter; fi",
"if ! [[ -d ext/drafter ]]; then git clone --branch v2.2.0 --recursive https://github.com/apiaryio/drafter.git ext/drafter; fi",
"if ! [[ -d vendor/bin ]]; then mkdir -p vendor/bin; fi",
"if ! [[ -f vendor/bin/drafter ]]; then cd ext/drafter && ./configure && make drafter; fi",
"if ! [[ -f vendor/bin/drafter ]]; then cd vendor/bin && ln -s ../../ext/drafter/bin/drafter drafter; fi"
]
}
```

> Note: the git clone command currently fetches the latest master of drafter; you can customize this to fir your needs,
> e.g. use a tagged release or a specific commit
> Note: the above example checks out a specific given tag `v2.2.0`
Now run `composer install`; it should start building drafter within an `ext/` folder in your project root.
If you want the script to put drafter somewhere else, modify every occurrence of `ext/drafter` to another one.
Expand Down Expand Up @@ -91,233 +90,107 @@ Given this api blueprint source:
Hello World!
```
The result will look similar (json format):
The result will look similar (json refract):
```json
{
"element": "category",
"meta": {
"classes": [
"api"
],
"title": ""
},
"element": "parseResult",
"content": [
{
"element": "category",
"meta": {
"classes": [
"resourceGroup"
"api"
],
"title": ""
},
"content": [
{
"element": "resource",
"element": "category",
"meta": {
"classes": [
"resourceGroup"
],
"title": ""
},
"attributes": {
"href": "/message"
},
"content": [
{
"element": "transition",
"element": "resource",
"meta": {
"title": ""
},
"content": [
{
"element": "httpTransaction",
"content": [
{
"element": "httpRequest",
"attributes": {
"method": "GET"
},
"content": []
},
{
"element": "httpResponse",
"attributes": {
"statusCode": "200",
"headers": {
"element": "httpHeaders",
"content": [
{
"element": "member",
"content": {
"key": {
"element": "string",
"content": "Content-Type"
},
"value": {
"element": "string",
"content": "text/plain"
}
}
}
]
}
},
"content": [
{
"element": "asset",
"meta": {
"classes": "messageBody"
},
"attributes": {
"contentType": "text/plain"
},
"content": "Hello World!\n"
}
]
}
]
}
]
}
]
}
]
}
]
}
```

Setting the type option to 'ast', results in this abstract syntax tree:

> type 'refract' is the default since since drafter v1.0.0
```json
{
"_version": "4.0",
"metadata": [],
"name": "",
"description": "",
"element": "category",
"resourceGroups": [
{
"name": "",
"description": "",
"resources": [
{
"element": "resource",
"name": "",
"description": "",
"uriTemplate": "/message",
"model": {},
"parameters": [],
"actions": [
{
"name": "",
"description": "",
"method": "GET",
"parameters": [],
"attributes": {
"relation": "",
"uriTemplate": ""
"href": "/message"
},
"content": [],
"examples": [
"content": [
{
"name": "",
"description": "",
"requests": [],
"responses": [
"element": "transition",
"meta": {
"title": ""
},
"content": [
{
"name": "200",
"description": "",
"headers": [
{
"name": "Content-Type",
"value": "text/plain"
}
],
"body": "Hello World!\n",
"schema": "",
"element": "httpTransaction",
"content": [
{
"element": "asset",
"element": "httpRequest",
"attributes": {
"role": "bodyExample"
"method": "GET"
},
"content": "Hello World!\n"
}
]
}
]
}
]
}
],
"content": []
}
]
}
],
"content": [
{
"element": "category",
"content": [
{
"element": "resource",
"name": "",
"description": "",
"uriTemplate": "/message",
"model": {},
"parameters": [],
"actions": [
{
"name": "",
"description": "",
"method": "GET",
"parameters": [],
"attributes": {
"relation": "",
"uriTemplate": ""
},
"content": [],
"examples": [
{
"name": "",
"description": "",
"requests": [],
"responses": [
{
"name": "200",
"description": "",
"headers": [
{
"name": "Content-Type",
"value": "text/plain"
}
],
"body": "Hello World!\n",
"schema": "",
"content": [
"content": []
},
{
"element": "asset",
"element": "httpResponse",
"attributes": {
"role": "bodyExample"
"statusCode": "200",
"headers": {
"element": "httpHeaders",
"content": [
{
"element": "member",
"content": {
"key": {
"element": "string",
"content": "Content-Type"
},
"value": {
"element": "string",
"content": "text/plain"
}
}
}
]
}
},
"content": "Hello World!\n"
"content": [
{
"element": "asset",
"meta": {
"classes": [
"messageBody"
]
},
"attributes": {
"contentType": "text/plain"
},
"content": "Hello World!\n"
}
]
}
]
}
]
}
]
}
],
"content": []
]
}
]
}
]
}
```

### Code Examples

> Found something wrong? Feel free to [contribute](https://github.com/hendrikmaus/drafter-php/blob/master/CONTRIBUTING.md)
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@
},
"require-dev": {
"phpunit/phpunit": "~5.0",
"codegyre/robo": "~0.5",
"codeclimate/php-test-reporter": "~0.1"
"codegyre/robo": "~0.7",
"codeclimate/php-test-reporter": "~0.3"
},
"autoload": {
"psr-4": {
"DrafterPhp\\": "src"
"Hmaus\\DrafterPhp\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"DrafterPhp\\Tests\\": "tests"
"Hmaus\\DrafterPhp\\Tests\\": "tests"
}
},
"scripts": {
"clean": "rm -rf vendor/ ext/ composer.lock",
"post-install-cmd": [
"if ! [[ -d ext/drafter ]]; then echo \"### Installing drafter to ./ext; drafter bin to ./vendor/bin/ ###\"; fi",
"if ! [[ -d ext/drafter ]]; then git clone --recursive https://github.com/apiaryio/drafter.git ext/drafter; fi",
"if ! [[ -d ext/drafter ]]; then git clone --branch v2.2.0 --recursive https://github.com/apiaryio/drafter.git ext/drafter; fi",
"if ! [[ -d vendor/bin ]]; then mkdir -p vendor/bin; fi",
"if ! [[ -f vendor/bin/drafter ]]; then cd ext/drafter && ./configure && make drafter; fi",
"if ! [[ -f vendor/bin/drafter ]]; then cd vendor/bin && ln -s ../../ext/drafter/bin/drafter drafter; fi"
Expand Down
17 changes: 8 additions & 9 deletions src/Drafter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,23 @@
* If called without <input file>, 'drafter' will listen on stdin.
*
* options:
* -o, --output save output AST into file (string [=])
* -f, --format output format of the AST (yaml|json) (string [=yaml])
* -t, --type type of the AST (refract|ast) (string [=refract])
* -s, --sourcemap export sourcemap AST into file (string [=])
* -o, --output save output Parse Result into file (string [=])
* -f, --format output format of the Parse Result (yaml|json) (string [=yaml])
* -t, --type type of the Parse Result (refract|ast) (string [=refract])
* -s, --sourcemap export sourcemap in the Parse Result
* -h, --help display this help message
* -v, --version print Drafter version
* -l, --validate validate input only, do not print AST
* -l, --validate validate input only, do not output Parse Result
* -u, --use-line-num use line and row number instead of character index when printing annotation
* ```
*
* @author hmaus
* @since 2015-08-28
* @copyright 2015 (c) Hendrik Maus
* @license All rights reserved.
* @package DrafterPhp
*/

namespace DrafterPhp;
namespace Hmaus\DrafterPhp;

use Symfony\Component\Process\Process;
use Symfony\Component\Process\ProcessBuilder;
Expand Down Expand Up @@ -116,9 +115,9 @@ public function type($type)
return $this;
}

public function sourcemap($path)
public function sourcemap()
{
$this->options['--sourcemap'] = $path;
$this->options['--sourcemap'] = '';

return $this;
}
Expand Down
Loading

0 comments on commit 2c19f70

Please sign in to comment.