Open API Specification 3.0 Support

Learn how to design and manage APIs using the Open API Specification 3.0.

API Platform Version: 2019.0.0

Table of Contents

Working with OpenAPI 3.0:
  1. Open API 3.0 support: Overview
  2. How do I design my API from scratch in OAS 3.0?
  3. How do I edit my API design in OAS 3.0?
  4. Using the JSON Text Editor
JSON Schema Editor:
  1. Overview
  2. Adding and editing model objects in OAS 3.0
  3. How do I access the JSON Schema Editor?
  4. Using the JSON Schema Editor
  5. What validations can I add to model object properties in the JSON Schema Editor?
  6. How do I define a $ref reference to another model in the JSON Schema Editor?

Working with OpenAPI 3.0:

Open API 3.0 support: Overview

With version 2019.0.0, the Akana API Platform supports OpenAPI version 3.0 (OAS 3.0) for creating and updating API definitions.

You can define an OAS 3.0 document by:

Once you have the basic API definition in place, you can edit it in any of these ways:

Some of the features of OAS 3.0 that are improvements from Swagger 2.0:

  • The ability to define a response for each HTTP code/media type combination. For example, you can define an HTTP 200 (successful response) message for each Accept media type.
  • Support includes an OAS Schema Form Editor, which is a graphical and text editor for authoring and editing Open API Specification v3 documents. The editor supports syntax and semantic validation on save or switch between text and graphical view, as well as code completion and syntax highlighting. The API Designer also supports dynamic switching between OAS 3.0 and other formats.

Back to top

How do I design my API from scratch in OAS 3.0?

Follow the instructions for adding an API, providing the API name and clicking Save. For full instructions, see How do I add an API?

To design an OAS 3.0 API from scratch
  1. Click the plus sign (+) in the middle of the top menu bar, and choose Add a New API.
  2. Optional: click the advanced options icon on the right, and choose a different implementation pattern. Proxy is the default, but you can also choose Orchestration or Physical Service. See What is the API pattern and which pattern should I choose?
  3. Specify a name for the API, and click Save. The API Designer opens in the initial view so that you can start defining your API in the visual designer, as shown below.

    API Designer, initial view

  4. Resources: Define resources as needed. For detailed instructions, see Resources (Operations).
  5. Models: Define models as needed. For detailed instructions, see Model Objects.
  6. Tags: Define tags as needed. For detailed instructions, see Tags.
  7. Settings: In the Settings section, define default media types as needed. For detailed instructions, see What are default media types and how do I set them up?
  8. When done, click Save.

Note: You can also define the API by working directly with the OAS 3.0 JSON definition rather than the visual editor. Just click the JSON tab at the top of the page. For more information, see Using the JSON Text Editor.

Back to top

How do I edit my API design in OAS 3.0?

By default, the JSON Schema Editor converts any Swagger API description document to OAS 3.0. However, you can also choose Swagger 2.0.

To edit an OAS 3.0 API definition in the API Designer
  1. Go to APIs > My APIs > choose API > Details.
  2. In the Design section, on the right, click Edit. The JSON Schema Editor opens. By default, the API description is displayed as an OAS 3.0 document.

    Note: You can also click the drop-down, as shown below, and choose Swagger 2.0.

    Specifying the Swagger version

  3. Edit any components of the API design. For details, refer to the linked procedure below. You can add, edit, or delete:
  4. You can also directly edit the OAS 3.0 API description document: click the JSON tab to access the API description in the JSON Text Editor. See Using the JSON Text Editor.
  5. When done, click Save.

Note: You can also define the API by working directly with the OAS 3.0 JSON definition rather than the visual editor. Just click the JSON tab at the top of the page. For more information, see Using the JSON Text Editor.

Back to top

Using the JSON Text Editor

If you prefer to edit the plain JSON for your API definition rather than working in the API Designer, click the JSON tab. The OpenAPI 3.0 swagger JSON file is displayed, as shown in the examples below.

Sample OAS 3.0 file for a new API with no API definition

