1

I'm tring to use spectral to make all the property names in request and response to match sneak_case name convention, but I am not able to get the syntax right. I have the following config file for spectral:

extends: ["spectral:oas", "spectral:asyncapi"]
rules:
  snake-case-for-keys:
    description: Keys must use snake_case
    severity: error
    given: $.schemas.*.properties.*
    then:
      field: '@key'
      function: pattern
      functionOptions:
        match: '^[a-z_\/{}]*$'

What I want is that if you write the following:

components:
  schemas:
    SomeSchema:
      type: array
      items:
        type: object
        properties:
           someProperty:
            type: string

Then it fails because someProperty should be written like some_property. For now I think checking that on the schemas is enough, but not sure if I should check it also on all the responses and requests too. Any idea how to achieve this behaviour? I suppose I have a wrong given clause in my rule.

Antonio Gamiz Delgado
  • 1,871
  • 1
  • 12
  • 33

0 Answers0