Bookmark this page

Importing OpenAPI Definitions

Objectives

After completing this section, you should be able to import OpenAPI standard API definitions into Red Hat 3scale API Management.

Introducing the OpenAPI Specification.

The OpenAPI Specification (OAS) is a way of describing REST APIs. It is an open source specification based on the Swagger Specification.

It offers the following benefits:

  • It provides a standard for documenting your APIs.

  • It allows API consumers to interact with your API from the documentation, for example for testing purposes.

  • It does not require any binding to a programming language or a programming framework.

  • It offers a way to generate clients and servers that comply with the OAS you define.

The OAS definition supports both YAML and JSON formats.

This specification is used by Red Hat 3scale API Management to provide interactive documentation for the Developer Portal. In 3scale API Management the OAS integration is called ActiveDocs.

Creating ActiveDocs with OAS Definitions

You can manage your ActiveDocs definitions either by using the Admin Portal or the 3scale Toolbox CLI.

Also, by using the 3scale Toolbox CLI and the import command you can generate all the 3scale API Management objects needed to create an application based on the OAS definition.

Creating ActiveDocs from the Admin Portal

You can create an ActiveDocs object either from the Audience page or from a product page. If you create the ActiveDocs from a product page then the ActiveDocs are assigned to that product.

To select any product for the OAS definition, create the ActiveDocs from the Audience page. For this you must navigate to Developer Portal>ActiveDocs, click Create a new spec, and complete the ActiveDocs form.

Managing ActiveDocs by Using the 3scale Toolbox CLI

The 3scale Toolbox CLI has the activedocs command, which offers several subcommands to manage ActiveDocs objects.

[user@host ~]$ 3scale activedocs -h
NAME
    activedocs - activedocs super command

USAGE
    3scale activedocs <sub-command> [options]

DESCRIPTION
    Manage your ActiveDocs

SUBCOMMANDS
    apply      Update activedocs
    create     Create an ActiveDocs
    delete     Delete an ActiveDocs
    list       List ActiveDocs

All these subcommands affect ActiveDocs objects exclusively. For example, you can use the delete subcommand as a way to delete ActiveDocs objects.

[user@host ~]$ 3scale activedocs delete \
  REMOTE \ 1
  ACTIVE_DOCS 2

1

The target tenant.

2

ID or system name of the ActiveDocs to delete.

Importing ActiveDocs from the 3scale Toolbox CLI

The 3scale Toolbox CLI offers a different way of creating ActiveDocs by importing the OAS definition. For this, you must use the import command and the openapi subcommand. You can get the OAS definition either from a file or from a URL.

This operation does more than creating the ActiveDocs object. It generates many 3scale API Management objects based on the OAS definition file. It creates:

  • A product with a name taken from the title attribute in the OAS file.

  • A backend with a name taken from the title attribute and a backend URL taken from the servers section in the OAS file.

  • Mapping rules and methods based on the paths section from the OAS file.

This is an example command with some of the available options:

[user@host ~]$ 3scale import openapi \
  --target_system_name=SYSTEM_NAME \ 1
  --destination=REMOTE \ 2
  --default-credentials-userkey=ANONYMOUS_KEY 3
  OAS_FILE 4

1

This is the system name that is used as the system name for the product, the backend and the ActiveDocs objects.

2

The target tenant.

3

This option adds an Anonymous Access policy. The value provided here is used for unauthenticated endpoints.

4

The OAS file in JSON or YAML. This option also accepts a URL that returns the OAS definition.

After executing this command you must create an application plan and an application to make your API public.

To use the ActiveDocs interactive documentation you must add a CORS Request Handling policy and set the allow_origin to the Developer Portal domain. The reason for this is that the ActiveDocs request is sent from the Developer Portal domain, which is different from your API domain. When the domain from where the request is originated differs from the domain serving the request, the browser blocks the call unless you configure APIcast to allow it.

 

References

For more information, refer to the How to write an OpenAPI document for use as a 3scale OpenAPI spec chapter in the Red Hat 3scale API Management Providing APIs in the Developer Portal at https://access.redhat.com/documentation/en-us/red_hat_3scale_api_management/2.11/html/providing_apis_in_the_developer_portal/how-to-write-an-openapi-document-for-use-as-a-threescale-openapi-spec_creating-a-new-service-based-on-oas

OpenAPI Specification

Revision: do240-2.11-40390f6