Mock endpoints using an API spec
Configures the Mocking plugin and passes the PetStore API specification.
Add this section to your declarative configuration file:
_format_version: "3.0"
plugins:
- name: mocking
config:
api_specification: |
openapi: 3.0.2
servers:
- url: /v3
info:
description: |-
This is a sample Pet Store Server based on the OpenAPI 3.0 specification. You can find out more about
Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!
You can now help us improve the API whether it's by making changes to the definition itself or to the code.
That way, with time, we can improve the API in general, and expose some of the new features in OAS3.
Some useful links:
- [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)
- [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)
version: 1.0.20-SNAPSHOT
title: Swagger Petstore - OpenAPI 3.0
termsOfService: 'http://swagger.io/terms/'
contact:
email: apiteam@swagger.io
license:
name: Apache 2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
tags:
- name: pet
description: Everything about your Pets
externalDocs:
description: Find out more
url: 'http://swagger.io'
- name: store
description: Access to Petstore orders
externalDocs:
description: Find out more about our store
url: 'http://swagger.io'
- name: user
description: Operations about user
paths:
/pet:
post:
tags:
- pet
summary: Add a new pet to the store
description: Add a new pet to the store
operationId: addPet
responses:
'200':
description: Successful operation
content:
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/json:
schema:
$ref: '#/components/schemas/Pet'
'405':
description: Invalid input
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
requestBody:
description: Create a new pet in the store
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/Pet'
put:
tags:
- pet
summary: Update an existing pet
description: Update an existing pet by Id
operationId: updatePet
responses:
'200':
description: Successful operation
content:
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/json:
schema:
$ref: '#/components/schemas/Pet'
'400':
description: Invalid ID supplied
'404':
description: Pet not found
'405':
description: Validation exception
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
requestBody:
description: Update an existent pet in the store
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/Pet'
Make the following request:
curl -i -X POST http://localhost:8001/plugins/ \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--data '
{
"name": "mocking",
"config": {
"api_specification": "openapi: 3.0.2\nservers:\n - url: /v3\ninfo:\n description: |-\n This is a sample Pet Store Server based on the OpenAPI 3.0 specification. You can find out more about\n Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!\n You can now help us improve the API whether it's by making changes to the definition itself or to the code.\n That way, with time, we can improve the API in general, and expose some of the new features in OAS3.\n Some useful links:\n - [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)\n - [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)\n version: 1.0.20-SNAPSHOT\n title: Swagger Petstore - OpenAPI 3.0\n termsOfService: 'http://swagger.io/terms/'\n contact:\n email: apiteam@swagger.io\n license:\n name: Apache 2.0\n url: 'http://www.apache.org/licenses/LICENSE-2.0.html'\ntags:\n - name: pet\n description: Everything about your Pets\n externalDocs:\n description: Find out more\n url: 'http://swagger.io'\n - name: store\n description: Access to Petstore orders\n externalDocs:\n description: Find out more about our store\n url: 'http://swagger.io'\n - name: user\n description: Operations about user\npaths:\n /pet:\n post:\n tags:\n - pet\n summary: Add a new pet to the store\n description: Add a new pet to the store\n operationId: addPet\n responses:\n '200':\n description: Successful operation\n content:\n application/xml:\n schema:\n $ref: '#/components/schemas/Pet'\n application/json:\n schema:\n $ref: '#/components/schemas/Pet'\n '405':\n description: Invalid input\n security:\n - petstore_auth:\n - 'write:pets'\n - 'read:pets'\n requestBody:\n description: Create a new pet in the store\n required: true\n content:\n application/json:\n schema:\n $ref: '#/components/schemas/Pet'\n application/xml:\n schema:\n $ref: '#/components/schemas/Pet'\n application/x-www-form-urlencoded:\n schema:\n $ref: '#/components/schemas/Pet'\n put:\n tags:\n - pet\n summary: Update an existing pet\n description: Update an existing pet by Id\n operationId: updatePet\n responses:\n '200':\n description: Successful operation\n content:\n application/xml:\n schema:\n $ref: '#/components/schemas/Pet'\n application/json:\n schema:\n $ref: '#/components/schemas/Pet'\n '400':\n description: Invalid ID supplied\n '404':\n description: Pet not found\n '405':\n description: Validation exception\n security:\n - petstore_auth:\n - 'write:pets'\n - 'read:pets'\n requestBody:\n description: Update an existent pet in the store\n required: true\n content:\n application/json:\n schema:\n $ref: '#/components/schemas/Pet'\n application/xml:\n schema:\n $ref: '#/components/schemas/Pet'\n application/x-www-form-urlencoded:\n schema:\n $ref: '#/components/schemas/Pet'\n"
}
}
'
Make the following request:
curl -X POST https://{region}.api.konghq.com/v2/control-planes/{controlPlaneId}/core-entities/plugins/ \
--header "accept: application/json" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $KONNECT_TOKEN" \
--data '
{
"name": "mocking",
"config": {
"api_specification": "openapi: 3.0.2\nservers:\n - url: /v3\ninfo:\n description: |-\n This is a sample Pet Store Server based on the OpenAPI 3.0 specification. You can find out more about\n Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!\n You can now help us improve the API whether it's by making changes to the definition itself or to the code.\n That way, with time, we can improve the API in general, and expose some of the new features in OAS3.\n Some useful links:\n - [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)\n - [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)\n version: 1.0.20-SNAPSHOT\n title: Swagger Petstore - OpenAPI 3.0\n termsOfService: 'http://swagger.io/terms/'\n contact:\n email: apiteam@swagger.io\n license:\n name: Apache 2.0\n url: 'http://www.apache.org/licenses/LICENSE-2.0.html'\ntags:\n - name: pet\n description: Everything about your Pets\n externalDocs:\n description: Find out more\n url: 'http://swagger.io'\n - name: store\n description: Access to Petstore orders\n externalDocs:\n description: Find out more about our store\n url: 'http://swagger.io'\n - name: user\n description: Operations about user\npaths:\n /pet:\n post:\n tags:\n - pet\n summary: Add a new pet to the store\n description: Add a new pet to the store\n operationId: addPet\n responses:\n '200':\n description: Successful operation\n content:\n application/xml:\n schema:\n $ref: '#/components/schemas/Pet'\n application/json:\n schema:\n $ref: '#/components/schemas/Pet'\n '405':\n description: Invalid input\n security:\n - petstore_auth:\n - 'write:pets'\n - 'read:pets'\n requestBody:\n description: Create a new pet in the store\n required: true\n content:\n application/json:\n schema:\n $ref: '#/components/schemas/Pet'\n application/xml:\n schema:\n $ref: '#/components/schemas/Pet'\n application/x-www-form-urlencoded:\n schema:\n $ref: '#/components/schemas/Pet'\n put:\n tags:\n - pet\n summary: Update an existing pet\n description: Update an existing pet by Id\n operationId: updatePet\n responses:\n '200':\n description: Successful operation\n content:\n application/xml:\n schema:\n $ref: '#/components/schemas/Pet'\n application/json:\n schema:\n $ref: '#/components/schemas/Pet'\n '400':\n description: Invalid ID supplied\n '404':\n description: Pet not found\n '405':\n description: Validation exception\n security:\n - petstore_auth:\n - 'write:pets'\n - 'read:pets'\n requestBody:\n description: Update an existent pet in the store\n required: true\n content:\n application/json:\n schema:\n $ref: '#/components/schemas/Pet'\n application/xml:\n schema:\n $ref: '#/components/schemas/Pet'\n application/x-www-form-urlencoded:\n schema:\n $ref: '#/components/schemas/Pet'\n"
}
}
'
Make sure to replace the following placeholders with your own values:
-
region
: Geographic region where your Kong Konnect is hosted and operates. -
controlPlaneId
: Theid
of the control plane. -
KONNECT_TOKEN
: Your Personal Access Token (PAT) associated with your Konnect account.
See the Konnect API reference to learn about region-specific URLs and personal access tokens.
echo "
apiVersion: configuration.konghq.com/v1
kind: KongClusterPlugin
metadata:
name: mocking
namespace: kong
annotations:
kubernetes.io/ingress.class: kong
labels:
global: 'true'
config:
api_specification: |
openapi: 3.0.2
servers:
- url: /v3
info:
description: |-
This is a sample Pet Store Server based on the OpenAPI 3.0 specification. You can find out more about
Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!
You can now help us improve the API whether it's by making changes to the definition itself or to the code.
That way, with time, we can improve the API in general, and expose some of the new features in OAS3.
Some useful links:
- [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)
- [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)
version: 1.0.20-SNAPSHOT
title: Swagger Petstore - OpenAPI 3.0
termsOfService: 'http://swagger.io/terms/'
contact:
email: apiteam@swagger.io
license:
name: Apache 2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
tags:
- name: pet
description: Everything about your Pets
externalDocs:
description: Find out more
url: 'http://swagger.io'
- name: store
description: Access to Petstore orders
externalDocs:
description: Find out more about our store
url: 'http://swagger.io'
- name: user
description: Operations about user
paths:
/pet:
post:
tags:
- pet
summary: Add a new pet to the store
description: Add a new pet to the store
operationId: addPet
responses:
'200':
description: Successful operation
content:
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/json:
schema:
$ref: '#/components/schemas/Pet'
'405':
description: Invalid input
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
requestBody:
description: Create a new pet in the store
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/Pet'
put:
tags:
- pet
summary: Update an existing pet
description: Update an existing pet by Id
operationId: updatePet
responses:
'200':
description: Successful operation
content:
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/json:
schema:
$ref: '#/components/schemas/Pet'
'400':
description: Invalid ID supplied
'404':
description: Pet not found
'405':
description: Validation exception
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
requestBody:
description: Update an existent pet in the store
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/Pet'
plugin: mocking
" | kubectl apply -f -
Prerequisite: Configure your Personal Access Token
terraform {
required_providers {
konnect = {
source = "kong/konnect"
}
}
}
provider "konnect" {
personal_access_token = "$KONNECT_TOKEN"
server_url = "https://us.api.konghq.com/"
}
Add the following to your Terraform configuration to create a Konnect Gateway Plugin:
resource "konnect_gateway_plugin_mocking" "my_mocking" {
enabled = true
config = {
api_specification = <<EOF
openapi: 3.0.2
servers:
- url: /v3
info:
description: |-
This is a sample Pet Store Server based on the OpenAPI 3.0 specification. You can find out more about
Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!
You can now help us improve the API whether it's by making changes to the definition itself or to the code.
That way, with time, we can improve the API in general, and expose some of the new features in OAS3.
Some useful links:
- [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)
- [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)
version: 1.0.20-SNAPSHOT
title: Swagger Petstore - OpenAPI 3.0
termsOfService: 'http://swagger.io/terms/'
contact:
email: apiteam@swagger.io
license:
name: Apache 2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
tags:
- name: pet
description: Everything about your Pets
externalDocs:
description: Find out more
url: 'http://swagger.io'
- name: store
description: Access to Petstore orders
externalDocs:
description: Find out more about our store
url: 'http://swagger.io'
- name: user
description: Operations about user
paths:
/pet:
post:
tags:
- pet
summary: Add a new pet to the store
description: Add a new pet to the store
operationId: addPet
responses:
'200':
description: Successful operation
content:
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/json:
schema:
$ref: '#/components/schemas/Pet'
'405':
description: Invalid input
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
requestBody:
description: Create a new pet in the store
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/Pet'
put:
tags:
- pet
summary: Update an existing pet
description: Update an existing pet by Id
operationId: updatePet
responses:
'200':
description: Successful operation
content:
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/json:
schema:
$ref: '#/components/schemas/Pet'
'400':
description: Invalid ID supplied
'404':
description: Pet not found
'405':
description: Validation exception
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
requestBody:
description: Update an existent pet in the store
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/Pet'
EOF
}
control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
}
Add this section to your declarative configuration file:
_format_version: "3.0"
plugins:
- name: mocking
service: serviceName|Id
config:
api_specification: |
openapi: 3.0.2
servers:
- url: /v3
info:
description: |-
This is a sample Pet Store Server based on the OpenAPI 3.0 specification. You can find out more about
Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!
You can now help us improve the API whether it's by making changes to the definition itself or to the code.
That way, with time, we can improve the API in general, and expose some of the new features in OAS3.
Some useful links:
- [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)
- [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)
version: 1.0.20-SNAPSHOT
title: Swagger Petstore - OpenAPI 3.0
termsOfService: 'http://swagger.io/terms/'
contact:
email: apiteam@swagger.io
license:
name: Apache 2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
tags:
- name: pet
description: Everything about your Pets
externalDocs:
description: Find out more
url: 'http://swagger.io'
- name: store
description: Access to Petstore orders
externalDocs:
description: Find out more about our store
url: 'http://swagger.io'
- name: user
description: Operations about user
paths:
/pet:
post:
tags:
- pet
summary: Add a new pet to the store
description: Add a new pet to the store
operationId: addPet
responses:
'200':
description: Successful operation
content:
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/json:
schema:
$ref: '#/components/schemas/Pet'
'405':
description: Invalid input
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
requestBody:
description: Create a new pet in the store
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/Pet'
put:
tags:
- pet
summary: Update an existing pet
description: Update an existing pet by Id
operationId: updatePet
responses:
'200':
description: Successful operation
content:
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/json:
schema:
$ref: '#/components/schemas/Pet'
'400':
description: Invalid ID supplied
'404':
description: Pet not found
'405':
description: Validation exception
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
requestBody:
description: Update an existent pet in the store
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/Pet'
Make sure to replace the following placeholders with your own values:
-
serviceName|Id
: Theid
orname
of the service the plugin configuration will target.
Make the following request:
curl -i -X POST http://localhost:8001/services/{serviceName|Id}/plugins/ \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--data '
{
"name": "mocking",
"config": {
"api_specification": "openapi: 3.0.2\nservers:\n - url: /v3\ninfo:\n description: |-\n This is a sample Pet Store Server based on the OpenAPI 3.0 specification. You can find out more about\n Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!\n You can now help us improve the API whether it's by making changes to the definition itself or to the code.\n That way, with time, we can improve the API in general, and expose some of the new features in OAS3.\n Some useful links:\n - [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)\n - [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)\n version: 1.0.20-SNAPSHOT\n title: Swagger Petstore - OpenAPI 3.0\n termsOfService: 'http://swagger.io/terms/'\n contact:\n email: apiteam@swagger.io\n license:\n name: Apache 2.0\n url: 'http://www.apache.org/licenses/LICENSE-2.0.html'\ntags:\n - name: pet\n description: Everything about your Pets\n externalDocs:\n description: Find out more\n url: 'http://swagger.io'\n - name: store\n description: Access to Petstore orders\n externalDocs:\n description: Find out more about our store\n url: 'http://swagger.io'\n - name: user\n description: Operations about user\npaths:\n /pet:\n post:\n tags:\n - pet\n summary: Add a new pet to the store\n description: Add a new pet to the store\n operationId: addPet\n responses:\n '200':\n description: Successful operation\n content:\n application/xml:\n schema:\n $ref: '#/components/schemas/Pet'\n application/json:\n schema:\n $ref: '#/components/schemas/Pet'\n '405':\n description: Invalid input\n security:\n - petstore_auth:\n - 'write:pets'\n - 'read:pets'\n requestBody:\n description: Create a new pet in the store\n required: true\n content:\n application/json:\n schema:\n $ref: '#/components/schemas/Pet'\n application/xml:\n schema:\n $ref: '#/components/schemas/Pet'\n application/x-www-form-urlencoded:\n schema:\n $ref: '#/components/schemas/Pet'\n put:\n tags:\n - pet\n summary: Update an existing pet\n description: Update an existing pet by Id\n operationId: updatePet\n responses:\n '200':\n description: Successful operation\n content:\n application/xml:\n schema:\n $ref: '#/components/schemas/Pet'\n application/json:\n schema:\n $ref: '#/components/schemas/Pet'\n '400':\n description: Invalid ID supplied\n '404':\n description: Pet not found\n '405':\n description: Validation exception\n security:\n - petstore_auth:\n - 'write:pets'\n - 'read:pets'\n requestBody:\n description: Update an existent pet in the store\n required: true\n content:\n application/json:\n schema:\n $ref: '#/components/schemas/Pet'\n application/xml:\n schema:\n $ref: '#/components/schemas/Pet'\n application/x-www-form-urlencoded:\n schema:\n $ref: '#/components/schemas/Pet'\n"
}
}
'
Make sure to replace the following placeholders with your own values:
-
serviceName|Id
: Theid
orname
of the service the plugin configuration will target.
Make the following request:
curl -X POST https://{region}.api.konghq.com/v2/control-planes/{controlPlaneId}/core-entities/services/{serviceId}/plugins/ \
--header "accept: application/json" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $KONNECT_TOKEN" \
--data '
{
"name": "mocking",
"config": {
"api_specification": "openapi: 3.0.2\nservers:\n - url: /v3\ninfo:\n description: |-\n This is a sample Pet Store Server based on the OpenAPI 3.0 specification. You can find out more about\n Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!\n You can now help us improve the API whether it's by making changes to the definition itself or to the code.\n That way, with time, we can improve the API in general, and expose some of the new features in OAS3.\n Some useful links:\n - [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)\n - [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)\n version: 1.0.20-SNAPSHOT\n title: Swagger Petstore - OpenAPI 3.0\n termsOfService: 'http://swagger.io/terms/'\n contact:\n email: apiteam@swagger.io\n license:\n name: Apache 2.0\n url: 'http://www.apache.org/licenses/LICENSE-2.0.html'\ntags:\n - name: pet\n description: Everything about your Pets\n externalDocs:\n description: Find out more\n url: 'http://swagger.io'\n - name: store\n description: Access to Petstore orders\n externalDocs:\n description: Find out more about our store\n url: 'http://swagger.io'\n - name: user\n description: Operations about user\npaths:\n /pet:\n post:\n tags:\n - pet\n summary: Add a new pet to the store\n description: Add a new pet to the store\n operationId: addPet\n responses:\n '200':\n description: Successful operation\n content:\n application/xml:\n schema:\n $ref: '#/components/schemas/Pet'\n application/json:\n schema:\n $ref: '#/components/schemas/Pet'\n '405':\n description: Invalid input\n security:\n - petstore_auth:\n - 'write:pets'\n - 'read:pets'\n requestBody:\n description: Create a new pet in the store\n required: true\n content:\n application/json:\n schema:\n $ref: '#/components/schemas/Pet'\n application/xml:\n schema:\n $ref: '#/components/schemas/Pet'\n application/x-www-form-urlencoded:\n schema:\n $ref: '#/components/schemas/Pet'\n put:\n tags:\n - pet\n summary: Update an existing pet\n description: Update an existing pet by Id\n operationId: updatePet\n responses:\n '200':\n description: Successful operation\n content:\n application/xml:\n schema:\n $ref: '#/components/schemas/Pet'\n application/json:\n schema:\n $ref: '#/components/schemas/Pet'\n '400':\n description: Invalid ID supplied\n '404':\n description: Pet not found\n '405':\n description: Validation exception\n security:\n - petstore_auth:\n - 'write:pets'\n - 'read:pets'\n requestBody:\n description: Update an existent pet in the store\n required: true\n content:\n application/json:\n schema:\n $ref: '#/components/schemas/Pet'\n application/xml:\n schema:\n $ref: '#/components/schemas/Pet'\n application/x-www-form-urlencoded:\n schema:\n $ref: '#/components/schemas/Pet'\n"
}
}
'
Make sure to replace the following placeholders with your own values:
-
region
: Geographic region where your Kong Konnect is hosted and operates. -
controlPlaneId
: Theid
of the control plane. -
KONNECT_TOKEN
: Your Personal Access Token (PAT) associated with your Konnect account. -
serviceId
: Theid
of the service the plugin configuration will target.
See the Konnect API reference to learn about region-specific URLs and personal access tokens.
echo "
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: mocking
namespace: kong
annotations:
kubernetes.io/ingress.class: kong
config:
api_specification: |
openapi: 3.0.2
servers:
- url: /v3
info:
description: |-
This is a sample Pet Store Server based on the OpenAPI 3.0 specification. You can find out more about
Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!
You can now help us improve the API whether it's by making changes to the definition itself or to the code.
That way, with time, we can improve the API in general, and expose some of the new features in OAS3.
Some useful links:
- [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)
- [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)
version: 1.0.20-SNAPSHOT
title: Swagger Petstore - OpenAPI 3.0
termsOfService: 'http://swagger.io/terms/'
contact:
email: apiteam@swagger.io
license:
name: Apache 2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
tags:
- name: pet
description: Everything about your Pets
externalDocs:
description: Find out more
url: 'http://swagger.io'
- name: store
description: Access to Petstore orders
externalDocs:
description: Find out more about our store
url: 'http://swagger.io'
- name: user
description: Operations about user
paths:
/pet:
post:
tags:
- pet
summary: Add a new pet to the store
description: Add a new pet to the store
operationId: addPet
responses:
'200':
description: Successful operation
content:
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/json:
schema:
$ref: '#/components/schemas/Pet'
'405':
description: Invalid input
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
requestBody:
description: Create a new pet in the store
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/Pet'
put:
tags:
- pet
summary: Update an existing pet
description: Update an existing pet by Id
operationId: updatePet
responses:
'200':
description: Successful operation
content:
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/json:
schema:
$ref: '#/components/schemas/Pet'
'400':
description: Invalid ID supplied
'404':
description: Pet not found
'405':
description: Validation exception
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
requestBody:
description: Update an existent pet in the store
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/Pet'
plugin: mocking
" | kubectl apply -f -
Next, apply the KongPlugin
resource by annotating the service
resource:
kubectl annotate -n kong service SERVICE_NAME konghq.com/plugins=mocking
Prerequisite: Configure your Personal Access Token
terraform {
required_providers {
konnect = {
source = "kong/konnect"
}
}
}
provider "konnect" {
personal_access_token = "$KONNECT_TOKEN"
server_url = "https://us.api.konghq.com/"
}
Add the following to your Terraform configuration to create a Konnect Gateway Plugin:
resource "konnect_gateway_plugin_mocking" "my_mocking" {
enabled = true
config = {
api_specification = <<EOF
openapi: 3.0.2
servers:
- url: /v3
info:
description: |-
This is a sample Pet Store Server based on the OpenAPI 3.0 specification. You can find out more about
Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!
You can now help us improve the API whether it's by making changes to the definition itself or to the code.
That way, with time, we can improve the API in general, and expose some of the new features in OAS3.
Some useful links:
- [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)
- [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)
version: 1.0.20-SNAPSHOT
title: Swagger Petstore - OpenAPI 3.0
termsOfService: 'http://swagger.io/terms/'
contact:
email: apiteam@swagger.io
license:
name: Apache 2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
tags:
- name: pet
description: Everything about your Pets
externalDocs:
description: Find out more
url: 'http://swagger.io'
- name: store
description: Access to Petstore orders
externalDocs:
description: Find out more about our store
url: 'http://swagger.io'
- name: user
description: Operations about user
paths:
/pet:
post:
tags:
- pet
summary: Add a new pet to the store
description: Add a new pet to the store
operationId: addPet
responses:
'200':
description: Successful operation
content:
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/json:
schema:
$ref: '#/components/schemas/Pet'
'405':
description: Invalid input
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
requestBody:
description: Create a new pet in the store
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/Pet'
put:
tags:
- pet
summary: Update an existing pet
description: Update an existing pet by Id
operationId: updatePet
responses:
'200':
description: Successful operation
content:
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/json:
schema:
$ref: '#/components/schemas/Pet'
'400':
description: Invalid ID supplied
'404':
description: Pet not found
'405':
description: Validation exception
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
requestBody:
description: Update an existent pet in the store
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/Pet'
EOF
}
control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
service = {
id = konnect_gateway_service.my_service.id
}
}
Add this section to your declarative configuration file:
_format_version: "3.0"
plugins:
- name: mocking
route: routeName|Id
config:
api_specification: |
openapi: 3.0.2
servers:
- url: /v3
info:
description: |-
This is a sample Pet Store Server based on the OpenAPI 3.0 specification. You can find out more about
Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!
You can now help us improve the API whether it's by making changes to the definition itself or to the code.
That way, with time, we can improve the API in general, and expose some of the new features in OAS3.
Some useful links:
- [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)
- [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)
version: 1.0.20-SNAPSHOT
title: Swagger Petstore - OpenAPI 3.0
termsOfService: 'http://swagger.io/terms/'
contact:
email: apiteam@swagger.io
license:
name: Apache 2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
tags:
- name: pet
description: Everything about your Pets
externalDocs:
description: Find out more
url: 'http://swagger.io'
- name: store
description: Access to Petstore orders
externalDocs:
description: Find out more about our store
url: 'http://swagger.io'
- name: user
description: Operations about user
paths:
/pet:
post:
tags:
- pet
summary: Add a new pet to the store
description: Add a new pet to the store
operationId: addPet
responses:
'200':
description: Successful operation
content:
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/json:
schema:
$ref: '#/components/schemas/Pet'
'405':
description: Invalid input
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
requestBody:
description: Create a new pet in the store
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/Pet'
put:
tags:
- pet
summary: Update an existing pet
description: Update an existing pet by Id
operationId: updatePet
responses:
'200':
description: Successful operation
content:
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/json:
schema:
$ref: '#/components/schemas/Pet'
'400':
description: Invalid ID supplied
'404':
description: Pet not found
'405':
description: Validation exception
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
requestBody:
description: Update an existent pet in the store
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/Pet'
Make sure to replace the following placeholders with your own values:
-
routeName|Id
: Theid
orname
of the route the plugin configuration will target.
Make the following request:
curl -i -X POST http://localhost:8001/routes/{routeName|Id}/plugins/ \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--data '
{
"name": "mocking",
"config": {
"api_specification": "openapi: 3.0.2\nservers:\n - url: /v3\ninfo:\n description: |-\n This is a sample Pet Store Server based on the OpenAPI 3.0 specification. You can find out more about\n Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!\n You can now help us improve the API whether it's by making changes to the definition itself or to the code.\n That way, with time, we can improve the API in general, and expose some of the new features in OAS3.\n Some useful links:\n - [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)\n - [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)\n version: 1.0.20-SNAPSHOT\n title: Swagger Petstore - OpenAPI 3.0\n termsOfService: 'http://swagger.io/terms/'\n contact:\n email: apiteam@swagger.io\n license:\n name: Apache 2.0\n url: 'http://www.apache.org/licenses/LICENSE-2.0.html'\ntags:\n - name: pet\n description: Everything about your Pets\n externalDocs:\n description: Find out more\n url: 'http://swagger.io'\n - name: store\n description: Access to Petstore orders\n externalDocs:\n description: Find out more about our store\n url: 'http://swagger.io'\n - name: user\n description: Operations about user\npaths:\n /pet:\n post:\n tags:\n - pet\n summary: Add a new pet to the store\n description: Add a new pet to the store\n operationId: addPet\n responses:\n '200':\n description: Successful operation\n content:\n application/xml:\n schema:\n $ref: '#/components/schemas/Pet'\n application/json:\n schema:\n $ref: '#/components/schemas/Pet'\n '405':\n description: Invalid input\n security:\n - petstore_auth:\n - 'write:pets'\n - 'read:pets'\n requestBody:\n description: Create a new pet in the store\n required: true\n content:\n application/json:\n schema:\n $ref: '#/components/schemas/Pet'\n application/xml:\n schema:\n $ref: '#/components/schemas/Pet'\n application/x-www-form-urlencoded:\n schema:\n $ref: '#/components/schemas/Pet'\n put:\n tags:\n - pet\n summary: Update an existing pet\n description: Update an existing pet by Id\n operationId: updatePet\n responses:\n '200':\n description: Successful operation\n content:\n application/xml:\n schema:\n $ref: '#/components/schemas/Pet'\n application/json:\n schema:\n $ref: '#/components/schemas/Pet'\n '400':\n description: Invalid ID supplied\n '404':\n description: Pet not found\n '405':\n description: Validation exception\n security:\n - petstore_auth:\n - 'write:pets'\n - 'read:pets'\n requestBody:\n description: Update an existent pet in the store\n required: true\n content:\n application/json:\n schema:\n $ref: '#/components/schemas/Pet'\n application/xml:\n schema:\n $ref: '#/components/schemas/Pet'\n application/x-www-form-urlencoded:\n schema:\n $ref: '#/components/schemas/Pet'\n"
}
}
'
Make sure to replace the following placeholders with your own values:
-
routeName|Id
: Theid
orname
of the route the plugin configuration will target.
Make the following request:
curl -X POST https://{region}.api.konghq.com/v2/control-planes/{controlPlaneId}/core-entities/routes/{routeId}/plugins/ \
--header "accept: application/json" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $KONNECT_TOKEN" \
--data '
{
"name": "mocking",
"config": {
"api_specification": "openapi: 3.0.2\nservers:\n - url: /v3\ninfo:\n description: |-\n This is a sample Pet Store Server based on the OpenAPI 3.0 specification. You can find out more about\n Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!\n You can now help us improve the API whether it's by making changes to the definition itself or to the code.\n That way, with time, we can improve the API in general, and expose some of the new features in OAS3.\n Some useful links:\n - [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)\n - [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)\n version: 1.0.20-SNAPSHOT\n title: Swagger Petstore - OpenAPI 3.0\n termsOfService: 'http://swagger.io/terms/'\n contact:\n email: apiteam@swagger.io\n license:\n name: Apache 2.0\n url: 'http://www.apache.org/licenses/LICENSE-2.0.html'\ntags:\n - name: pet\n description: Everything about your Pets\n externalDocs:\n description: Find out more\n url: 'http://swagger.io'\n - name: store\n description: Access to Petstore orders\n externalDocs:\n description: Find out more about our store\n url: 'http://swagger.io'\n - name: user\n description: Operations about user\npaths:\n /pet:\n post:\n tags:\n - pet\n summary: Add a new pet to the store\n description: Add a new pet to the store\n operationId: addPet\n responses:\n '200':\n description: Successful operation\n content:\n application/xml:\n schema:\n $ref: '#/components/schemas/Pet'\n application/json:\n schema:\n $ref: '#/components/schemas/Pet'\n '405':\n description: Invalid input\n security:\n - petstore_auth:\n - 'write:pets'\n - 'read:pets'\n requestBody:\n description: Create a new pet in the store\n required: true\n content:\n application/json:\n schema:\n $ref: '#/components/schemas/Pet'\n application/xml:\n schema:\n $ref: '#/components/schemas/Pet'\n application/x-www-form-urlencoded:\n schema:\n $ref: '#/components/schemas/Pet'\n put:\n tags:\n - pet\n summary: Update an existing pet\n description: Update an existing pet by Id\n operationId: updatePet\n responses:\n '200':\n description: Successful operation\n content:\n application/xml:\n schema:\n $ref: '#/components/schemas/Pet'\n application/json:\n schema:\n $ref: '#/components/schemas/Pet'\n '400':\n description: Invalid ID supplied\n '404':\n description: Pet not found\n '405':\n description: Validation exception\n security:\n - petstore_auth:\n - 'write:pets'\n - 'read:pets'\n requestBody:\n description: Update an existent pet in the store\n required: true\n content:\n application/json:\n schema:\n $ref: '#/components/schemas/Pet'\n application/xml:\n schema:\n $ref: '#/components/schemas/Pet'\n application/x-www-form-urlencoded:\n schema:\n $ref: '#/components/schemas/Pet'\n"
}
}
'
Make sure to replace the following placeholders with your own values:
-
region
: Geographic region where your Kong Konnect is hosted and operates. -
controlPlaneId
: Theid
of the control plane. -
KONNECT_TOKEN
: Your Personal Access Token (PAT) associated with your Konnect account. -
routeId
: Theid
of the route the plugin configuration will target.
See the Konnect API reference to learn about region-specific URLs and personal access tokens.
echo "
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: mocking
namespace: kong
annotations:
kubernetes.io/ingress.class: kong
config:
api_specification: |
openapi: 3.0.2
servers:
- url: /v3
info:
description: |-
This is a sample Pet Store Server based on the OpenAPI 3.0 specification. You can find out more about
Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!
You can now help us improve the API whether it's by making changes to the definition itself or to the code.
That way, with time, we can improve the API in general, and expose some of the new features in OAS3.
Some useful links:
- [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)
- [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)
version: 1.0.20-SNAPSHOT
title: Swagger Petstore - OpenAPI 3.0
termsOfService: 'http://swagger.io/terms/'
contact:
email: apiteam@swagger.io
license:
name: Apache 2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
tags:
- name: pet
description: Everything about your Pets
externalDocs:
description: Find out more
url: 'http://swagger.io'
- name: store
description: Access to Petstore orders
externalDocs:
description: Find out more about our store
url: 'http://swagger.io'
- name: user
description: Operations about user
paths:
/pet:
post:
tags:
- pet
summary: Add a new pet to the store
description: Add a new pet to the store
operationId: addPet
responses:
'200':
description: Successful operation
content:
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/json:
schema:
$ref: '#/components/schemas/Pet'
'405':
description: Invalid input
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
requestBody:
description: Create a new pet in the store
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/Pet'
put:
tags:
- pet
summary: Update an existing pet
description: Update an existing pet by Id
operationId: updatePet
responses:
'200':
description: Successful operation
content:
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/json:
schema:
$ref: '#/components/schemas/Pet'
'400':
description: Invalid ID supplied
'404':
description: Pet not found
'405':
description: Validation exception
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
requestBody:
description: Update an existent pet in the store
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/Pet'
plugin: mocking
" | kubectl apply -f -
Next, apply the KongPlugin
resource by annotating the httproute
or ingress
resource:
kubectl annotate -n kong httproute konghq.com/plugins=mocking
kubectl annotate -n kong ingress konghq.com/plugins=mocking
Prerequisite: Configure your Personal Access Token
terraform {
required_providers {
konnect = {
source = "kong/konnect"
}
}
}
provider "konnect" {
personal_access_token = "$KONNECT_TOKEN"
server_url = "https://us.api.konghq.com/"
}
Add the following to your Terraform configuration to create a Konnect Gateway Plugin:
resource "konnect_gateway_plugin_mocking" "my_mocking" {
enabled = true
config = {
api_specification = <<EOF
openapi: 3.0.2
servers:
- url: /v3
info:
description: |-
This is a sample Pet Store Server based on the OpenAPI 3.0 specification. You can find out more about
Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!
You can now help us improve the API whether it's by making changes to the definition itself or to the code.
That way, with time, we can improve the API in general, and expose some of the new features in OAS3.
Some useful links:
- [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)
- [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)
version: 1.0.20-SNAPSHOT
title: Swagger Petstore - OpenAPI 3.0
termsOfService: 'http://swagger.io/terms/'
contact:
email: apiteam@swagger.io
license:
name: Apache 2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
tags:
- name: pet
description: Everything about your Pets
externalDocs:
description: Find out more
url: 'http://swagger.io'
- name: store
description: Access to Petstore orders
externalDocs:
description: Find out more about our store
url: 'http://swagger.io'
- name: user
description: Operations about user
paths:
/pet:
post:
tags:
- pet
summary: Add a new pet to the store
description: Add a new pet to the store
operationId: addPet
responses:
'200':
description: Successful operation
content:
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/json:
schema:
$ref: '#/components/schemas/Pet'
'405':
description: Invalid input
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
requestBody:
description: Create a new pet in the store
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/Pet'
put:
tags:
- pet
summary: Update an existing pet
description: Update an existing pet by Id
operationId: updatePet
responses:
'200':
description: Successful operation
content:
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/json:
schema:
$ref: '#/components/schemas/Pet'
'400':
description: Invalid ID supplied
'404':
description: Pet not found
'405':
description: Validation exception
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
requestBody:
description: Update an existent pet in the store
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/Pet'
EOF
}
control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
route = {
id = konnect_gateway_route.my_route.id
}
}
Add this section to your declarative configuration file:
_format_version: "3.0"
plugins:
- name: mocking
consumer: consumerName|Id
config:
api_specification: |
openapi: 3.0.2
servers:
- url: /v3
info:
description: |-
This is a sample Pet Store Server based on the OpenAPI 3.0 specification. You can find out more about
Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!
You can now help us improve the API whether it's by making changes to the definition itself or to the code.
That way, with time, we can improve the API in general, and expose some of the new features in OAS3.
Some useful links:
- [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)
- [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)
version: 1.0.20-SNAPSHOT
title: Swagger Petstore - OpenAPI 3.0
termsOfService: 'http://swagger.io/terms/'
contact:
email: apiteam@swagger.io
license:
name: Apache 2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
tags:
- name: pet
description: Everything about your Pets
externalDocs:
description: Find out more
url: 'http://swagger.io'
- name: store
description: Access to Petstore orders
externalDocs:
description: Find out more about our store
url: 'http://swagger.io'
- name: user
description: Operations about user
paths:
/pet:
post:
tags:
- pet
summary: Add a new pet to the store
description: Add a new pet to the store
operationId: addPet
responses:
'200':
description: Successful operation
content:
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/json:
schema:
$ref: '#/components/schemas/Pet'
'405':
description: Invalid input
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
requestBody:
description: Create a new pet in the store
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/Pet'
put:
tags:
- pet
summary: Update an existing pet
description: Update an existing pet by Id
operationId: updatePet
responses:
'200':
description: Successful operation
content:
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/json:
schema:
$ref: '#/components/schemas/Pet'
'400':
description: Invalid ID supplied
'404':
description: Pet not found
'405':
description: Validation exception
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
requestBody:
description: Update an existent pet in the store
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/Pet'
Make sure to replace the following placeholders with your own values:
-
consumerName|Id
: Theid
orname
of the consumer the plugin configuration will target.
Make the following request:
curl -i -X POST http://localhost:8001/consumers/{consumerName|Id}/plugins/ \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--data '
{
"name": "mocking",
"config": {
"api_specification": "openapi: 3.0.2\nservers:\n - url: /v3\ninfo:\n description: |-\n This is a sample Pet Store Server based on the OpenAPI 3.0 specification. You can find out more about\n Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!\n You can now help us improve the API whether it's by making changes to the definition itself or to the code.\n That way, with time, we can improve the API in general, and expose some of the new features in OAS3.\n Some useful links:\n - [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)\n - [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)\n version: 1.0.20-SNAPSHOT\n title: Swagger Petstore - OpenAPI 3.0\n termsOfService: 'http://swagger.io/terms/'\n contact:\n email: apiteam@swagger.io\n license:\n name: Apache 2.0\n url: 'http://www.apache.org/licenses/LICENSE-2.0.html'\ntags:\n - name: pet\n description: Everything about your Pets\n externalDocs:\n description: Find out more\n url: 'http://swagger.io'\n - name: store\n description: Access to Petstore orders\n externalDocs:\n description: Find out more about our store\n url: 'http://swagger.io'\n - name: user\n description: Operations about user\npaths:\n /pet:\n post:\n tags:\n - pet\n summary: Add a new pet to the store\n description: Add a new pet to the store\n operationId: addPet\n responses:\n '200':\n description: Successful operation\n content:\n application/xml:\n schema:\n $ref: '#/components/schemas/Pet'\n application/json:\n schema:\n $ref: '#/components/schemas/Pet'\n '405':\n description: Invalid input\n security:\n - petstore_auth:\n - 'write:pets'\n - 'read:pets'\n requestBody:\n description: Create a new pet in the store\n required: true\n content:\n application/json:\n schema:\n $ref: '#/components/schemas/Pet'\n application/xml:\n schema:\n $ref: '#/components/schemas/Pet'\n application/x-www-form-urlencoded:\n schema:\n $ref: '#/components/schemas/Pet'\n put:\n tags:\n - pet\n summary: Update an existing pet\n description: Update an existing pet by Id\n operationId: updatePet\n responses:\n '200':\n description: Successful operation\n content:\n application/xml:\n schema:\n $ref: '#/components/schemas/Pet'\n application/json:\n schema:\n $ref: '#/components/schemas/Pet'\n '400':\n description: Invalid ID supplied\n '404':\n description: Pet not found\n '405':\n description: Validation exception\n security:\n - petstore_auth:\n - 'write:pets'\n - 'read:pets'\n requestBody:\n description: Update an existent pet in the store\n required: true\n content:\n application/json:\n schema:\n $ref: '#/components/schemas/Pet'\n application/xml:\n schema:\n $ref: '#/components/schemas/Pet'\n application/x-www-form-urlencoded:\n schema:\n $ref: '#/components/schemas/Pet'\n"
}
}
'
Make sure to replace the following placeholders with your own values:
-
consumerName|Id
: Theid
orname
of the consumer the plugin configuration will target.
Make the following request:
curl -X POST https://{region}.api.konghq.com/v2/control-planes/{controlPlaneId}/core-entities/consumers/{consumerId}/plugins/ \
--header "accept: application/json" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $KONNECT_TOKEN" \
--data '
{
"name": "mocking",
"config": {
"api_specification": "openapi: 3.0.2\nservers:\n - url: /v3\ninfo:\n description: |-\n This is a sample Pet Store Server based on the OpenAPI 3.0 specification. You can find out more about\n Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!\n You can now help us improve the API whether it's by making changes to the definition itself or to the code.\n That way, with time, we can improve the API in general, and expose some of the new features in OAS3.\n Some useful links:\n - [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)\n - [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)\n version: 1.0.20-SNAPSHOT\n title: Swagger Petstore - OpenAPI 3.0\n termsOfService: 'http://swagger.io/terms/'\n contact:\n email: apiteam@swagger.io\n license:\n name: Apache 2.0\n url: 'http://www.apache.org/licenses/LICENSE-2.0.html'\ntags:\n - name: pet\n description: Everything about your Pets\n externalDocs:\n description: Find out more\n url: 'http://swagger.io'\n - name: store\n description: Access to Petstore orders\n externalDocs:\n description: Find out more about our store\n url: 'http://swagger.io'\n - name: user\n description: Operations about user\npaths:\n /pet:\n post:\n tags:\n - pet\n summary: Add a new pet to the store\n description: Add a new pet to the store\n operationId: addPet\n responses:\n '200':\n description: Successful operation\n content:\n application/xml:\n schema:\n $ref: '#/components/schemas/Pet'\n application/json:\n schema:\n $ref: '#/components/schemas/Pet'\n '405':\n description: Invalid input\n security:\n - petstore_auth:\n - 'write:pets'\n - 'read:pets'\n requestBody:\n description: Create a new pet in the store\n required: true\n content:\n application/json:\n schema:\n $ref: '#/components/schemas/Pet'\n application/xml:\n schema:\n $ref: '#/components/schemas/Pet'\n application/x-www-form-urlencoded:\n schema:\n $ref: '#/components/schemas/Pet'\n put:\n tags:\n - pet\n summary: Update an existing pet\n description: Update an existing pet by Id\n operationId: updatePet\n responses:\n '200':\n description: Successful operation\n content:\n application/xml:\n schema:\n $ref: '#/components/schemas/Pet'\n application/json:\n schema:\n $ref: '#/components/schemas/Pet'\n '400':\n description: Invalid ID supplied\n '404':\n description: Pet not found\n '405':\n description: Validation exception\n security:\n - petstore_auth:\n - 'write:pets'\n - 'read:pets'\n requestBody:\n description: Update an existent pet in the store\n required: true\n content:\n application/json:\n schema:\n $ref: '#/components/schemas/Pet'\n application/xml:\n schema:\n $ref: '#/components/schemas/Pet'\n application/x-www-form-urlencoded:\n schema:\n $ref: '#/components/schemas/Pet'\n"
}
}
'
Make sure to replace the following placeholders with your own values:
-
region
: Geographic region where your Kong Konnect is hosted and operates. -
controlPlaneId
: Theid
of the control plane. -
KONNECT_TOKEN
: Your Personal Access Token (PAT) associated with your Konnect account. -
consumerId
: Theid
of the consumer the plugin configuration will target.
See the Konnect API reference to learn about region-specific URLs and personal access tokens.
echo "
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: mocking
namespace: kong
annotations:
kubernetes.io/ingress.class: kong
config:
api_specification: |
openapi: 3.0.2
servers:
- url: /v3
info:
description: |-
This is a sample Pet Store Server based on the OpenAPI 3.0 specification. You can find out more about
Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!
You can now help us improve the API whether it's by making changes to the definition itself or to the code.
That way, with time, we can improve the API in general, and expose some of the new features in OAS3.
Some useful links:
- [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)
- [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)
version: 1.0.20-SNAPSHOT
title: Swagger Petstore - OpenAPI 3.0
termsOfService: 'http://swagger.io/terms/'
contact:
email: apiteam@swagger.io
license:
name: Apache 2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
tags:
- name: pet
description: Everything about your Pets
externalDocs:
description: Find out more
url: 'http://swagger.io'
- name: store
description: Access to Petstore orders
externalDocs:
description: Find out more about our store
url: 'http://swagger.io'
- name: user
description: Operations about user
paths:
/pet:
post:
tags:
- pet
summary: Add a new pet to the store
description: Add a new pet to the store
operationId: addPet
responses:
'200':
description: Successful operation
content:
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/json:
schema:
$ref: '#/components/schemas/Pet'
'405':
description: Invalid input
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
requestBody:
description: Create a new pet in the store
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/Pet'
put:
tags:
- pet
summary: Update an existing pet
description: Update an existing pet by Id
operationId: updatePet
responses:
'200':
description: Successful operation
content:
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/json:
schema:
$ref: '#/components/schemas/Pet'
'400':
description: Invalid ID supplied
'404':
description: Pet not found
'405':
description: Validation exception
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
requestBody:
description: Update an existent pet in the store
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/Pet'
plugin: mocking
" | kubectl apply -f -
Next, apply the KongPlugin
resource by annotating the KongConsumer
resource:
kubectl annotate -n kong CONSUMER_NAME konghq.com/plugins=mocking
Prerequisite: Configure your Personal Access Token
terraform {
required_providers {
konnect = {
source = "kong/konnect"
}
}
}
provider "konnect" {
personal_access_token = "$KONNECT_TOKEN"
server_url = "https://us.api.konghq.com/"
}
Add the following to your Terraform configuration to create a Konnect Gateway Plugin:
resource "konnect_gateway_plugin_mocking" "my_mocking" {
enabled = true
config = {
api_specification = <<EOF
openapi: 3.0.2
servers:
- url: /v3
info:
description: |-
This is a sample Pet Store Server based on the OpenAPI 3.0 specification. You can find out more about
Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!
You can now help us improve the API whether it's by making changes to the definition itself or to the code.
That way, with time, we can improve the API in general, and expose some of the new features in OAS3.
Some useful links:
- [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)
- [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)
version: 1.0.20-SNAPSHOT
title: Swagger Petstore - OpenAPI 3.0
termsOfService: 'http://swagger.io/terms/'
contact:
email: apiteam@swagger.io
license:
name: Apache 2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
tags:
- name: pet
description: Everything about your Pets
externalDocs:
description: Find out more
url: 'http://swagger.io'
- name: store
description: Access to Petstore orders
externalDocs:
description: Find out more about our store
url: 'http://swagger.io'
- name: user
description: Operations about user
paths:
/pet:
post:
tags:
- pet
summary: Add a new pet to the store
description: Add a new pet to the store
operationId: addPet
responses:
'200':
description: Successful operation
content:
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/json:
schema:
$ref: '#/components/schemas/Pet'
'405':
description: Invalid input
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
requestBody:
description: Create a new pet in the store
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/Pet'
put:
tags:
- pet
summary: Update an existing pet
description: Update an existing pet by Id
operationId: updatePet
responses:
'200':
description: Successful operation
content:
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/json:
schema:
$ref: '#/components/schemas/Pet'
'400':
description: Invalid ID supplied
'404':
description: Pet not found
'405':
description: Validation exception
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
requestBody:
description: Update an existent pet in the store
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
application/xml:
schema:
$ref: '#/components/schemas/Pet'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/Pet'
EOF
}
control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
consumer = {
id = konnect_gateway_consumer.my_consumer.id
}
}