Skip to content

Commit c12e4f6

Browse files
committed
update custom domain
1 parent eb197c1 commit c12e4f6

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ Automatically generate your API documentation from your existing Laravel routes.
44

55
`php artisan api:gen --routePrefix="settings/api/*"`
66

7-
![image](http://img.shields.io/packagist/v/mpociot/laravel-apidoc-generator.svg?style=flat)
8-
![image](http://img.shields.io/packagist/l/mpociot/laravel-apidoc-generator.svg?style=flat)
9-
[![codecov.io](https://codecov.io/github/mpociot/laravel-apidoc-generator/coverage.svg?branch=master)](https://codecov.io/github/mpociot/laravel-apidoc-generator?branch=master)
10-
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/mpociot/laravel-apidoc-generator/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/mpociot/laravel-apidoc-generator/?branch=master)
11-
[![Build Status](https://travis-ci.org/mpociot/laravel-apidoc-generator.svg?branch=master)](https://travis-ci.org/mpociot/laravel-apidoc-generator)
7+
![image](http://img.shields.io/packagist/v/oxycoder/laravel-apidoc-generator.svg?style=flat)
8+
![image](http://img.shields.io/packagist/l/oxycoder/laravel-apidoc-generator.svg?style=flat)
9+
[![codecov.io](https://codecov.io/github/oxycoder/laravel-apidoc-generator/coverage.svg?branch=master)](https://codecov.io/github/oxycoder/laravel-apidoc-generator?branch=master)
10+
[![Build Status](https://travis-ci.org/oxycoder/laravel-apidoc-generator.svg?branch=master)](https://travis-ci.org/oxycoder/laravel-apidoc-generator)
1211
[![StyleCI](https://styleci.io/repos/57999295/shield?style=flat)](https://styleci.io/repos/57999295)
13-
[![Dependency Status](https://www.versioneye.com/php/mpociot:laravel-apidoc-generator/dev-master/badge?style=flat)](https://www.versioneye.com/php/mpociot:laravel-apidoc-generator/dev-master)
12+
[![Dependency Status](https://www.versioneye.com/php/oxycoder:laravel-apidoc-generator/dev-master/badge?style=flat)](https://www.versioneye.com/php/oxycoder:laravel-apidoc-generator/dev-master)
1413

1514

1615
## Installation
@@ -64,6 +63,7 @@ Option | Description
6463
`bindings` | List of route bindings that should be replaced when trying to retrieve route results. Syntax format: `binding_one,id|binding_two,id`
6564
`force` | Force the re-generation of existing/modified API routes
6665
`header` | Custom HTTP headers to add to the example requests. Separate the header name and value with ":". For example: `--header="Authorization: CustomToken"`
66+
`domain` | Custom domain to get response. Domain must end with "/". Will be ignore if `noResponseCalls` set to TRUE
6767

6868
## Customisation or translation.
6969

src/Oxycoder/ApiDoc/Commands/GenerateDocumentation.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class GenerateDocumentation extends Command
3535
{--force : Force rewriting of existing routes}
3636
{--bindings= : Route Model Bindings}
3737
{--header=* : Custom HTTP headers to add to the example requests. Separate the header name and value with ":"}
38+
{--domain= : Custom domain on get response. Domain must end with splash}
3839
';
3940

4041
/**
@@ -268,7 +269,7 @@ private function processLaravelRoutes(AbstractGenerator $generator, $allowedRout
268269
foreach ($routes as $route) {
269270
if (in_array($route->getName(), $allowedRoutes) || str_is($routePrefix, $generator->getUri($route)) || in_array($middleware, $route->middleware())) {
270271
if ($this->isValidRoute($route) && $this->isRouteVisibleForDocumentation($route->getAction()['uses'])) {
271-
$parsedRoutes[] = $generator->processRoute($route, $bindings, $headers, $withResponse);
272+
$parsedRoutes[] = $generator->processRoute($route, $bindings, $headers, $withResponse, $this->options());
272273
$this->info('Processed route: ['.implode(',', $generator->getMethods($route)).'] '.$generator->getUri($route));
273274
} else {
274275
$this->warn('Skipping route: ['.implode(',', $generator->getMethods($route)).'] '.$generator->getUri($route));

src/Oxycoder/ApiDoc/Generators/AbstractGenerator.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ protected function getParameters($routeData, $routeAction, $bindings)
111111
*
112112
* @return \Illuminate\Http\Response
113113
*/
114-
protected function getRouteResponse($route, $bindings, $headers = [])
114+
protected function getRouteResponse($route, $bindings, $headers = [], $domain = "")
115115
{
116116
$uri = $this->addRouteModelBindings($route, $bindings);
117117

@@ -129,6 +129,11 @@ protected function getRouteResponse($route, $bindings, $headers = [])
129129
//Changes url with parameters like /users/{user} to /users/1
130130
$uri = preg_replace('/{(.*?)}/', 1, $uri);
131131

132+
if ($domain != "") {
133+
// process custom domain
134+
$uri = $domain . $uri;
135+
}
136+
132137
return $this->callRoute(array_shift($methods), $uri, [], [], [], $headers);
133138
}
134139

src/Oxycoder/ApiDoc/Generators/LaravelGenerator.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,14 @@ public function getMethods($route)
4747
* @param array $bindings
4848
* @param array $headers
4949
* @param bool $withResponse
50+
* @param array $options
5051
*
5152
* @return array
5253
*/
53-
public function processRoute($route, $bindings = [], $headers = [], $withResponse = true)
54+
public function processRoute($route, $bindings = [], $headers = [], $withResponse = true, $options = [])
5455
{
5556
$content = '';
57+
$route->setUri($options['uri']);
5658

5759
$routeAction = $route->getAction();
5860
$routeGroup = $this->getRouteGroup($routeAction['uses']);
@@ -76,7 +78,7 @@ public function processRoute($route, $bindings = [], $headers = [], $withRespons
7678
}
7779
}
7880
if (! $response) {
79-
$response = $this->getRouteResponse($route, $bindings, $headers);
81+
$response = $this->getRouteResponse($route, $bindings, $headers, $options['domain']);
8082
}
8183
if ($response->headers->get('Content-Type') === 'application/json') {
8284
$content = json_decode($response->getContent(), JSON_PRETTY_PRINT);

0 commit comments

Comments
 (0)