Skip to content

Commit

Permalink
fix: include example path in valid-example
Browse files Browse the repository at this point in the history
  • Loading branch information
P0lip committed Aug 18, 2019
1 parent 0a6377c commit 0e3844f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/__tests__/linter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,8 +565,8 @@ responses:: !!foo
}),
expect.objectContaining({
code: 'valid-example',
message: '"foo" property type should be number',
path: ['components', 'schemas', 'foo'],
message: '"example" property type should be number',
path: ['components', 'schemas', 'foo', 'example'],
}),
expect.objectContaining({
code: 'oas3-schema',
Expand All @@ -586,8 +586,8 @@ responses:: !!foo
expect.arrayContaining([
expect.objectContaining({
code: 'valid-example',
message: '"schema" property can\'t resolve reference #/parameters/missing from id #',
path: ['paths', '/todos/{todoId}', 'put', 'parameters', '1', 'schema'],
message: '"example" property can\'t resolve reference #/parameters/missing from id #',
path: ['paths', '/todos/{todoId}', 'put', 'parameters', '1', 'schema', 'example'],
}),
]),
);
Expand Down
4 changes: 2 additions & 2 deletions src/functions/__tests__/schema-path.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('schema', () => {
};
expect(runSchemaPath(target, fieldToCheck, path)).toEqual([
{
path: [],
path: ['example'],
message: "should have required property 'url'",
},
]);
Expand All @@ -79,7 +79,7 @@ describe('schema', () => {
expect(runSchemaPath(target, fieldToCheck, path)).toEqual([
{
message: 'format should match format "url"',
path: [],
path: ['example'],
},
]);
});
Expand Down
7 changes: 7 additions & 0 deletions src/functions/schema-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,12 @@ export const schemaPath: IFunction<ISchemaPathOptions> = (targetVal, opts, paths
console.error(error);
}

if (opts.field) {
paths.given.push(opts.field);
if (paths.target) {
paths.target.push(opts.field);
}
}

return schema(relevantObject, { schema: schemaObject }, paths, otherValues);
};
3 changes: 2 additions & 1 deletion src/rulesets/oas2/__tests__/valid-example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ describe('valid-example', () => {
expect(results).toEqual([
expect.objectContaining({
code: 'valid-example',
message: '"c" property type should be string',
message: '"example" property type should be string',
path: [
'paths',
'/pet',
Expand All @@ -236,6 +236,7 @@ describe('valid-example', () => {
'b',
'properties',
'c',
'example',
],
range: expect.any(Object),
severity: DiagnosticSeverity.Warning,
Expand Down
6 changes: 3 additions & 3 deletions src/rulesets/oas3/__tests__/valid-example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ describe('valid-example', () => {
expect(results).toEqual([
expect.objectContaining({
code: 'valid-example',
message: '"schema" property format should match format "email"',
path: ['paths', '/pet', 'post', 'requestBody', 'content', '*/*', 'schema'],
message: '"example" property format should match format "email"',
path: ['paths', '/pet', 'post', 'requestBody', 'content', '*/*', 'schema', 'example'],
range: expect.any(Object),
severity: DiagnosticSeverity.Warning,
}),
Expand Down Expand Up @@ -169,7 +169,7 @@ describe('valid-example', () => {
expect(results).toEqual([
expect.objectContaining({
code: 'valid-example',
message: `"ip_address" property format should match format "${format}"`,
message: `"example" property format should match format "${format}"`, // hm, ip_address is likely to be more meaningful no?
}),
]);
},
Expand Down

0 comments on commit 0e3844f

Please sign in to comment.