Skip to content

Commit

Permalink
feat: lint arazzo test descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitryAnansky committed Jul 8, 2024
1 parent c912737 commit ead188a
Show file tree
Hide file tree
Showing 112 changed files with 992 additions and 115 deletions.
6 changes: 6 additions & 0 deletions .changeset/green-worms-vanish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@redocly/openapi-core": minor
"@redocly/cli": minor
---

Added support for Arazzo description linting.
32 changes: 32 additions & 0 deletions __tests__/bundle/bundle-arazzo-valid-test-description/museum.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
arazzo: 1.0.0
info:
title: Redocly Museum API Tickets
description: >-
A part of imaginary, but delightful Museum API for interacting with museum services
and information. Built with love by Redocly.
version: 1.0.0

sourceDescriptions:
- name: museum-api
type: openapi
url: museum-api.yaml

workflows:
- workflowId: get-museum-tickets
description: >-
This workflow demonstrates how to buy tickets for the museum.
parameters:
- $ref: './parameter.yaml'
steps:
- stepId: buy-tickets
description: >-
Buy museum tickets resolving request details with buyMuseumTickets operationId from museum-api.yaml description.
operationId: buyMuseumTickets
requestBody:
$ref: './request-body.yaml#/requestBody'
successCriteria:
- condition: $statusCode == 201
outputs:
ticketId: $response.body.ticketId
outputs:
ticketId: $steps.buy-tickets.outputs.ticketId
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
in: header
name: Authorization
value: Basic Og==
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
requestBody:
payload:
ticketType: general
ticketDate: 2023-09-07
email: [email protected]
43 changes: 43 additions & 0 deletions __tests__/bundle/bundle-arazzo-valid-test-description/snapshot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`E2E bundle bundle-arazzo-valid-test-description 1`] = `
info:
title: Redocly Museum API Tickets
description: A part of imaginary, but delightful Museum API for interacting with museum services and information. Built with love by Redocly.
version: 1.0.0
components:
parameters:
parameter:
in: header
name: Authorization
value: Basic Og==
arazzo: 1.0.0
sourceDescriptions:
- name: museum-api
type: openapi
url: museum-api.yaml
workflows:
- workflowId: get-museum-tickets
description: This workflow demonstrates how to buy tickets for the museum.
parameters:
- $ref: '#/parameters/parameter'
steps:
- stepId: buy-tickets
description: Buy museum tickets resolving request details with buyMuseumTickets operationId from museum-api.yaml description.
operationId: buyMuseumTickets
requestBody:
payload:
ticketType: general
ticketDate: '2023-09-07'
email: [email protected]
successCriteria:
- condition: $statusCode == 201
outputs:
ticketId: $response.body.ticketId
outputs:
ticketId: $steps.buy-tickets.outputs.ticketId
bundling museum.yaml...
📦 Created a bundle for museum.yaml at stdout <test>ms.
`;

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

37 changes: 35 additions & 2 deletions __tests__/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,35 @@ describe('E2E', () => {

const args = getParams('../../../packages/cli/src/index.ts', 'lint');

it(file, () => {
test(file, () => {
const result = getCommandOutput(args, testPath);
(<any>expect(cleanupOutput(result))).toMatchSpecificSnapshot(join(testPath, 'snapshot.js'));
});
}

test('lint valid Arazzo description', () => {
const dirName = 'arazzo-valid-test-description';
const folderPath = join(__dirname, `lint/${dirName}`);

const args = getParams('../../../packages/cli/src/index.ts', 'lint', ['museum.yaml']);

const result = getCommandOutput(args, folderPath);
(expect(cleanupOutput(result)) as any).toMatchSpecificSnapshot(
join(folderPath, 'snapshot.js')
);
});

test('lint not valid Arazzo description', () => {
const dirName = 'arazzo-not-valid-test-description';
const folderPath = join(__dirname, `lint/${dirName}`);

const args = getParams('../../../packages/cli/src/index.ts', 'lint', ['museum.yaml']);

const result = getCommandOutput(args, folderPath);
(expect(cleanupOutput(result)) as any).toMatchSpecificSnapshot(
join(folderPath, 'snapshot.js')
);
});
});

describe('zero-config', () => {
Expand Down Expand Up @@ -389,6 +413,7 @@ describe('E2E', () => {
const excludeFolders = [
'bundle-remove-unused-components',
'bundle-remove-unused-components-from-config',
'bundle-arazzo-valid-test-description',
];
const folderPath = join(__dirname, 'bundle');
const contents = readdirSync(folderPath).filter((folder) => !excludeFolders.includes(folder));
Expand All @@ -403,11 +428,19 @@ describe('E2E', () => {

const args = getParams('../../../packages/cli/src/index.ts', 'bundle', [...entryPoints]);

it(file, () => {
test(file, () => {
const result = getCommandOutput(args, testPath);
(<any>expect(cleanupOutput(result))).toMatchSpecificSnapshot(join(testPath, 'snapshot.js'));
});
}

test('bundle-arazzo-valid-test-description', () => {
const testPath = join(folderPath, 'bundle-arazzo-valid-test-description');
const args = getParams('../../../packages/cli/src/index.ts', 'bundle', ['museum.yaml']);

const result = getCommandOutput(args, testPath);
(<any>expect(cleanupOutput(result))).toMatchSpecificSnapshot(join(testPath, 'snapshot.js'));
});
});

describe('bundle with option: remove-unused-components', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exports[`E2E lint-config test with option: { dirName: 'invalid-config--lint-conf
validating ../__fixtures__/valid-openapi.yaml...
../__fixtures__/valid-openapi.yaml: validated in <test>ms
Woohoo! Your API description is valid. 🎉
Woohoo! Your description document is valid. 🎉
[WARNING] Unused rules found in .redocly.yaml: context.
Check the spelling and verify the added plugin prefix.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Warning was generated by the configuration spec rule.
validating ../__fixtures__/valid-openapi.yaml...
../__fixtures__/valid-openapi.yaml: validated in <test>ms
Woohoo! Your API description is valid. 🎉
Woohoo! Your description document is valid. 🎉
[WARNING] Unused rules found in .redocly.yaml: context.
Check the spelling and verify the added plugin prefix.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Warning was generated by the configuration spec rule.
validating ../__fixtures__/valid-openapi.yaml...
../__fixtures__/valid-openapi.yaml: validated in <test>ms
Woohoo! Your API description is valid. 🎉
Woohoo! Your description document is valid. 🎉
[WARNING] Unused rules found in .redocly.yaml: context.
Check the spelling and verify the added plugin prefix.
Expand Down
Loading

0 comments on commit ead188a

Please sign in to comment.