Skip to content

Commit

Permalink
fix: remove 'ois' from the error path (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcroote authored Oct 4, 2023
1 parent 0f2eb7a commit 60af742
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
28 changes: 14 additions & 14 deletions src/ois.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ describe('parameter uniqueness', () => {
{
code: 'custom',
message: 'Parameter "from" in "query" is used multiple times',
path: ['ois', 'endpoints', 0, 'parameters', 0],
path: ['endpoints', 0, 'parameters', 0],
},
{
code: 'custom',
message: 'Parameter "from" in "query" is used multiple times',
path: ['ois', 'endpoints', 0, 'parameters', 3],
path: ['endpoints', 0, 'parameters', 3],
},
])
);
Expand All @@ -146,12 +146,12 @@ describe('parameter uniqueness', () => {
{
code: 'custom',
message: 'Parameter "to" in "query" is used multiple times',
path: ['ois', 'endpoints', 0, 'fixedOperationParameters', 0],
path: ['endpoints', 0, 'fixedOperationParameters', 0],
},
{
code: 'custom',
message: 'Parameter "to" in "query" is used multiple times',
path: ['ois', 'endpoints', 0, 'fixedOperationParameters', 1],
path: ['endpoints', 0, 'fixedOperationParameters', 1],
},
])
);
Expand All @@ -169,12 +169,12 @@ describe('parameter uniqueness', () => {
{
code: 'custom',
message: 'Parameter "from" in "query" is used in both "parameters" and "fixedOperationParameters"',
path: ['ois', 'endpoints', 0, 'parameters', 0],
path: ['endpoints', 0, 'parameters', 0],
},
{
code: 'custom',
message: 'Parameter "from" in "query" is used in both "parameters" and "fixedOperationParameters"',
path: ['ois', 'endpoints', 0, 'fixedOperationParameters', 1],
path: ['endpoints', 0, 'fixedOperationParameters', 1],
},
])
);
Expand Down Expand Up @@ -292,7 +292,7 @@ describe('apiSpecification parameters validation', () => {
{
code: 'custom',
message: 'Parameter "non-existing-parameter" not found in "fixedOperationParameters" or "parameters"',
path: ['ois', 'endpoints', 0],
path: ['endpoints', 0],
},
])
);
Expand All @@ -314,7 +314,7 @@ describe('apiSpecification parameters validation', () => {
{
code: 'custom',
message: 'No matching API specification parameter found in "apiSpecifications" section',
path: ['ois', 'endpoints', 0, 'parameters', 3],
path: ['endpoints', 0, 'parameters', 3],
},
])
);
Expand Down Expand Up @@ -343,12 +343,12 @@ describe('apiSpecification parameters validation', () => {
{
code: 'custom',
message: 'Parameter "api-param-name" not found in "fixedOperationParameters" or "parameters"',
path: ['ois', 'endpoints', 0],
path: ['endpoints', 0],
},
{
code: 'custom',
message: 'Parameter "api-param-name" not found in "fixedOperationParameters" or "parameters"',
path: ['ois', 'endpoints', 1],
path: ['endpoints', 1],
},
])
);
Expand All @@ -369,7 +369,7 @@ describe('apiSpecification parameters validation', () => {
{
code: 'custom',
message: 'No matching API specification parameter found in "apiSpecifications" section',
path: ['ois', 'endpoints', 0, 'parameters', 3],
path: ['endpoints', 0, 'parameters', 3],
},
])
);
Expand Down Expand Up @@ -609,7 +609,7 @@ describe('API call skip validation', () => {
{
code: 'custom',
message: `"postProcessingSpecifications" or "preProcessingSpecifications" must not be empty or undefined when "operation" is not specified and "fixedOperationParameters" is empty array.`,
path: ['ois', 'endpoints', 0],
path: ['endpoints', 0],
},
])
);
Expand All @@ -626,7 +626,7 @@ describe('API call skip validation', () => {
{
code: 'custom',
message: `"postProcessingSpecifications" or "preProcessingSpecifications" must not be empty or undefined when "operation" is not specified and "fixedOperationParameters" is empty array.`,
path: ['ois', 'endpoints', 0],
path: ['endpoints', 0],
},
])
);
Expand Down Expand Up @@ -700,7 +700,7 @@ describe('API call skip validation', () => {
{
code: 'custom',
message: `"fixedOperationParameters" must be empty array when "operation" is not specified.`,
path: ['ois', 'endpoints', 0],
path: ['endpoints', 0],
},
])
);
Expand Down
18 changes: 9 additions & 9 deletions src/ois.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ const ensureSingleParameterUsagePerEndpoint: SuperRefinement<{
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: `Parameter "${param.name}" in "${param.in}" is used multiple times`,
path: ['ois', 'endpoints', oisIndex, section, paramIndex],
path: ['endpoints', oisIndex, section, paramIndex],
});
}
});
Expand All @@ -360,14 +360,14 @@ const ensureSingleParameterUsagePerEndpoint: SuperRefinement<{
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: `Parameter "${param.name}" in "${param.in}" is used in both "parameters" and "fixedOperationParameters"`,
path: ['ois', 'endpoints', oisIndex, 'parameters', paramIndex],
path: ['endpoints', oisIndex, 'parameters', paramIndex],
});

