Check allOf in az-schema-type-and-format
This commit is contained in:
Родитель
4ee585a4d4
Коммит
b530de7791
|
@ -72,5 +72,14 @@ module.exports = function checkTypeAndFormat(schema, options, { path }) {
|
|||
}
|
||||
}
|
||||
|
||||
if (schema.allOf && Array.isArray(schema.allOf)) {
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (const [index, value] of schema.allOf.entries()) {
|
||||
errors.push(
|
||||
...checkTypeAndFormat(value, options, { path: [...path, 'allOf', index] }),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return errors;
|
||||
};
|
||||
|
|
|
@ -41,6 +41,16 @@ test('az-schema-type-and-format should find errors', () => {
|
|||
type: 'number',
|
||||
},
|
||||
},
|
||||
allOf: [
|
||||
{
|
||||
properties: {
|
||||
prop5: {
|
||||
type: 'string',
|
||||
format: 'email',
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
|
@ -79,15 +89,29 @@ test('az-schema-type-and-format should find errors', () => {
|
|||
$ref: '#/definitions/PropZZ',
|
||||
},
|
||||
},
|
||||
allOf: [
|
||||
{
|
||||
$ref: '#/definitions/ModelA',
|
||||
},
|
||||
],
|
||||
},
|
||||
PropZZ: {
|
||||
type: 'string',
|
||||
format: 'ZZTop',
|
||||
},
|
||||
ModelA: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
id: {
|
||||
type: 'string',
|
||||
format: 'guid',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
return linter.run(oasDoc).then((results) => {
|
||||
expect(results.length).toBe(8);
|
||||
expect(results.length).toBe(10);
|
||||
expect(results[0].path.join('.')).toBe('paths./test1.post.parameters.0.schema.properties.prop1.format');
|
||||
expect(results[0].message).toBe('Schema with type: integer has unrecognized format: int52');
|
||||
expect(results[1].path.join('.')).toBe('paths./test1.post.parameters.0.schema.properties.prop2.properties.prop3.format');
|
||||
|
@ -96,14 +120,18 @@ test('az-schema-type-and-format should find errors', () => {
|
|||
expect(results[2].message).toBe('Schema with type: boolean should not specify format');
|
||||
expect(results[3].path.join('.')).toBe('paths./test1.post.parameters.0.schema.properties.prop4');
|
||||
expect(results[3].message).toBe('Schema with type: number should specify format');
|
||||
expect(results[4].path.join('.')).toBe('paths./test1.post.responses.200.schema.properties.propW.format');
|
||||
expect(results[4].message).toBe('Schema with type: number has unrecognized format: exponential');
|
||||
expect(results[5].path.join('.')).toBe('paths./test1.post.responses.200.schema.properties.propX.properties.propY.format');
|
||||
expect(results[5].message).toBe('Schema with type: string has unrecognized format: secret');
|
||||
expect(results[6].path.join('.')).toBe('paths./test1.post.responses.200.schema.properties.propZ');
|
||||
expect(results[6].message).toBe('Schema with type: integer should specify format');
|
||||
expect(results[7].path.join('.')).toBe('paths./test1.post.responses.200.schema.properties.propZZ.format');
|
||||
expect(results[7].message).toBe('Schema with type: string has unrecognized format: ZZTop');
|
||||
expect(results[4].path.join('.')).toBe('paths./test1.post.parameters.0.schema.allOf.0.properties.prop5.format');
|
||||
expect(results[4].message).toBe('Schema with type: string has unrecognized format: email');
|
||||
expect(results[5].path.join('.')).toBe('paths./test1.post.responses.200.schema.allOf.0.properties.id.format');
|
||||
expect(results[5].message).toBe('Schema with type: string has unrecognized format: guid');
|
||||
expect(results[6].path.join('.')).toBe('paths./test1.post.responses.200.schema.properties.propW.format');
|
||||
expect(results[6].message).toBe('Schema with type: number has unrecognized format: exponential');
|
||||
expect(results[7].path.join('.')).toBe('paths./test1.post.responses.200.schema.properties.propX.properties.propY.format');
|
||||
expect(results[7].message).toBe('Schema with type: string has unrecognized format: secret');
|
||||
expect(results[8].path.join('.')).toBe('paths./test1.post.responses.200.schema.properties.propZ');
|
||||
expect(results[8].message).toBe('Schema with type: integer should specify format');
|
||||
expect(results[9].path.join('.')).toBe('paths./test1.post.responses.200.schema.properties.propZZ.format');
|
||||
expect(results[9].message).toBe('Schema with type: string has unrecognized format: ZZTop');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -141,6 +169,15 @@ test('az-schema-type-and-format should find no errors', () => {
|
|||
format: 'float',
|
||||
},
|
||||
},
|
||||
allOf: [
|
||||
{
|
||||
properties: {
|
||||
prop5: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
|
@ -180,11 +217,25 @@ test('az-schema-type-and-format should find no errors', () => {
|
|||
$ref: '#/definitions/PropZZ',
|
||||
},
|
||||
},
|
||||
allOf: [
|
||||
{
|
||||
$ref: '#/definitions/ModelA',
|
||||
},
|
||||
],
|
||||
},
|
||||
PropZZ: {
|
||||
type: 'string',
|
||||
format: 'url',
|
||||
},
|
||||
ModelA: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
id: {
|
||||
type: 'string',
|
||||
format: 'uuid',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
return linter.run(oasDoc).then((results) => {
|
||||
|
|
Загрузка…
Ссылка в новой задаче