If you choose to provide a name, and then design from scratch, the platform creates a placeholder OAS 3.0 Swagger document using the name you provided, as shown below.

JSON Text Editor with placeholder info

Sample OAS 3.0 file when API definition document was uploaded

JSON Text Editor

Editing in the JSON Text Editor

In the JSON Text Editor you can directly modify your OAS 3.0 API definition. The Editor has built-in features to help you design your API, such as:

  • Syntax highlighting, as shown above.
  • Code hinting as you type. An example is shown below.

    JSON Text Editor: code hinting

  • Search for model objects includes typeahead search in popup dialog for search; the results are a drop-down list with hover for description.
  • Contextual help. Type CTRL+Spacebar to access the contextual help, as shown in the example below.

    JSON Text Editor: accessing contextual help

  • Syntax and semantic validation when you switch between text and graphical view.
  • Validation on save. You cannot save the file unless the JSON is valid and conforms to the OpenAPI 3.0 standard.

Back to top

JSON Schema Editor:

Overview

The JSON Schema Editor, new in version 2019.0.0, is a graphical user interface for creating and editing JSON schema definitions, using JSON Schema Draft 4. It includes such features as:

  • Code completion
  • Syntax highlighting
  • Syntax and semantic validation when you save or switch between text and graphical view

Back to top

Adding and editing model objects in OAS 3.0

You can add and edit model objects in the API Design view, Models section.

With OAS 3.0, the default view in 2019.0.0, the tabs are:

  • Editor (the default): the JSON Schema Editor.
  • JSON: when you click the JSON tab you can directly edit the OAS 3.0 Swagger document. For details, see Using the JSON Text Editor.

Back to top

How do I access the JSON Schema Editor?

The JSON Schema Editor is available in two places in the developer portal:

  • For the API Admin: in the API Designer.

    Go to APIs > My APIs > choose API > Details. In the Design section, click Edit. In the Models section, click Add, or select an existing model and click Edit.

  • For the Business Admin: in the context of a specific business model.

    Go to More > Organizations > choose organization > Models > Add. Provide name and any other basic details and click Save to access the Edit Schema page. The JSON Schema Editor is the default view.

Back to top

Using the JSON Schema Editor

The initial view in the JSON Schema Editor, after defining an API, is shown below.

With OAS 3.0, the default view in 2019.0.0, the tabs are:

  • Editor (the default): the JSON Schema Editor.
  • JSON: when you click the JSON tab you can directly edit the OAS 3.0 Swagger document. For details, see Using the JSON Text Editor.

Note: You can also define the API by working directly with the OAS 3.0 JSON definition rather than the visual editor. Just click the JSON tab at the top of the page. For more information, see Using the JSON Text Editor.

To author in the JSON Schema Editor
  1. Go to the Design page for your API and click Add Model. The initial view of the JSON Schema Editor, for a new model, is shown below.

    Add Model, initial view of JSON Schema Editor

  2. Enter the name for the model object.
  3. Define one or more properties. For each property:
    • Click the + sign, and then click object and specify the object type from the list below (your installation might include additional custom object definitions).

      Specifying the object type

      Default object types available: String, Number, Integer, Boolean, Object, Array, $ref, oneOf, anyOf, allOf, patternProperty. For Array, you must specify the data type for the array (String, Number, Integer, Boolean, or $ref). For $ref, you must specify the referenced object. For patternProperty, you must specify the pattern (regular expression) that the value must match, and the object type.

    • Specify the ID (property name) and click Finish.
    • Optional: on the right, click the Validations link to specify validations. For example, if you choose Integer, you can specify int32 or int64. When done, click Finish on the Validations overlay. For more information about validations that you can add, see What validations can I add to model object properties in the JSON Schema Editor?
    • Optional: if the property is required, check the required box, as shown below.

      Specifying the object type

  4. On the Add Model dialog, click Finish to save the new model. You are returned to the API Designer.

    Note: Changes are not permanently saved until you click Save on the API Designer page. Remember to save before exiting.

    You can also switch between tabs. When you switch, the platform automatically validates the API description, and provides messaging if there are validation errors.

