Support for hateoas style
Closed this issue · 3 comments
Hi,
would you be able to suggest how to write a rule that accepts hateoas fields, like "_link" and "_embedded", but at the same time validate the casing of other properties in a schema?
For instance, I'd like to enforce a camel casing for this entity, but also accept words starting with "_".
components:
schemas:
Application:
type: object
properties:
applicationId:
type: string
_links:
type: object
properties:
self:
$ref: '#/components/schemas/Link'
ApplicationResponse:
properties:
application:
$ref: '#/components/schemas/Application'
Link:
type: object
properties:
href:
type: string
Thanks
Hi @michelecurioni, I think you have two options here. Depending on the version of the validator you're using, we use Spectral's casing
function to perform the validations. You may be able to customize the rule to provide greater specificity about the convention used.
If that doesn't work, a less elegant but still effective solution would be to use Spectral overrides
. The tool supports this feature - you can ignore properties on a case-by-case basis.
I created this custom rule that seems to do the trick:
'property-case-convention': {
description: 'Property names must follow camel case',
message: '{{error}}',
resolved: true,
given: schemas,
severity: 'error',
then: {
function: propertyCaseConvention,
functionOptions: {
type: 'camel',
separator: {
char: '_',
allowLeading: true
}
}
}
}
Great!