Skip to content

Commit

Permalink
feat: lint arazzo test descriptions (#1601)
Browse files Browse the repository at this point in the history
* feat: lint arazzo test descriptions
  • Loading branch information
DmitryAnansky authored Jul 10, 2024
1 parent 4c3d8cf commit 599b5fa
Show file tree
Hide file tree
Showing 46 changed files with 1,016 additions and 60 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]
40 changes: 40 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,40 @@
// 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: {}
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:
- in: header
name: Authorization
value: Basic Og==
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.

60 changes: 57 additions & 3 deletions __tests__/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,65 @@ callSerializer();

describe('E2E', () => {
describe('lint', () => {
const excludeFolders = [
'arazzo-type-extensions-with-plugin',
'arazzo-not-valid-test-description',
'arazzo-valid-test-description',
];
const folderPath = join(__dirname, 'lint');
const contents = readdirSync(folderPath);
const contents = readdirSync(folderPath).filter((folder) => !excludeFolders.includes(folder));

for (const file of contents) {
const testPath = join(folderPath, file);
if (statSync(testPath).isFile()) continue;
if (!existsSync(join(testPath, 'redocly.yaml'))) continue;

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')
);
});

test('arazzo-type-extensions-with-plugin', () => {
const dirName = 'arazzo-type-extensions-with-plugin';
const folderPath = join(__dirname, `lint/${dirName}`);

const args = getParams('../../../packages/cli/src/index.ts', 'lint', [
'museum.yaml',
'--config=redocly.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 +434,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 +449,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
Loading

1 comment on commit 599b5fa

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements 77.22% 4565/5912
🟡 Branches 67.18% 2512/3739
🟡 Functions 70.72% 751/1062
🟡 Lines 77.45% 4300/5552

Test suite run success

750 tests passing in 105 suites.

Report generated by 🧪jest coverage report action from 599b5fa

Please sign in to comment.