From 4dc2b7254653f6a22e1dbac3b8fa23e3e98928a1 Mon Sep 17 00:00:00 2001 From: Tokesh Date: Mon, 20 Jan 2025 00:01:56 +0500 Subject: [PATCH] chore: getting back files Signed-off-by: Tokesh --- tools/src/linter/SchemaVisitingValidator.ts | 27 ++++++++----------- .../InlineObjectSchemaValidator.test.ts | 12 ++++++++- .../namespaces/ops.yaml | 11 +++++--- 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/tools/src/linter/SchemaVisitingValidator.ts b/tools/src/linter/SchemaVisitingValidator.ts index bf3beff82..f946fa7aa 100644 --- a/tools/src/linter/SchemaVisitingValidator.ts +++ b/tools/src/linter/SchemaVisitingValidator.ts @@ -48,7 +48,6 @@ export default class SchemaVisitingValidator { ...this._namespaces_folder.files, ...this._schemas_folder.files ].forEach(f => { visitor.visit_specification(new SpecificationContext(f.file), f.spec()) }) - return errors } @@ -73,27 +72,23 @@ export default class SchemaVisitingValidator { } if (schema.type === 'number') { - if (schema.format === undefined || SCHEMA_NUMBER_FORMATS.includes(schema.format)) { - return + if (schema.format == null || !schema.format) { + errors.push(ctx.error(`Schema of type 'number' must specify a valid format. Allowed formats: ${SCHEMA_NUMBER_FORMATS.join(', ')}`)); + return; } - - if (SCHEMA_INTEGER_FORMATS.includes(schema.format)) { - errors.push(ctx.error(`schema of type 'number' with format '${schema.format}' should instead be of type 'integer'`)) - } else { - errors.push(ctx.error(`schema of type 'number' with format '${schema.format}' is invalid, expected one of: ${SCHEMA_NUMBER_FORMATS.join(', ')}`)) + if (!SCHEMA_NUMBER_FORMATS.includes(schema.format)) { + errors.push(ctx.error(`Schema of type 'number' with format '${schema.format}' is invalid. Expected one of: ${SCHEMA_NUMBER_FORMATS.join(', ')}`)); } } if (schema.type === 'integer') { - if (schema.format === undefined || SCHEMA_INTEGER_FORMATS.includes(schema.format)) { - return + if (schema.format == null || !schema.format) { + errors.push(ctx.error(`Schema of type 'integer' must specify a valid format. Allowed formats: ${SCHEMA_INTEGER_FORMATS.join(', ')}`)); + return; } - - if (SCHEMA_NUMBER_FORMATS.includes(schema.format)) { - errors.push(ctx.error(`schema of type 'integer' with format '${schema.format}' should instead be of type 'number'`)) - } else { - errors.push(ctx.error(`schema of type 'integer' with format '${schema.format}' is invalid, expected one of: ${SCHEMA_INTEGER_FORMATS.join(', ')}`)) + if (!SCHEMA_INTEGER_FORMATS.includes(schema.format)) { + errors.push(ctx.error(`Schema of type 'integer' with format '${schema.format}' is invalid. Expected one of: ${SCHEMA_INTEGER_FORMATS.join(', ')}`)); } } } -} +} \ No newline at end of file diff --git a/tools/tests/linter/InlineObjectSchemaValidator.test.ts b/tools/tests/linter/InlineObjectSchemaValidator.test.ts index 7e3b2514c..efd44f954 100644 --- a/tools/tests/linter/InlineObjectSchemaValidator.test.ts +++ b/tools/tests/linter/InlineObjectSchemaValidator.test.ts @@ -32,10 +32,20 @@ test('validate()', () => { location: '#/paths/~1the~1path/post/responses/200/content/application~1json/schema/properties/inline_object_as_a_property_is_not_ok', message: 'object schemas should be defined out-of-line via a $ref' }, + { + file: 'namespaces/ops.yaml', + location: '#/components/parameters/query.ref_object_is_ok/schema/properties/setting', + message: `Schema of type 'integer' must specify a valid format. Allowed formats: int32, int64`, + }, + { + file: 'namespaces/ops.yaml', + location: '#/components/parameters/query.ref_object_is_ok/schema/properties/bytes', + message: `Schema of type 'number' must specify a valid format. Allowed formats: float, double` + }, { file: 'schemas/schemas.yaml', location: '#/components/schemas/additionalProperties_with_object_value_schema_can_not_be_inline/additionalProperties', message: 'object schemas should be defined out-of-line via a $ref' } ]) -}) +}) \ No newline at end of file diff --git a/tools/tests/linter/fixtures/inline_object_schema_validator/namespaces/ops.yaml b/tools/tests/linter/fixtures/inline_object_schema_validator/namespaces/ops.yaml index 7c8a2a59e..62a749f6f 100644 --- a/tools/tests/linter/fixtures/inline_object_schema_validator/namespaces/ops.yaml +++ b/tools/tests/linter/fixtures/inline_object_schema_validator/namespaces/ops.yaml @@ -29,7 +29,8 @@ paths: type: object properties: item_prop: - type: number + type: integer + format: int32 responses: '200': content: @@ -57,6 +58,8 @@ components: properties: setting: type: integer + bytes: + type: number requestBodies: obj: content: @@ -65,7 +68,8 @@ components: type: object properties: prop: - type: number + type: integer + format: int32 responses: obj@200: content: @@ -74,4 +78,5 @@ components: type: object properties: prop: - type: number \ No newline at end of file + type: integer + format: int64 \ No newline at end of file