Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,32 @@ Much of this is unchanged from [Steps](#steps), however, we are adding a `stepNu

If you don't provide either a `operationId`, `operationPath` or a `workflowId` for the step, the `operationId` will be set to the name of your function. In the above example, the `operationId` would become **addPet**.

## Validator

Validation for the Araazo Specification is done by [Redocly](https://redocly.com/).

### Rules

I have configured the validator to use these Rules:

- [struct](https://redocly.com/docs/cli/rules/common/struct)
- [sourceDescriptions-name-unique](https://redocly.com/docs/cli/rules/arazzo/sourcedescriptions-name-unique)
- [sourceDescriptions-type](https://redocly.com/docs/cli/rules/arazzo/sourcedescriptions-type)
- [stepId-unique](https://redocly.com/docs/cli/rules/arazzo/stepid-unique)
- [workflowId-unique](https://redocly.com/docs/cli/rules/arazzo/workflowid-unique)

However, you can configure your own rules from the [ruleset available on the Redocly site](https://redocly.com/docs/cli/rules/built-in-rules#arazzo-rules). To do this, you will need to create a `redocly-arazzo.json` file within an `options` folder. The file should look like:

```json
{
"struct": "error",
"sourceDescriptions-name-unique": "error",
"sourceDescriptions-type": "error",
"stepId-unique": "error",
"workflowId-unique": "error"
}
```

## Running the Arazzo Specification

For now, I recommend using the [Redocly CLI](https://redocly.com/redocly-cli) to [run your Arazzo Workflows](https://redocly.com/learn/arazzo/testing-arazzo-workflows).
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "serverless-arazzo-workflows",
"version": "0.0.7",
"version": "0.0.8",
"description": "Document your Serverless Framework API workflows with the OpenAPI Arazzo Workflow Spec",
"main": "index.js",
"scripts": {
Expand Down
23 changes: 21 additions & 2 deletions src/ArazzoGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const {
createConfig,
} = require("@redocly/openapi-core");

const path = require('node:path');

class ArazzoGenerator {
constructor(arazzoDocumentation, options) {
this.arazzoDocumentation = arazzoDocumentation;
Expand All @@ -22,6 +24,24 @@ class ArazzoGenerator {
this.sourceFile = options?.sourceFile;

this.ajv = new Ajv();

try {
this.logger.verbose(
`Trying to resolve Redocly rules from: ${path.resolve(
"options",
"redocly.json"
)}`
);
this.REDOCLY_RULES = require(path.resolve("options", "redocly-arazzo.json"));
} catch (err) {
this.REDOCLY_RULES = {
"struct": "error",
"sourceDescriptions-name-unique": "error",
"sourceDescriptions-type": "error",
"stepId-unique": "error",
"workflowId-unique": "error"
};
}
}

parse() {
Expand Down Expand Up @@ -313,7 +333,6 @@ class ArazzoGenerator {
.map((functionType) => {
const event = functionType.events.filter(isViableFunction);
const operationName = functionType.name.split("-").at(-1);
console.log(operationName)

return {
operationName: operationName,
Expand All @@ -328,7 +347,7 @@ class ArazzoGenerator {
async validate() {
const config = await createConfig({
apis: {},
rules: {},
rules: this.REDOCLY_RULES,
});

const apiDesc = stringifyYaml(this.arazzo);
Expand Down
1 change: 1 addition & 0 deletions test/serverless-pets/arazzo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"arazzo":"1.0.1","info":{"title":"pets","description":"This is an example of an Arazzo Specification","summary":"Example Arazzo Specification","version":"1.0.0"},"sourceDescriptions":[{"name":"pets-openAPI","url":"openapi.json","type":"openapi"},{"name":"usersOpenAPI","url":"./openapi.json","type":"openapi"}],"workflows":[{"workflowId":"loginUserAndRetrievePet","summary":"Login User and then retrieve pets","description":"This workflow lays out the steps to login a user and then retrieve pets","inputs":{"type":"object","properties":{"username":{"type":"string"},"password":{"type":"string"},"petId":{"type":"integer"}}},"steps":[{"stepId":"loginStep","description":"This step demonstrates the user login step","operationId":"$sourceDescriptions.usersOpenAPI.loginUser","requestBody":{"contentType":"application/json","payload":{"username":"$inputs.username","password":"$inputs.password"}},"outputs":{"AccessToken":"$response.body/AccessToken"}},{"stepId":"getPet","description":"This step brings the pet back by id","operationId":"getPetById","parameters":[{"name":"petId","in":"path","value":"$inputs.petId"}]}]}]}
5 changes: 5 additions & 0 deletions test/serverless-pets/input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"findPetByStatus": {
"status": "pending"
}
}
Loading