// Add also an issue for the fixed parameter. This makes it easier for the user to find the offending parameter
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: `Parameter "${param.name}" in "${param.in}" is used in both "parameters" and "fixedOperationParameters"`,
path: ['ois', 'endpoints', oisIndex, 'fixedOperationParameters', fixedParams.indexOf(fixedParam)],
path: ['endpoints', oisIndex, 'fixedOperationParameters', fixedParams.indexOf(fixedParam)],
});
}
});
Expand All @@ -388,15 +388,15 @@ const ensureApiCallSkipRequirements: SuperRefinement<{
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.`,
path: ['ois', 'endpoints', endpoints.indexOf(endpoint)],
path: ['endpoints', endpoints.indexOf(endpoint)],
});
}

if (!endpoint.operation && endpoint.fixedOperationParameters.length !== 0) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: `"fixedOperationParameters" must be empty array when "operation" is not specified.`,
path: ['ois', 'endpoints', endpoints.indexOf(endpoint)],
path: ['endpoints', endpoints.indexOf(endpoint)],
});
}
});
Expand Down Expand Up @@ -428,7 +428,7 @@ const ensureEndpointAndApiSpecificationParamsMatch: SuperRefinement<{
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: `Parameter "${apiParam.name}" not found in "fixedOperationParameters" or "parameters"`,
path: ['ois', 'endpoints', endpoints.indexOf(endpoint)],
path: ['endpoints', endpoints.indexOf(endpoint)],
});
}
});
Expand All @@ -450,7 +450,7 @@ const ensureEndpointAndApiSpecificationParamsMatch: SuperRefinement<{
return ctx.addIssue({
code: z.ZodIssueCode.custom,
message: `No matching API specification found in "apiSpecifications" section`,
path: ['ois', 'endpoints', endpointIndex],
path: ['endpoints', endpointIndex],
});
}

Expand All @@ -466,7 +466,7 @@ const ensureEndpointAndApiSpecificationParamsMatch: SuperRefinement<{
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: `No matching API specification parameter found in "apiSpecifications" section`,
path: ['ois', 'endpoints', endpointIndex, 'parameters', endpointParamIndex],
path: ['endpoints', endpointIndex, 'parameters', endpointParamIndex],
});
}
});
Expand All @@ -483,7 +483,7 @@ const ensureEndpointAndApiSpecificationParamsMatch: SuperRefinement<{
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: `No matching API specification parameter found in "apiSpecifications" section`,
path: ['ois', 'endpoints', endpointIndex, 'fixedOperationParameters', endpointParamIndex],
path: ['endpoints', endpointIndex, 'fixedOperationParameters', endpointParamIndex],
});
}
}
Expand Down

0 comments on commit 60af742

Please sign in to comment.