Skip to content

Commit

Permalink
chore(rulesets): add arazzoTypes and refactor validations and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
frankkilcommins committed Aug 27, 2024
1 parent 6a3fd3d commit 98fcfe3
Show file tree
Hide file tree
Showing 26 changed files with 139 additions and 1,209 deletions.
Original file line number Diff line number Diff line change
@@ -1,53 +1,6 @@
import arazzoStepFailureActionsValidation from '../arazzoStepFailureActionsValidation';
import type { RulesetFunctionContext } from '@stoplight/spectral-core';

type FailureAction = {
name: string;
type: string;
workflowId?: string;
stepId?: string;
retryAfter?: number;
retryLimit?: number;
criteria?: Criterion[];
};

type SourceDescription = {
name: string;
url: string;
type?: string;
};

type CriterionExpressionType = {
type: 'jsonpath' | 'xpath';
version: 'draft-goessner-dispatch-jsonpath-00' | 'xpath-30' | 'xpath-20' | 'xpath-10';
};

type Criterion = {
context?: string;
condition: string;
type?: 'simple' | 'regex' | 'jsonpath' | 'xpath' | CriterionExpressionType;
};

type ReusableObject = {
reference: string;
};

type Step = {
stepId: string;
onFailure?: (FailureAction | ReusableObject)[];
};

type Workflow = {
workflowId: string;
steps: Step[];
failureActions?: (FailureAction | ReusableObject)[];
};

type ArazzoSpecification = {
sourceDescriptions?: SourceDescription[];
workflows: Workflow[];
components?: { failureActions?: Record<string, FailureAction> };
};
import { ArazzoSpecification } from '../types/arazzoTypes';

