Skip to content

Commit 4395952

Browse files
authored
Merge pull request #13 from JaredCE/improve-examples
Improve examples
2 parents 7fc50e4 + c2cf77b commit 4395952

20 files changed

+12690
-85
lines changed

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,32 @@ Much of this is unchanged from [Steps](#steps), however, we are adding a `stepNu
377377

378378
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**.
379379

380+
## Validator
381+
382+
Validation for the Araazo Specification is done by [Redocly](https://redocly.com/).
383+
384+
### Rules
385+
386+
I have configured the validator to use these Rules:
387+
388+
- [struct](https://redocly.com/docs/cli/rules/common/struct)
389+
- [sourceDescriptions-name-unique](https://redocly.com/docs/cli/rules/arazzo/sourcedescriptions-name-unique)
390+
- [sourceDescriptions-type](https://redocly.com/docs/cli/rules/arazzo/sourcedescriptions-type)
391+
- [stepId-unique](https://redocly.com/docs/cli/rules/arazzo/stepid-unique)
392+
- [workflowId-unique](https://redocly.com/docs/cli/rules/arazzo/workflowid-unique)
393+
394+
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:
395+
396+
```json
397+
{
398+
"struct": "error",
399+
"sourceDescriptions-name-unique": "error",
400+
"sourceDescriptions-type": "error",
401+
"stepId-unique": "error",
402+
"workflowId-unique": "error"
403+
}
404+
```
405+
380406
## Running the Arazzo Specification
381407

382408
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).

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "serverless-arazzo-workflows",
3-
"version": "0.0.7",
3+
"version": "0.0.8",
44
"description": "Document your Serverless Framework API workflows with the OpenAPI Arazzo Workflow Spec",
55
"main": "index.js",
66
"scripts": {

src/ArazzoGenerator.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ const {
88
createConfig,
99
} = require("@redocly/openapi-core");
1010

11+
const path = require('node:path');
12+
1113
class ArazzoGenerator {
1214
constructor(arazzoDocumentation, options) {
1315
this.arazzoDocumentation = arazzoDocumentation;
@@ -22,6 +24,24 @@ class ArazzoGenerator {
2224
this.sourceFile = options?.sourceFile;
2325

2426
this.ajv = new Ajv();
27+
28+
try {
29+
this.logger.verbose(
30+
`Trying to resolve Redocly rules from: ${path.resolve(
31+
"options",
32+
"redocly.json"
33+
)}`
34+
);
35+
this.REDOCLY_RULES = require(path.resolve("options", "redocly-arazzo.json"));
36+
} catch (err) {
37+
this.REDOCLY_RULES = {
38+
"struct": "error",
39+
"sourceDescriptions-name-unique": "error",
40+
"sourceDescriptions-type": "error",
41+
"stepId-unique": "error",
42+
"workflowId-unique": "error"
43+
};
44+
}
2545
}
2646

2747
parse() {
@@ -313,7 +333,6 @@ class ArazzoGenerator {
313333
.map((functionType) => {
314334
const event = functionType.events.filter(isViableFunction);
315335
const operationName = functionType.name.split("-").at(-1);
316-
console.log(operationName)
317336

318337
return {
319338
operationName: operationName,
@@ -328,7 +347,7 @@ class ArazzoGenerator {
328347
async validate() {
329348
const config = await createConfig({
330349
apis: {},
331-
rules: {},
350+
rules: this.REDOCLY_RULES,
332351
});
333352

334353
const apiDesc = stringifyYaml(this.arazzo);

test/serverless-pets/arazzo.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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"}]}]}]}

test/serverless-pets/input.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"findPetByStatus": {
3+
"status": "pending"
4+
}
5+
}

0 commit comments

Comments
 (0)