Backend function for Kontent.ai Learn that uses Kontent.ai as a source of its data.
This service is responsible for creating HTML documents that represent API reference pages on the Kontent.ai Learn, and passing them forward using Azure Blob Storage.
It responds to events triggered by the blob storage, after the Reference Preprocessor creates a blob with the preprocessed data. The OpenAPI Processor then processes the data into HTML pages that are then saved in the Blob Storage.
- This project is a TypeScript Azure Functions application.
- It is subscribed to an Azure Event Grid topic and listens for events. Each event contains information about the content that was changed.
- After receiving an event, it fetches the content from the Blob storage.
- The fetched content is first processed into a JSON object, that is supposed to satisfy OpenAPI Specification 3.0.2 format. The JSON is also validated using the openapi-schema-validator package.
- The created JSON object is then processed by a forked ReDoc package. ReDoc generates an HTML file that represents a single API Reference page.
- Finally, a blob with the generated HTML is stored to an Azure Blob Storage.
- Node 10 (+yarn) installed
- Visual Studio Code installed
- Open Visual Studio Code and install the prerequisites according to the following steps.
- Log in to Azure using the Azure Functions extension tab.
- Clone the project repository and open it in Visual Studio Code.
- Run
yarn install
in the terminal. - Set the required keys.
- Deploy to Azure using Azure Functions extension tab, or run locally by pressing
Ctrl + F5
in Visual Studio Code.
Use the local.settings.json.template for a quick setup.
Azure.StorageKey
- Azure Storage keyAzure.StorageAccountName
- Azure Storage account nameAzure.ContainerName
- Azure Storage container name - for HTML API Reference pagesAzure.SpecificationContainerName
- Azure Storage container name - for JSON API Reference specificationsEventGrid.Notification.Key
- Key for notification eventGrid topicEventGrid.Notification.Endpoint
- Url for notification eventGrid topic
- Run
yarn run test
in the terminal.
For local testing without EventGrid:
- Install and run Windows Azure Storage Emulator 5.10.
- Omit setting the
EventGrid.*
keys in local.settings.json, you don't need these. - In
.\kcd-open-api-processor\index.ts
, change the following:- Comment out lines 31 to 33, you don't need them.
- Change
Configuration.set(isTest)
toConfiguration.set(false)
. - In the input parameters of the getBlobFromStorage function, use your own variable for
url
instead ofevent.data.url
. Your URL must lead to an output JSON file from the preprocessor such ashttps://<StorageAccountName>.blob.core.windows.net/<ReferenceDataContainerName/<ApiName>
.
- In
.\kcd-open-api-processor\function.json
, replace the existingeventGridTrigger
binding with anhttpTrigger
so that the Azure Function responds to GET requests instead of eventGrid events.
Example httpTrigger
binding.
{
"type": "httpTrigger",
"name": "req",
"direction": "in",
"methods": [ "get" ]
}
After making the changes:
- Press F5 to run the Azure Function in Visual Studio Code.
- You should see a line like this
kcd-open-api-processor: [GET] http://localhost:7071/api/kcd-open-api-processor
.
- You should see a line like this
- Send a GET request to the function URL in your terminal.
The function will output two files (HTML + OAS JSON) in two remote locations, which depend on the values you specified for Azure.ContainerName
and Azure.SpecificationContainerName
. The HTML file will be in ContainerName
while the JSON will be in SpecificationContainerName
. For example, you'll find the HTML under a URL such as https://<StorageAccountName>.blob.core.windows.net/<ContainerName/<ApiName>.html
.
Feel free to open a new issue where you describe your proposed changes, or even create a new pull request from your branch with proposed changes.
The source codes is published under MIT license.