Back to top

What validations can I add to model object properties in the JSON Schema Editor?

When you're adding or modifying elements, in the JSON API description, you can specify validations that must be applied to various elements.

The specific validations available vary according to the type of element.

Some examples and their definitions are shown below, in these sections:

Common Validations

Validations: Common

Dependencies
If validation is required against other properties, specify the dependencies. An example from the Swagger Petstore API: id, quantity, shipDate, status, complete.
String Validations

Validations: String

Enum
Enter the items for the enumerated list, with comma separators. For example: placed,approved,delivered.
Format
A valid sub-format for the data type. For Integer, options are: int32 or int64.
Minimum Length
Minimum allowable length for the string.
Maximum Length
Maximum allowable length for the string.
Pattern (regexp)
A regular expression pattern that the string must match.
Number Validations

See Integer Validations below.

Integer Validations

Validations: Integer

Enum
Enter the items for the enumerated list, with comma separators. For example: placed,approved,delivered.
Format
A valid sub-format for the data type. For Integer, options are: int32 or int64.
Multiple Of
An integer value that the property value must be a multiple of.
Minimum
Minimum allowable integer value for the property.
Maximum
Maximum allowable integer value for the property.
Boolean Validations

None except common validations (dependencies).

Object Validations

Adding validations to the model object: example 2

Minimum Number of Properties
Enter an integer value.
Maximum Number of Properties
Enter an integer value.
Additional Properties Allowed?
Specify Yes, No, or Specify Properties Allowed. If you choose to specify, an additional field appears, for Additional Property Types:

Adding validations to the model object: example 2

Array Validations

Arrays have these sets of validations:

  • Common Validations
  • Validations for the data type specified for the array
  • Array Validations listed below

Validations: Array

Additional Items Allowed?
Default is Yes. You can change to No, or click Specify Types Allowed and specify the data type for additional items allowed in the array.
Minimum Number of Items
The minimum allowable number of items for the array to be valid.
Maximum Number of Items
The maximum allowable number of items for the array to be valid.
Unique Items
Check the box to add validation that an item appears only once in the array.
$ref Validations

When you're defining a $ref property, you must specify the destination object that's being referenced.

There are no other validations for $ref properties.

oneOf Validations

When you choose an object type of oneOf, a sub-object is created. You can then go in there and specify what the property must be one of, as shown below.

There are no other validations for oneOf properties.

Validations: oneOf

anyOf Validations

In the same way as oneOf shown above, when you choose an object type of anyOf, a sub-object is created. You can then go in there and specify what the property must be any of.

There are no other validations for anyOf properties.

allOf Validations

In the same way as oneOf shown above, when you choose an object type of allOf, a sub-object is created. You can then go in there and specify what the property must be all of.

There are no other validations for allOf properties.

patternProperty Validations

When you're defining a patternProperty property, you must specify the pattern (regular expression) that the value must match, and the object type. For example, if you specify a pattern of [0-9]{3}, the value must be three digits.

For validations available, refer to the validations for the object type you specify.

Back to top

How do I define a $ref reference to another model in the JSON Schema Editor?

When defining your models, it's best to define the models that are referenced by others, before adding the $ref references to those models.

When you add a $ref, you'll need to specify which model is being referenced. The portal offers you a list of valid models to choose from, as shown in the example below. Because of this, you really need to define the referenced model first.

Choosing from a list of valid objects to define a $ref property

For basic instructions on defining a model, see Using the JSON Schema Editor.

Notes re the model object selection list

Two types of model objects might appear on the list:

  • Models already defined in the context of the current API.
  • Models defined for the business.

In the example above, the first model was defined in the context of the API and the other two are global model objects.

In addition, global model objects can have multiple versions. The version is included in the path so that it's clear what you're selecting.

Note: When you choose a global model object, it becomes local to the API. At that point, you can change it without affecting the global definition. Changes to the global model object do not filter down to your API, and additional versions do not apply to the API. If you want to update to a newer global model object, go into the API definition, as above, and choose the new model from the list.

Back to top