Skip to main content

Ingest Swagger paths from swagger.json file into your catalog

The following example shows you how to create a swaggerPath blueprint that ingests all API paths in your swagger.json file using Port's GitHub file ingesting feature.

To ingest the packages to Port, the GitHub integration is used.

Prerequisites

This guide assumes:

  • You have a Port account
  • You have installed Port's GitHub app in your organisation or in repositories you are interested in.

GitHub configuration

To ingest GitHub objects, use one of the following methods:

To manage your GitHub integration configuration using Port:

  1. Go to the data sources page of your portal.
  2. Under Exporters, click on your desired GitHub organization.
  3. A window will open containing the default YAML configuration of your GitHub integration.
  4. Here you can modify the configuration to suit your needs, by adding/removing entries.
  5. When finished, click resync to apply any changes.

Using this method applies the configuration to all repositories that the GitHub app has permissions to.

When configuring the integration using Port, the YAML configuration is global, allowing you to specify mappings for multiple Port blueprints.

Important

When using Port's UI, the specified configuration will override any port-app-config.yml file in your GitHub repository/ies.

Setting up the blueprint and mapping configuration

Create the following blueprint definition and mapping configuration:

Swagger path blueprint
{
"identifier": "swaggerPath",
"description": "This blueprint represents a Swagger path in our software catalog",
"title": "Swagger API Paths",
"icon": "Swagger",
"schema": {
"properties": {
"method": {
"type": "string",
"title": "Method",
"default": "get",
"enum": ["get", "post", "delete", "put", "patch"],
"enumColors": {
"get": "yellow",
"post": "green",
"delete": "red",
"put": "purple",
"patch": "purple"
}
},
"host": {
"type": "string",
"title": "API Base URL",
"format": "url"
},
"path": {
"title": "Path",
"type": "string"
},
"parameters": {
"items": {
"type": "object"
},
"title": "Parameters",
"type": "array"
},
"responses": {
"title": "Responses",
"type": "object"
},
"description": {
"title": "Description",
"type": "string"
},
"version": {
"title": "Version",
"type": "string"
},
"summary": {
"title": "Summary",
"type": "string"
}
},
"required": []
},
"mirrorProperties": {},
"calculationProperties": {},
"relations": {}
}
Swagger path mapping configuration
resources:
- kind: file
selector:
query: 'true'
files:
- path: '**/swagger.json' # or .yaml

port:
itemsToParse: '[. as $root | .paths | to_entries[] as $entries | {version: $root.info.version, host: $root.host, base_path: $root.basePath, title: $root.info.title, path: $entries.key, methods: ($entries.value | to_entries[] as $inner | {method: ($inner.key), rest: $inner.value, path: $entries.key})}][] | {id: .title + "-" + .path + .methods.method, path, method: .methods.method, summary: .methods.rest.summary, description: .methods.rest.description, parameters: .methods.rest.parameters, responses: .methods.rest.responses, project: .title, version, host: "https://" + .host + .base_path}'
entity:
mappings:
identifier: '.item.id | sub("[^A-Za-z0-9@_.:/=-]"; "-"; "g")'
title: .item.method + .item.path
blueprint: '"swaggerPath"'
properties:
method: .item.method
host: .item.host
path: .item.path
parameters: .item.parameters
responses: .item.responses
description: .item.description
version: .item.version
summary: .item.summary
relations: {}

Then click on Resync and wait for the entities to be ingested in your Port environment.