Create an API from an Open API Definition¶
An OpenAPI definition is a format that describes REST APIs.
Follow the instructions below to create a REST API using an Open API definition for an existing API.
Create an API using the basic flow¶
-
Sign in to the WSO2 API Publisher.
https://<hostname>:9443/publisher
(e.g.,https://localhost:9443/publisher
).Note
The CREATE API button will only appear if the user who has signed in has the creator role permission.
-
Click CREATE API and then click I have an existing REST API.
-
Select one of the following options:
- OpenAPI URL - If you select this option, you need to provide an endpoint URL.
- OpenAPI Archive/File - If you select this option, click Browse and upload either an individual Open API definition or an archive that has an Open API definition with external file references.
Note
You need to upload an archive if you have remote references in your API definition. If it is a single Swagger file without remote references it can be imported directly, without zipping. When uploading an OpenAPI archive, the master Swagger file should be named as swagger.yaml/swagger.json. If not, the validation will fail at the point of API creation. Referenced files can be named independently.
Tip
The Swagger definitions should be placed under one root folder and zipped.
Sample folder structures
-masterFolder ---Swagger.json ---reference.json ---add.json
-masterFolder ---Swagger.json ---schemes ---pet.json ---add.json
In the above sample, every Swagger definition is placed inside one root folder namely
masterFolder
. -
Select OpenAPI URL and provide
http://petstore.swagger.io/v2/swagger.json
as the URL. Click NEXT. -
Edit the information as given below and click CREATE.
Field Sample value Name SwaggerPetstore Context /v2 Version 1.0.5 The Petstore API overview page appears.
Resources¶
Click Resources to navigate to the resources page.
You will notice that all the API resources are created automatically when the OpenAPI URL is specified.
API Definition¶
-
Click API Definition and click Edit to remove the security headers.
This is required to invoke the API in the Developer Portal using the OpenAPI UI.
-
Remove the
petstore_auth
tag related configuration that appears under thesecurity
tag from the/pet
POST resource given below.Note
Do not remove the
default
tag related configuration that appears under thesecurity
tag.OpenAPI - Post resource
security: - petstore_auth: - 'write:pets' - 'read:pets' - default: - 'write:pets' - 'read:pets'
-
Remove the security
pet/{petId}
GET resource given below:OpenAPI - Get resource
4. After removing the security tags, click Update Contents to save the changes.//remove the following code snippet security: - api_key: []
Enpoints¶
-
Navigate to the Endpoints page.
-
Enter the information shown below.
Field Sample value Endpoint type HTTP/REST endpoint Production endpoint http://petstore.swagger.io/v2/ Sandbox endpoint Let's only work with the production endpoint for this sample. Therefore, uncheck the sandbox endpoint option. -
Click SAVE.
Runtime Configuration¶
Click Runtime Configuration to navigate to the runtime configurations that correspond to the API.
The Transport Level Security defines the transport protocol on which the API is exposed.
Note
Both HTTP and HTTPS transports are selected by default. It is able to limit the API availability to only one transport (e.g., HTTPS) by clearing the checkbox of the other transport.
Note
Transport Level Security defines the transport protocol on which the API is exposed. When creating a new API by using a Swagger or Open API definition, these transport security schemes can be defined using “x-wso2- transports”and "x-wso2-mutual-ssl”extensions.
x-wso2-mutual-ssl: "optional"
x-wso2-transports:
- "https"
- “http”
Subscriptions¶
-
Click Subscriptions.
-
Select Gold and Silver as the Bussiness plans.
Note
The API can be available at different levels of the service. They allow you to limit the number of successful hits to an API during a given period of time.
-
Click SAVE
Now, a REST API from an Open API Definition has been created and configured successfully.
Next, publish the API, for more information, see Publish an API.
Top