Import and map SwaggerHub resources in Service Catalog
Install the SwaggerHub integration in Konnect and authorize using your SwaggerHub API key. Create a Service Catalog service and associate it with your SwaggerHub API versions to display metadata and enable event tracking.
Prerequisites
Kong Konnect
If you don’t have a Konnect account, you can get started quickly with our onboarding wizard.
- The following Konnect items are required to complete this tutorial:
- Personal access token (PAT): Create a new personal access token by opening the Konnect PAT page and selecting Generate Token.
-
Set the personal access token as an environment variable:
export KONNECT_TOKEN='YOUR KONNECT TOKEN'
Konnect roles
You need the Integration Admin role in Konnect to install and authorize Service Catalog integrations.
SwaggerHub API key
You must have a SwaggerHub API key to authenticate your SwaggerHub account with Konnect. Export it as an environment variable:
export SWAGGERHUB_API_KEY='YOUR-API-KEY'
Additionally, you’ll need an API version in SwaggerHub to pull into Konnect as a resource.
Install and authorize the SwaggerHub integration
Before you can ingest resources from SwaggerHub, you must first install and authorize the SwaggerHub integration.
First, install the SwaggerHub integration:
curl -X POST "https://us.api.konghq.com/v1/integration-instances" \
-H "Authorization: Bearer $KONNECT_TOKEN" \
--json '{
"integration_name": "swaggerhub",
"name": "swaggerhub",
"display_name": "SwaggerHub",
"config": {}
}'
Export the ID of your SwaggerHub integration:
export SWAGGERHUB_INTEGRATION_ID='YOUR-INTEGRATION-ID'
Next, authorize the SwaggerHub integration with your SwaggerHub API key:
curl -X POST "https://us.api.konghq.com/v1/integration-instances/$SWAGGERHUB_INTEGRATION_ID/auth-credential" \
-H "Authorization: Bearer $KONNECT_TOKEN" \
--json '{
"type": "multi_key_auth",
"config": {
"headers": [
{
"name": "authorization",
"key": "'$SWAGGERHUB_API_KEY'"
}
]
}
}'
Once authorized, resources from your SwaggerHub account will be discoverable in the UI.
Create a service in Service Catalog
Create a service that you’ll map to your SwaggerHub resources:
curl -X POST "https://us.api.konghq.com/v1/catalog-services" \
-H "Authorization: Bearer $KONNECT_TOKEN" \
--json '{
"name": "billing",
"display_name": "Billing Service"
}'
Export the service ID:
export SWAGGERHUB_SERVICE_ID='YOUR-SERVICE-ID'
List SwaggerHub resources
Before you can map your SwaggerHub resources to a service in Service Catalog, you first need to find the resources that are pulled in from SwaggerHub:
curl -X GET "https://us.api.konghq.com/v1/resources?filter%5Bintegration.name%5D=swaggerhub" \
-H "Authorization: Bearer $KONNECT_TOKEN"
You might need to manually sync your SwaggerHub integration for resources to appear. From the Konnect UI by navigating to the SwaggerHub integration you just installed and selecting Sync Now from the Actions dropdown menu.
Export the resource ID you want to map to the service:
export SWAGGERHUB_RESOURCE_ID='YOUR-RESOURCE-ID'
Map resources to a service
Now, you can map the SwaggerHub resource to the service:
curl -X POST "https://us.api.konghq.com/v1/resource-mappings" \
-H "Authorization: Bearer $KONNECT_TOKEN" \
--json '{
"service": "billing",
"resource": "'$SWAGGERHUB_RESOURCE_ID'"
}'
Validate the mapping
To confirm that the SwaggerHub resource is now mapped to the intended service, list the service’s mapped resources:
curl -X GET "https://us.api.konghq.com/v1/catalog-services/$SWAGGERHUB_SERVICE_ID/resources" \
-H "Authorization: Bearer $KONNECT_TOKEN"