Skip to content

Commit

Permalink
feat(reference): add Workflows 1.0.0 JSON parser plugin (#3568)
Browse files Browse the repository at this point in the history
Refs #3567
  • Loading branch information
frankkilcommins authored Dec 21, 2023
1 parent 8c2e246 commit 1b12b50
Show file tree
Hide file tree
Showing 6 changed files with 358 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/apidom-reference/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,20 @@ Supported media types are:
]
```

#### [workflows-json-1](https://github.com/swagger-api/apidom/tree/main/packages/apidom-reference/src/parse/parsers/workflows-json-1)

Wraps [@swagger-api/apidom-parser-adapter-workflows-json-1](https://github.com/swagger-api/apidom/tree/main/packages/apidom-parser-adapter-workflows-json-1) package
and is uniquely identified by `workflows-json-1` name.

Supported media types are:

```js
[
'application/vnd.oai.workflows;version=1.0.0',
'application/vnd.oai.workflows+json;version=1.0.0',
]
```

#### [api-design-systems-json](https://github.com/swagger-api/apidom/tree/main/packages/apidom-reference/src/parse/parsers/api-design-systems-json)

Wraps [@swagger-api/apidom-parser-adapter-api-design-systsems-json](https://github.com/swagger-api/apidom/tree/main/packages/apidom-parser-adapter-api-design-systems-json) package
Expand Down Expand Up @@ -338,6 +352,7 @@ returns `true` or until entire list of parser plugins is exhausted (throws error
OpenApiYaml3_1Parser({ allowEmpty: true, sourceMap: false }),
AsyncApiJson2Parser({ allowEmpty: true, sourceMap: false }),
AsyncApiYaml2Parser({ allowEmpty: true, sourceMap: false }),
WorkflowsJson1Parser({ allowEmpty: true, sourceMap: false }),
ApiDesignSystemsJsonParser({ allowEmpty: true, sourceMap: false }),
ApiDesignSystemsYamlParser({ allowEmpty: true, sourceMap: false }),
JsonParser({ allowEmpty: true, sourceMap: false }),
Expand All @@ -359,6 +374,7 @@ import OpenApiJson3_1Parser from '@swagger-api/apidom-reference/parse/parsers/op
import OpenApiYaml3_1Parser from '@swagger-api/apidom-reference/parse/parsers/openapi-yaml-3-1'
import AsyncApiJson2Parser from '@swagger-api/apidom-reference/parse/parsers/asyncapi-json-2';
import AsyncApiYaml2Parser from '@swagger-api/apidom-reference/parse/parsers/asyncapi-yaml-2';
import WorkflowsJson1Parser from '@swagger-api/apidom-reference/parse/parsers/workflows-json-1';
import ApiDesignSystemsJsonParser from '@swagger-api/apidom-reference/parse/parsers/api-design-systems-json';
import ApiDesignSystemsYamlParser from '@swagger-api/apidom-reference/parse/parsers/api-design-systems-json';
import JsonParser from '@swagger-api/apidom-reference/parse/parsers/json';
Expand All @@ -375,6 +391,7 @@ options.parse.parsers = [
OpenApiYaml3_1Parser({ allowEmpty: true, sourceMap: false }),
AsyncApiJson2Parser({ allowEmpty: true, sourceMap: false }),
AsyncApiYaml2Parser({ allowEmpty: true, sourceMap: false }),
WorkflowsJson1Parser({ allowEmpty: true, sourceMap: false }),
ApiDesignSystemsJsonParser({ allowEmpty: true, sourceMap: false }),
ApiDesignSystemsYamlParser({ allowEmpty: true, sourceMap: false }),
YamlParser({ allowEmpty: true, sourceMap: false }),
Expand All @@ -395,6 +412,7 @@ import OpenApiJson3_1Parser from '@swagger-api/apidom-reference/parse/parsers/op
import OpenApiYaml3_1Parser from '@swagger-api/apidom-reference/parse/parsers/openapi-yaml-3-1'
import AsyncApiJson2Parser from '@swagger-api/apidom-reference/parse/parsers/asyncapi-json-2';
import AsyncApiYaml2Parser from '@swagger-api/apidom-reference/parse/parsers/asyncapi-yaml-2';
import WorkflowsJson1Parser from '@swagger-api/apidom-reference/parse/parsers/workflows-json-2';
import ApiDesignSystemsJsonParser from '@swagger-api/apidom-reference/parse/parsers/api-design-systems-json';
import ApiDesignSystemsYamlParser from '@swagger-api/apidom-reference/parse/parsers/api-design-systems-json';
import JsonParser from '@swagger-api/apidom-reference/parse/parsers/json';
Expand All @@ -413,6 +431,7 @@ await parse('/home/user/oas.json', {
OpenApiYaml3_0Parser({ allowEmpty: true, sourceMap: false }),
AsyncApiJson2Parser({ allowEmpty: true, sourceMap: false }),
AsyncApiYaml2Parser({ allowEmpty: true, sourceMap: false }),
WorkflowsJson1Parser({ allowEmpty: true, sourceMap: false }),
ApiDesignSystemsJsonParser({ allowEmpty: true, sourceMap: false }),
ApiDesignSystemsYamlParser({ allowEmpty: true, sourceMap: false }),
YamlParser({ allowEmpty: true, sourceMap: false }),
Expand Down
7 changes: 7 additions & 0 deletions packages/apidom-reference/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@
"require": "./cjs/parse/parsers/asyncapi-yaml-2/index.cjs",
"types": "./types/parse/parsers/asyncapi-yaml-2/index.d.ts"
},
"./parse/parsers/workflows-json-1": {
"import": "./es/parse/parsers/workflows-json-1/index.mjs",
"require": "./cjs/parse/parsers/workflows-json-1/index.cjs",
"types": "./types/parse/parsers/workflows-json-1/index.d.ts"
},
"./parse/parsers/binary": {
"browser": {
"import": "./es/parse/parsers/binary/index-browser.mjs",
Expand Down Expand Up @@ -255,6 +260,7 @@
"@swagger-api/apidom-parser-adapter-openapi-yaml-2": "^0.89.0",
"@swagger-api/apidom-parser-adapter-openapi-yaml-3-0": "^0.89.0",
"@swagger-api/apidom-parser-adapter-openapi-yaml-3-1": "^0.89.0",
"@swagger-api/apidom-ns-workflows-1": "^0.89.0",
"@swagger-api/apidom-parser-adapter-yaml-1-2": "^0.89.0"
},
"devDependencies": {
Expand All @@ -275,6 +281,7 @@
"@swagger-api/apidom-parser-adapter-openapi-yaml-2": "*",
"@swagger-api/apidom-parser-adapter-openapi-yaml-3-0": "*",
"@swagger-api/apidom-parser-adapter-openapi-yaml-3-1": "*",
"@swagger-api/apidom-ns-workflows-1": "*",
"@swagger-api/apidom-parser-adapter-yaml-1-2": "*",
"axios-mock-adapter": "^1.21.4"
},
Expand Down
2 changes: 2 additions & 0 deletions packages/apidom-reference/src/configuration/saturated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import OpenApiJson3_1Parser from '../parse/parsers/openapi-json-3-1';
import OpenApiYaml3_1Parser from '../parse/parsers/openapi-yaml-3-1';
import AsyncApiJson2Parser from '../parse/parsers/asyncapi-json-2';
import AsyncApiYaml2Parser from '../parse/parsers/asyncapi-yaml-2';
import WorkflowsJson1Parser from '../parse/parsers/workflows-json-1';
import JsonParser from '../parse/parsers/json';
import YamlParser from '../parse/parsers/yaml-1-2';
import BinaryParser from '../parse/parsers/binary/index-node';
Expand All @@ -33,6 +34,7 @@ options.parse.parsers = [
OpenApiYaml3_1Parser({ allowEmpty: true, sourceMap: false }),
AsyncApiJson2Parser({ allowEmpty: true, sourceMap: false }),
AsyncApiYaml2Parser({ allowEmpty: true, sourceMap: false }),
WorkflowsJson1Parser({ allowEmpty: true, sourceMap: false }),
ApiDesignSystemsJsonParser({ allowEmpty: true, sourceMap: false }),
ApiDesignSystemsYamlParser({ allowEmpty: true, sourceMap: false }),
JsonParser({ allowEmpty: true, sourceMap: false }),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import stampit from 'stampit';
import { pick } from 'ramda';
import { ParseResultElement } from '@swagger-api/apidom-core';
import { parse, mediaTypes, detect } from '@swagger-api/apidom-parser-adapter-workflows-json-1';

import ParserError from '../../../errors/ParserError';
import { File as IFile, Parser as IParser } from '../../../types';
import Parser from '../Parser';

const WorkflowsJson1Parser: stampit.Stamp<IParser> = stampit(Parser, {
props: {
name: 'workflows-json-1',
fileExtensions: ['.json'],
mediaTypes,
},
methods: {
async canParse(file: IFile): Promise<boolean> {
const hasSupportedFileExtension =
this.fileExtensions.length === 0 ? true : this.fileExtensions.includes(file.extension);
const hasSupportedMediaType = this.mediaTypes.includes(file.mediaType);

if (!hasSupportedFileExtension) return false;
if (hasSupportedMediaType) return true;
if (!hasSupportedMediaType) {
return detect(file.toString());
}
return false;
},
async parse(file: IFile): Promise<ParseResultElement> {
const source = file.toString();

try {
const parserOpts = pick(['sourceMap', 'syntacticAnalysis', 'refractorOpts'], this);
return await parse(source, parserOpts);
} catch (error: any) {
throw new ParserError(`Error parsing "${file.uri}"`, { cause: error });
}
},
},
});

export default WorkflowsJson1Parser;
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
{
"workflowsSpec": "1.0.0",
"info": {
"title": "A pet purchasing workflow",
"summary": "This workflow showcases how to purchase a pet through a sequence of API calls",
"description": "This workflow walks you through the steps of `searching` for, `selecting`, and `purchasing` an available pet.\n",
"version": "1.0.1"
},
"sourceDescriptions": [
{
"name": "petStoreDescription",
"url": "https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml",
"type": "openapi"
}
],
"workflows": [
{
"workflowId": "loginUserRetrievePet",
"summary": "Login User and then retrieve pets",
"description": "This procedure lays out the steps to login a user and then retrieve pets",
"inputs": {
"type": "object",
"properties": {
"username": {
"type": "string"
},
"password": {
"type": "string"
}
}
},
"steps": [
{
"stepId": "loginStep",
"description": "This step demonstrates the user login step",
"operationId": "petStoreDescription.loginUser",
"parameters": [
{
"name": "username",
"in": "query",
"value": "$inputs.username"
},
{
"name": "password",
"in": "query",
"value": "$inputs.password"
}
],
"successCriteria": [
{
"condition": "$statusCode == 200"
}
],
"outputs": {
"tokenExpires": "$response.header.X-Expires-After",
"rateLimit": "$response.header.X-Rate-Limit",
"sessionToken": "$response.body"
}
},
{
"stepId": "getPetStep",
"description": "retrieve a pet by status from the GET pets endpoint",
"operationRef": "https://petstore3.swagger.io/api/v3/openapi.json#/paths/users/~findbystatus~1{status}/get",
"dependsOn": "loginStep",
"parameters": [
{
"name": "status",
"in": "query",
"value": "available"
},
{
"name": "Authorization",
"in": "header",
"value": "$steps.loginUser.outputs.sessionToken"
}
],
"successCriteria": [
{
"condition": "$statusCode == 200"
}
],
"outputs": {
"availablePets": "$response.body"
}
}
],
"outputs": {
"available": "$steps.getPetStep.availablePets"
}
}
]
}
Loading

0 comments on commit 1b12b50

Please sign in to comment.