Skip to content

Commit

Permalink
Skip API call with processing v2 (#130)
Browse files Browse the repository at this point in the history
* Update ignore files

* Add failing tests

* Allow skipping a call with processing V2
  • Loading branch information
Siegrift authored Feb 3, 2024
1 parent 9343c95 commit 1c73e96
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ coverage/
# IDE specific files
.idea
.vscode
.DS_Store
4 changes: 3 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
# Test files
coverage/

# Jetbrains
# IDE specific files
.idea
.vscode
.DS_Store
30 changes: 28 additions & 2 deletions src/ois.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ describe('API call skip validation', () => {
new ZodError([
{
code: 'custom',
message: `"postProcessingSpecifications" or "preProcessingSpecifications" must not be empty or undefined when "operation" is not specified and "fixedOperationParameters" is empty array.`,
message: `At least one processing schema must be defined when "operation" is not specified and "fixedOperationParameters" is empty array.`,
path: ['endpoints', 0],
},
])
Expand All @@ -626,7 +626,7 @@ describe('API call skip validation', () => {
new ZodError([
{
code: 'custom',
message: `"postProcessingSpecifications" or "preProcessingSpecifications" must not be empty or undefined when "operation" is not specified and "fixedOperationParameters" is empty array.`,
message: `At least one processing schema must be defined when "operation" is not specified and "fixedOperationParameters" is empty array.`,
path: ['endpoints', 0],
},
])
Expand Down Expand Up @@ -706,6 +706,32 @@ describe('API call skip validation', () => {
])
);
});

it('allows skipping API call with pre-processing v2', () => {
const ois = loadOisFixture();
ois.endpoints[0].operation = undefined;
ois.endpoints[0].fixedOperationParameters = [];
ois.endpoints[0].preProcessingSpecificationV2 = {
environment: 'Node',
timeoutMs: 5000,
value: 'output = input;',
};

expect(() => oisSchema.parse(ois)).not.toThrow();
});

it('allows skipping API call with post-processing v2', () => {
const ois = loadOisFixture();
ois.endpoints[0].operation = undefined;
ois.endpoints[0].fixedOperationParameters = [];
ois.endpoints[0].postProcessingSpecificationV2 = {
environment: 'Node',
timeoutMs: 5000,
value: 'output = input;',
};

expect(() => oisSchema.parse(ois)).not.toThrow();
});
});

describe('fixedOperationParameters', () => {
Expand Down
6 changes: 4 additions & 2 deletions src/ois.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,11 +423,13 @@ const ensureApiCallSkipRequirements: SuperRefinement<{
!endpoint.operation &&
endpoint.fixedOperationParameters.length === 0 &&
(!endpoint.postProcessingSpecifications || endpoint.postProcessingSpecifications?.length === 0) &&
(!endpoint.preProcessingSpecifications || endpoint.preProcessingSpecifications?.length === 0)
(!endpoint.preProcessingSpecifications || endpoint.preProcessingSpecifications?.length === 0) &&
!endpoint.preProcessingSpecificationV2 &&
!endpoint.postProcessingSpecificationV2
) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: `"postProcessingSpecifications" or "preProcessingSpecifications" must not be empty or undefined when "operation" is not specified and "fixedOperationParameters" is empty array.`,
message: `At least one processing schema must be defined when "operation" is not specified and "fixedOperationParameters" is empty array.`,
path: ['endpoints', endpoints.indexOf(endpoint)],
});
}
Expand Down

0 comments on commit 1c73e96

Please sign in to comment.