const runRule = (target: ArazzoSpecification, _contextOverrides: Partial<RulesetFunctionContext> = {}) => {
return arazzoStepFailureActionsValidation(target, null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,44 +1,6 @@
import arazzoStepParametersValidation from '../arazzoStepParametersValidation';
import type { RulesetFunctionContext } from '@stoplight/spectral-core';

type Parameter = {
name: string;
in?: string;
value: string;
};

type ReusableObject = {
reference: string;
};

type Step = {
stepId: string;
parameters?: (Parameter | ReusableObject)[];
workflowId?: string;
operationId?: string;
operationPath?: string;
};

type Workflow = {
workflowId: string;
steps: Step[];
inputs?: Record<string, unknown>;
};

type SourceDescription = {
name: string;
url: string;
type?: string;
};

type ArazzoSpecification = {
workflows: Workflow[];
components?: {
parameters?: Record<string, Parameter>;
inputs?: Record<string, unknown>;
};
sourceDescriptions?: SourceDescription[];
};
import { ArazzoSpecification } from '../types/arazzoTypes';

const runRule = (target: ArazzoSpecification, _contextOverrides: Partial<RulesetFunctionContext> = {}) => {
return arazzoStepParametersValidation(target, null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,56 +1,6 @@
import arazzoStepRequestBodyValidation from '../arazzoStepRequestBodyValidation';
import type { RulesetFunctionContext } from '@stoplight/spectral-core';

type PayloadReplacement = {
target: string;
value: unknown | string;
};

type RequestBody = {
contentType?: string;
payload?: unknown | string;
replacements?: PayloadReplacement[];
};

type Parameter = {
name: string;
in?: string;
value?: unknown;
};

type Step = {
stepId: string;
outputs?: Record<string, string>;
requestBody?: RequestBody;
parameters?: (Parameter | ReusableObject)[];
};

type ArazzoSpecification = {
workflows: Workflow[];
sourceDescriptions?: SourceDescription[];
components?: {
parameters?: Record<string, Parameter>;
[key: string]: unknown;
};
};

type ReusableObject = {
reference: string;
};

type SourceDescription = {
name: string;
url: string;
type?: string;
};

type Workflow = {
workflowId: string;
steps: Step[];
inputs?: Record<string, unknown>;
parameters?: (Parameter | ReusableObject)[];
outputs?: Record<string, string>;
};
import { ArazzoSpecification } from '../types/arazzoTypes';

const runRule = (target: ArazzoSpecification, _contextOverrides: Partial<RulesetFunctionContext> = {}) => {
return arazzoStepRequestBodyValidation(target, null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,51 +1,6 @@
import arazzoStepSuccessActionsValidation from '../arazzoStepSuccessActionsValidation';
import type { RulesetFunctionContext } from '@stoplight/spectral-core';

type SuccessAction = {
name: string;
type: string;
workflowId?: string;
stepId?: string;
criteria?: Criterion[];
};

type SourceDescription = {
name: string;
url: string;
type?: string;
};

type CriterionExpressionType = {
type: 'jsonpath' | 'xpath';
version: 'draft-goessner-dispatch-jsonpath-00' | 'xpath-30' | 'xpath-20' | 'xpath-10';
};

type Criterion = {
context?: string;
condition: string;
type?: 'simple' | 'regex' | 'jsonpath' | 'xpath' | CriterionExpressionType;
};

type ReusableObject = {
reference: string;
};

type Step = {
stepId: string;
onSuccess?: (SuccessAction | ReusableObject)[];
};

type Workflow = {
workflowId: string;
steps: Step[];
successActions?: (SuccessAction | ReusableObject)[];
};

type ArazzoSpecification = {
workflows: Workflow[];
sourceDescriptions?: SourceDescription[];
components?: { successActions?: Record<string, SuccessAction> };
};
import { ArazzoSpecification } from '../types/arazzoTypes';

const runRule = (target: ArazzoSpecification, _contextOverrides: Partial<RulesetFunctionContext> = {}) => {
return arazzoStepSuccessActionsValidation(target, null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,6 @@
import arazzoStepSuccessCriteriaValidation from '../arazzoStepSuccessCriteriaValidation';
import type { RulesetFunctionContext } from '@stoplight/spectral-core';

type CriterionExpressionType = {
type: 'jsonpath' | 'xpath';
version: 'draft-goessner-dispatch-jsonpath-00' | 'xpath-30' | 'xpath-20' | 'xpath-10';
};

type Criterion = {
context?: string;
condition: string;
type?: 'simple' | 'regex' | 'jsonpath' | 'xpath' | CriterionExpressionType;
};

type Step = {
stepId: string;
successCriteria?: Criterion[];
};

type Workflow = {
workflowId: string;
steps: Step[];
};

type ArazzoSpecification = {
workflows: Workflow[];
components?: object;
};
import { ArazzoSpecification } from '../types/arazzoTypes';

const runRule = (target: ArazzoSpecification, _contextOverrides: Partial<RulesetFunctionContext> = {}) => {
return arazzoStepSuccessCriteriaValidation(target, null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,77 +1,6 @@
import arazzoStepValidation from '../arazzoStepValidation';
import type { IFunctionResult } from '@stoplight/spectral-core';

type SourceDescription = {
name: string;
url: string;
type?: string;
};

type ArazzoSpecification = {
workflows: Workflow[];
sourceDescriptions?: SourceDescription[];
components?: {
parameters?: Record<string, Parameter>;
successActions?: Record<string, SuccessAction>;
failureActions?: Record<string, FailureAction>;
[key: string]: unknown;
};
};

type Parameter = {
name: string;
in?: string;
value?: unknown;
};

type Workflow = {
workflowId: string;
steps: Step[];
successActions?: (SuccessAction | ReusableObject)[];
failureActions?: (FailureAction | ReusableObject)[];
outputs?: Record<string, string>;
};

type Step = {
stepId: string;
operationId?: string;
operationPath?: string;
workflowId?: string;
outputs?: Record<string, string>;
onSuccess?: (SuccessAction | ReusableObject)[];
onFailure?: (FailureAction | ReusableObject)[];
};

type SuccessAction = {
name: string;
type: string;
workflowId?: string;
stepId?: string;
criteria?: Criterion[];
};

type FailureAction = {
name: string;
type: string;
workflowId?: string;
stepId?: string;
criteria?: Criterion[];
};

type Criterion = {
context?: string;
condition: string;
type?: 'simple' | 'regex' | 'jsonpath' | 'xpath' | CriterionExpressionType;
};

type CriterionExpressionType = {
type: 'jsonpath' | 'xpath';
version: string;
};

type ReusableObject = {
reference: string;
};
import { ArazzoSpecification } from '../types/arazzoTypes';

const runRule = (target: ArazzoSpecification): IFunctionResult[] => {
return arazzoStepValidation(target, null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
import { DeepPartial } from '@stoplight/types';
import { IFunctionResult } from '@stoplight/spectral-core';
import arazzoWorkflowIdUniqueness from '../arazzoWorkflowIdUniqueness';
import type { RulesetFunctionContext } from '@stoplight/spectral-core';
import { ArazzoSpecification } from '../types/arazzoTypes';

const runRule = (target: { workflows: Record<string, unknown>[] }) => {
const context: DeepPartial<RulesetFunctionContext> = {
path: [],
documentInventory: {
graph: {} as any, // Mock the graph property
referencedDocuments: {}, // Mock the referencedDocuments property as a Dictionary
findAssociatedItemForPath: jest.fn(), // Mock the findAssociatedItemForPath function
},
document: {
formats: new Set(), // Mock the formats property correctly
},
};

return arazzoWorkflowIdUniqueness(target, null, context as RulesetFunctionContext);
const runRule = (target: ArazzoSpecification): IFunctionResult[] => {
return arazzoWorkflowIdUniqueness(target, null);
};

describe('arazzoWorkflowIdUniqueness', () => {
Expand Down
Loading

0 comments on commit 98fcfe3

Please sign in to comment.