Skip to main content
Version: v2.x

Import Action from OpenAPI Spec

Available on: Cloud, Enterprise Edition

Overview

The most common use case for Actions is to expose an existing API as a GraphQL query. To make this easier, we have added the ability to import an Action from an OpenAPI spec. OpenAPI is a widely used standard for describing REST APIs, and many APIs already have an OpenAPI spec available. This feature allows you to upload an OpenAPI spec, select the operation you want to expose as an Action, and Hasura will automatically prepopulate the Action definition for you.

Import Action from OpenAPI Spec availability

The Import Action from OpenAPI Spec feature is currently available in alpha for all Hasura Cloud offerings and for Hasura Enterprise Edition (EE) customers. Once it is generally available (GA), it will be available only for Hasura Cloud Enterprise and EE customers.

Enabling the feature

While the Import Action from OpenAPI Spec is in alpha, the feature can only be enabled by turning on the Import from OpenAPI under the Feature Flags section of the Console configuration page.

Click the gear icon (1) in the top-right corner of your Cloud project; in the side navigation, click "Feature Flags" (2); finally, toggle the "Import Action from OpenAPI" switch to enable (3).

Turning on experimental features.

Importing an Action from an OpenAPI spec

After enabling the feature, you can import an Action from an OpenAPI spec by clicking the "Create" button from the Actions page of the Console. You should see a new option to Import from OpenAPI, click this to start the import:

Turning on experimental features.

Either select a file (YAML or JSON) or paste the contents of an OpenAPI spec into the text box. Then, select an endpoint and click Generate Action:

Turning on experimental features.

From the Actions page, you can further customize the Action definition, and then click "Create" to create the Action:

Turning on experimental features.

You can now use this imported Action in your GraphQL API!