Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Camel case function does not accommodate uppercase single letter words at the end of a property name #1500

Closed
SensibleWood opened this issue Feb 3, 2021 · 0 comments · Fixed by #1506
Assignees
Labels
t/bug Something isn't working
Milestone

Comments

@SensibleWood
Copy link

SensibleWood commented Feb 3, 2021

Describe the bug

When using the built-in function casing with the argument camel Spectral raises an error when it encounters a single, uppercase word at the end of the camel-cased string. For example:

  • coordinateX
  • scaleY

To Reproduce

Using the following OpenAPI document:

openapi: 3.0.3
info:
  title: Spectral evidence
  description: Noddy API to use in Spectral ticket
  version: 0.0.1
paths:
  /:
    get:
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  coordinateX:
                    type: string
                  scaleY:
                    type: string

And the following ruleset:

extends: spectral:oas
rules:
  operation-operationId: off
  oas3-api-servers: off
  info-contact: off
  operation-description: off
  operation-tags: off
  camel-case-enforcement:
    message: "Property is not named in lower camel case: {{path}}, {{property}}"
    severity: error
    given: $..[?(@.type === 'object' && @.properties)].properties.*~
    then:
      function: casing
      functionOptions:
        type: camel

Executing Spectral gives the following output:

➜  spectral-evidence spectral lint --ruleset ./evidence.yaml openapi.yaml
OpenAPI 3.x detected

/Users/chris/Documents/git/github/spectral-evidence/openapi.yaml
 22:31  error  camel-case-enforcement  Property is not named in lower camel case: #/paths/~1/get/responses/200/content/application~1json/schema/properties/coordinateX, coordinateX  paths./.get.responses[200].content.application/json.schema.properties.coordinateX
 24:26  error  camel-case-enforcement  Property is not named in lower camel case: #/paths/~1/get/responses/200/content/application~1json/schema/properties/scaleY, scaleY            paths./.get.responses[200].content.application/json.schema.properties.scaleY

✖ 2 problems (2 errors, 0 warnings, 0 infos, 0 hints)

➜  spectral-evidence

I think this is the root of the issue: here - the regex should allow end of line I guess i.e. ([a-z{__DIGITS__}]+|$)

Expected behavior

The ruleset should not raise the camel-case-enforcement errors as semantically the property names are correct.

Environment:

  • Node version: 12.20.0
  • Library version: 5.7.2
  • OS: macOs Catalina 10.15.7
@SensibleWood SensibleWood added the t/bug Something isn't working label Feb 3, 2021
@SensibleWood SensibleWood changed the title Camel case function does not accommodate single letter words Camel case function does not accommodate uppercase single letter words Feb 4, 2021
@SensibleWood SensibleWood changed the title Camel case function does not accommodate uppercase single letter words Camel case function does not accommodate uppercase single letter words at the end of a property name Feb 4, 2021
@P0lip P0lip self-assigned this Feb 15, 2021
@P0lip P0lip added this to the 2021-02-02 milestone Feb 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
t/bug Something isn't working
Projects
None yet
2 participants