Skip to content

Commit 8ebae10

Browse files
committed
Add Sphinx doc
1 parent aa16387 commit 8ebae10

File tree

8 files changed

+468
-2
lines changed

8 files changed

+468
-2
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ composer.lock
66
.idea/
77
coverage.xml
88
results.xml
9+
docs/_build
10+
docs/make.bat

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ return [
125125
With the configuration above, routes on the `v1.*` domain will have the `Token` and `Version` headers applied, while routes on the `v2.*` domain will have the `Authorization` and `Api-Version` headers applied.
126126

127127
> Note: the `include` and `exclude` items are arrays of route names. THe * wildcard is supported.
128-
> Note: If you're using DIngo router, the `versions` parameter is required in each route group. This parameter does not support wildcards. Each version must be listed explicitly,
128+
> Note: If you're using Dingo router, the `versions` parameter is required in each route group. This parameter does not support wildcards. Each version must be listed explicitly,
129129
130130
To generate your API documentation, use the `apidoc:generate` artisan command.
131131

@@ -384,7 +384,7 @@ If you don't specify an example response using any of the above means, this pack
384384
- The configuration for response calls is located in the `config/apidoc.php`. They are configured within the `['apply']['response_calls']` section for each route group, allowing you to apply different settings for different sets of routes.
385385
- By default, response calls are only made for GET routes, but you can configure this. Set the `methods` key to an array of methods or '*' to mean all methods. Leave it as an empty array to turn off response calls for that route group.
386386
- Parameters in URLs (example: `/users/{user}`, `/orders/{id?}`) will be replaced with '1' by default. You can configure this, however. Put the parameter names (including curly braces and question marks) as the keys and their replacements as the values in the `bindings` key.
387-
- You can configure environment variables (this is useful so you can prevent external services like notifications from being triggered). By default the APP_ENV is set to 'documentation'. You can add more variables in the `env` key.
387+
- You can set Laravel config variables (this is useful so you can prevent external services like notifications from being triggered). By default the `app.env` is set to 'documentation'. You can add more variables in the `config` key.
388388
- By default, the package will generate dummy values for your documented body and query parameters and send in the request. (If you specified example values using `@bodyParam` or `@queryParam`, those will be used instead.) You can configure what headers and additional query and parameters should be sent when making the request (the `headers`, `query`, and `body` keys respectively).
389389

390390

docs/Makefile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line.
5+
SPHINXOPTS =
6+
SPHINXBUILD = sphinx-build
7+
SOURCEDIR = .
8+
BUILDDIR = _build
9+
10+
# Put it first so that "make" without argument is like "make help".
11+
help:
12+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
13+
14+
.PHONY: help Makefile
15+
16+
# Catch-all target: route all unknown targets to Sphinx using the new
17+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
18+
%: Makefile
19+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/conf.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Configuration file for the Sphinx documentation builder.
2+
#
3+
# This file only contains a selection of the most common options. For a full
4+
# list see the documentation:
5+
# http://www.sphinx-doc.org/en/master/config
6+
7+
# -- Path setup --------------------------------------------------------------
8+
9+
# If extensions (or modules to document with autodoc) are in another directory,
10+
# add these directories to sys.path here. If the directory is relative to the
11+
# documentation root, use os.path.abspath to make it absolute, like shown here.
12+
#
13+
# import os
14+
# import sys
15+
# sys.path.insert(0, os.path.abspath('.'))
16+
import recommonmark
17+
from recommonmark.transform import AutoStructify
18+
19+
# -- Project information -----------------------------------------------------
20+
21+
project = 'laravel-apidoc-generator'
22+
copyright = '2019, Marcel Pociot'
23+
author = 'Marcel Pociot'
24+
25+
26+
# -- General configuration ---------------------------------------------------
27+
28+
# Add any Sphinx extension module names here, as strings. They can be
29+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
30+
# ones.
31+
extensions = ['recommonmark']
32+
33+
# Add any paths that contain templates here, relative to this directory.
34+
templates_path = ['_templates']
35+
36+
# List of patterns, relative to source directory, that match files and
37+
# directories to ignore when looking for source files.
38+
# This pattern also affects html_static_path and html_extra_path.
39+
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
40+
41+
42+
# -- Options for HTML output -------------------------------------------------
43+
44+
# The theme to use for HTML and HTML Help pages. See the documentation for
45+
# a list of builtin themes.
46+
#
47+
html_theme = 'sphinx_rtd_theme'
48+
49+
# Add any paths that contain custom static files (such as style sheets) here,
50+
# relative to this directory. They are copied after the builtin static files,
51+
# so a file named "default.css" will overwrite the builtin "default.css".
52+
html_static_path = ['_static']
53+
54+
# app setup hook
55+
def setup(app):
56+
app.add_config_value('recommonmark_config', {
57+
'auto_toc_tree_section': 'Contents',
58+
}, True)
59+
app.add_transform(AutoStructify)

docs/config.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Configuration
2+
3+
Before you can generate your documentation, you'll need to configure a few things in your `config/apidoc.php`.
4+
5+
- `output`
6+
This is the file path where the generated documentation will be written to. Default: **public/docs**
7+
8+
- `postman`
9+
This package can automatically generate a Postman collection for your routes, along with the documentation. This section is where you can configure (or disable) that.
10+
11+
- `router`
12+
The router to use when processing the route (can be Laravel or Dingo. Defaults to **Laravel**)
13+
14+
- `logo`
15+
You can specify your custom logo to be used on the generated documentation. Set the `logo` option to an absolute path pointing to your logo file.
16+
17+
- `routes`
18+
This is where you specify what rules documentation should be generated for. You specify routes to be parsed by defining conditions that the routes should meet and rules that should be applied when generating documentation. These conditions and rules are specified in groups, allowing you to apply different rules to different routes.
19+
20+
For instance, suppose your configuration looks like this:
21+
22+
```php
23+
return [
24+
//...,
25+
26+
'routes' => [
27+
[
28+
'match' => [
29+
'domains' => ['*'],
30+
'prefixes' => ['api/*', 'v2-api/*'],
31+
'versions' => ['v1'],
32+
],
33+
'include' => ['users.index', 'healthcheck*'],
34+
'exclude' => ['users.create', 'admin.*'],
35+
'apply' => [
36+
'headers' => [
37+
'Authorization' => 'Bearer: {token}',
38+
],
39+
],
40+
],
41+
];
42+
```
43+
44+
This means documentation will be generated for routes in all domains ('*' is a wildcard meaning 'any character') which match any of the patterns 'api/*' or 'v2-api/*', excluding the 'users.create' route and any routes whose names begin with `admin.`, and including the 'users.index' route and any routes whose names begin with `healthcheck.`. (The `versions` key is ignored unless you are using Dingo router).
45+
Also, in the generated documentation, these routes will have the header 'Authorization: Bearer: {token}' added to the example requests.
46+
47+
You can also separate routes into groups to apply different rules to them:
48+
49+
```php
50+
<?php
51+
return [
52+
//...,
53+
54+
'routes' => [
55+
[
56+
'match' => [
57+
'domains' => ['v1.*'],
58+
'prefixes' => ['*'],
59+
],
60+
'include' => [],
61+
'exclude' => [],
62+
'apply' => [
63+
'headers' => [
64+
'Token' => '{token}',
65+
'Version' => 'v1',
66+
],
67+
],
68+
],
69+
[
70+
'match' => [
71+
'domains' => ['v2.*'],
72+
'prefixes' => ['*'],
73+
],
74+
'include' => [],
75+
'exclude' => [],
76+
'apply' => [
77+
'headers' => [
78+
'Authorization' => 'Bearer: {token}',
79+
'Api-Version' => 'v2',
80+
],
81+
],
82+
],
83+
];
84+
```
85+
86+
With the configuration above, routes on the `v1.*` domain will have the `Token` and `Version` headers applied, while routes on the `v2.*` domain will have the `Authorization` and `Api-Version` headers applied.
87+
88+
> Note: the `include` and `exclude` items are arrays of route names. THe &ast; wildcard is supported.
89+
> Note: If you're using DIngo router, the `versions` parameter is required in each route group. This parameter does not support wildcards. Each version must be listed explicitly,

0 commit comments

Comments
 (0)