Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip API call with processing v2 #130

Merged
merged 3 commits into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading