Skip to content

Commit

Permalink
Added validation: naming convention for parameters
Browse files Browse the repository at this point in the history
Signed-off-by: Theo Truong <[email protected]>
  • Loading branch information
nhtruong committed Apr 12, 2024
1 parent 8855d78 commit e29ebd7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
4 changes: 4 additions & 0 deletions tools/linter/components/NamespaceFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ export default class NamespaceFile extends FileValidator {
return this.error(
`Parameter component '${name}' must be named '${expected}' since it is a ${p.in} parameter named '${p.name}'.`,
`#/components/parameters/#${name}`);
if(!p.name.match(/^[a-z0-9._]+$/))
return this.error(
`Invalid parameter name '${p.name}'. A parameter's name can only contain lower-cased alphanumerics, underscores, and dots`,
`#/components/parameters/#${name}`);
}).filter((e) => e) as ValidationError[];
}
}
11 changes: 8 additions & 3 deletions tools/test/linter/NamespaceFile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,14 @@ test('validate_parameter_refs()', () => {
const validator = namespace_file('invalid_components.yaml');
expect(validator.validate_parameter_refs()).toEqual([
{
"file": `namespaces/invalid_components.yaml`,
"location": `#/components/parameters/#indices.create::query.h`,
"message": `Parameter component 'indices.create::query.h' must be named 'indices.create::query.v' since it is a query parameter named 'v'.`
file: "namespaces/invalid_components.yaml",
location: "#/components/parameters/#indices.create::query.ExpandWildcards",
message: "Invalid parameter name 'ExpandWildcards'. A parameter's name can only contain lower-cased alphanumerics, underscores, and dots"
},
{
file: "namespaces/invalid_components.yaml",
location: "#/components/parameters/#indices.create::query.h",
message: "Parameter component 'indices.create::query.h' must be named 'indices.create::query.v' since it is a query parameter named 'v'."
}
]);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ paths:
$ref: '#/components/responses/indices.create@200'
parameters:
- $ref: '#/components/parameters/indices.create::path.index'
- $ref: '#/components/parameters/indices.create::query.ExpandWildcards'
- $ref: '#/components/parameters/indices.create::query.pretty'

components:
Expand All @@ -15,6 +16,9 @@ components:
indices.create::path.index:
name: index
in: path
indices.create::query.ExpandWildcards:
name: ExpandWildcards
in: query
indices.create::query.h:
name: v
in: query

0 comments on commit e29ebd7

Please sign in to comment.