Skip to content

Commit

Permalink
chore: adding back lint check and tests for them
Browse files Browse the repository at this point in the history
Signed-off-by: Tokesh <[email protected]>
  • Loading branch information
Tokesh committed Jan 22, 2025
1 parent 4930421 commit 031cd73
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
27 changes: 11 additions & 16 deletions tools/src/linter/SchemaVisitingValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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(', ')}`));
}
}
}
}
}
10 changes: 10 additions & 0 deletions tools/tests/linter/InlineObjectSchemaValidator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ 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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ paths:
type: object
properties:
item_prop:
type: number
type: integer
format: int32
responses:
'200':
content:
Expand Down Expand Up @@ -57,6 +58,8 @@ components:
properties:
setting:
type: integer
bytes:
type: number
requestBodies:
obj:
content:
Expand All @@ -65,7 +68,8 @@ components:
type: object
properties:
prop:
type: number
type: integer
format: int32
responses:
obj@200:
content:
Expand All @@ -74,4 +78,5 @@ components:
type: object
properties:
prop:
type: number
type: integer
format: int64

0 comments on commit 031cd73

Please sign in to comment.