Community Plugin: This plugin is developed, tested, and maintained by a third-party contributor.
This plugin will expose the OpenAPI Spec (OAS), Swagger, or other specification of auth protected API services fronted by the Kong gateway.
API providers need a means of exposing the specifications of their services while maintaining authentication on the service itself - this plugin solves this problem by:
-
Plugin enables Kong Admin to specify the endpoint of their API specification.
-
Plugin will validate the Proxy request is GET method, and will validate the proxy request ends with “/specz”. If these two requirements are met, the endpoint will return the specification of the API Service with Content-Type header identical to what the API Service exposes.
Installation
Recommended:
1
| $ luarocks install kong-spec-expose
|
Other:
1
2
3
| $ git clone https://github.com/Optum/kong-spec-expose.git /path/to/kong/plugins/kong-spec-expose
$ cd /path/to/kong/plugins/kong-spec-expose
$ luarocks make *.rockspec
|
Maintainers
jeremyjpj0916
rsbrisci
Feel free to open issues, or refer to our Contribution Guidelines if you have any questions.
Configuration Reference
Enabling the plugin on a service
Admin API
Kubernetes
Declarative (YAML)
For example, configure this plugin on a service by
making the following request:
1
2
3
| $ curl -X POST http://<admin-hostname>:8001/services/<service>/plugins \
--data "name=kong-spec-expose" \
--data "config.spec_url=https://github.com/OAI/OpenAPI-Specification/blob/master/examples/v2.0/json/petstore.json"
|
<service>
is the id
or name
of the service that this plugin
configuration will target.
First, create a KongPlugin
resource:
1
2
3
4
5
6
7
| apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: <kong-spec-expose-example>
config:
spec_url: https://github.com/OAI/OpenAPI-Specification/blob/master/examples/v2.0/json/petstore.json
plugin: kong-spec-expose
|
Next, apply the KongPlugin resource to a
Service by annotating the
Service as follows:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| apiVersion: v1
kind: Service
metadata:
name: <service>
labels:
app: <service>
annotations:
konghq.com/plugins: <kong-spec-expose-example>
spec:
ports:
- port: 80
targetPort: 80
protocol: TCP
name: <service>
selector:
app: <service>
|
<service>
is the id
or name
of the service that this plugin
configuration will target.
Note: The KongPlugin resource only needs to be defined once
and can be applied to any service, consumer, or route in the namespace. If you
want the plugin to be available cluster-wide, create the resource as a
KongClusterPlugin
instead of KongPlugin
.
For example, configure this plugin on a service by
adding this section to your declarative configuration file:
1
2
3
4
5
| plugins:
- name: kong-spec-expose
service: <service>
config:
spec_url: https://github.com/OAI/OpenAPI-Specification/blob/master/examples/v2.0/json/petstore.json
|
<service>
is the id
or name
of the service that this plugin
configuration will target.
Enabling the plugin on a route
Admin API
Kubernetes
Declarative (YAML)
For example, configure this plugin on a route with:
1
2
3
| $ curl -X POST http://<admin-hostname>:8001/routes/<route>/plugins \
--data "name=kong-spec-expose" \
--data "config.spec_url=https://github.com/OAI/OpenAPI-Specification/blob/master/examples/v2.0/json/petstore.json"
|
<route>
is the id
or name
of the route that this plugin configuration
will target.
First, create a KongPlugin
resource:
1
2
3
4
5
6
7
| apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: <kong-spec-expose-example>
config:
spec_url: https://github.com/OAI/OpenAPI-Specification/blob/master/examples/v2.0/json/petstore.json
plugin: kong-spec-expose
|
Then, apply it to an ingress (Route or Routes)
by annotating the ingress as follows:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| apiVersion: networking/v1beta1
kind: Ingress
metadata:
name: <route>
annotations:
kubernetes.io/ingress.class: kong
konghq.com/plugins: <kong-spec-expose-example>
spec:
rules:
- host: examplehostname.com
http:
paths:
- path: /bar
backend:
serviceName: echo
servicePort: 80
|
<route>
is the id
or name
of the route that this plugin configuration
will target.
Note: The KongPlugin resource only needs to be defined once
and can be applied to any service, consumer, or route in the namespace. If you
want the plugin to be available cluster-wide, create the resource as a
KongClusterPlugin
instead of KongPlugin
.
For example, configure this plugin on a route by
adding this section to your declarative configuration file:
1
2
3
4
5
| plugins:
- name: kong-spec-expose
route: <route>
config:
spec_url: https://github.com/OAI/OpenAPI-Specification/blob/master/examples/v2.0/json/petstore.json
|
<route>
is the id
or name
of the route that this plugin configuration
will target.
Enabling the plugin globally
A plugin which is not associated to any service, route, or consumer is
considered global, and will be run on every request. Read the
Plugin Reference and the Plugin Precedence
sections for more information.
Admin API
Kubernetes
Declarative (YAML)
For example, configure this plugin globally with:
1
2
3
| $ curl -X POST http://<admin-hostname>:8001/plugins/ \
--data "name=kong-spec-expose" \
--data "config.spec_url=https://github.com/OAI/OpenAPI-Specification/blob/master/examples/v2.0/json/petstore.json"
|
Create a KongClusterPlugin
resource and label it as global:
1
2
3
4
5
6
7
8
9
10
11
| apiVersion: configuration.konghq.com/v1
kind: KongClusterPlugin
metadata:
name: <global-kong-spec-expose>
annotations:
kubernetes.io/ingress.class: kong
labels:
global: \"true\"
config:
spec_url: https://github.com/OAI/OpenAPI-Specification/blob/master/examples/v2.0/json/petstore.json
plugin: kong-spec-expose
|
For example, configure this plugin using the plugins:
entry in the declarative
configuration file:
1
2
3
4
| plugins:
- name: kong-spec-expose
config:
spec_url: https://github.com/OAI/OpenAPI-Specification/blob/master/examples/v2.0/json/petstore.json
|
Parameters
Here's a list of all the parameters which can be used in this plugin's configuration:
Form Parameter | Description |
name
Type: string |
The name of the plugin to use, in this case kong-spec-expose . |
service.id
Type: string |
The ID of the Service the plugin targets. |
route.id
Type: string |
The ID of the Route the plugin targets. |
enabled
Type: boolean
Default value: true |
Whether this plugin will be applied. |
api_id
Type: string |
The ID of the API the plugin targets.
Note: The API Entity is deprecated in favor of Services since CE 0.13.0 and EE 0.32. |
config.spec_url
required
|
The full path to the specification/documentation of your service.
|