-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(reference): add Workflows 1.0.0 YAML parser plugin (#3572)
- Loading branch information
1 parent
1679c7d
commit 7e4ba45
Showing
7 changed files
with
363 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
packages/apidom-reference/src/parse/parsers/workflows-yaml-1/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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-yaml-1'; | ||
|
||
import ParserError from '../../../errors/ParserError'; | ||
import { File as IFile, Parser as IParser } from '../../../types'; | ||
import Parser from '../Parser'; | ||
|
||
const WorkflowsYaml1Parser: stampit.Stamp<IParser> = stampit(Parser, { | ||
props: { | ||
name: 'workflows-yaml-1', | ||
fileExtensions: ['.yaml', '.yml'], | ||
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', 'refractorOpts'], this); | ||
return await parse(source, parserOpts); | ||
} catch (error: any) { | ||
throw new ParserError(`Error parsing "${file.uri}"`, { cause: error }); | ||
} | ||
}, | ||
}, | ||
}); | ||
|
||
export default WorkflowsYaml1Parser; |
61 changes: 61 additions & 0 deletions
61
packages/apidom-reference/test/parse/parsers/workflows-yaml-1/fixtures/sample-workflow.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
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. | ||
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: | ||
# parameters to inject into the loginUser operation (parameter name must be resolvable at the referenced operation and the value is determined using {expression} syntax) | ||
- name: username | ||
in: query | ||
value: $inputs.username | ||
- name: password | ||
in: query | ||
value: $inputs.password | ||
successCriteria: | ||
# assertions to determine step was successful | ||
- condition: $statusCode == 200 | ||
outputs: | ||
# outputs from this step | ||
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: | ||
# outputs from this step | ||
availablePets: $response.body | ||
outputs: | ||
available: $steps.getPetStep.availablePets |
Oops, something went wrong.