spectral icon indicating copy to clipboard operation
spectral copied to clipboard

Spectral treats wrongly specially named properties

Open petkostas opened this issue 2 years ago • 2 comments

Spectral wrongly raises an error when using "reserved" fields as properties

properties:
  enum:
    type: object
    description: An object whose properties are the only possible values of a functionality.

Now spectral fails to understand that this is treated as a field of our schema, and raises an error treating it as a type (some values have been replaced with xxxx as they are internal for demonstration purposes):

 683:28  warning  duplicated-entry-in-enum  "enum" property type must be array  paths./xxxx.get.responses[200].content.application/json.examples['xxxxx'].value.xxxxx.enum
 698:28  warning  duplicated-entry-in-enum  "enum" property type must be array  paths./xxxx.get.responses[200].content.application/json.examples['xxxx'].value.xxxxx.enum
 731:28  warning  duplicated-entry-in-enum  "enum" property type must be array  paths./xxxx.get.responses[200].content.application/json.examples['xxxx'].value.xxxxx.enum

✖ 154 problems (89 errors, 65 warnings, 0 infos, 0 hints)

On the other hand, redoc linting is able to detect that the enum above is treated as a property (the 154 errors reported from spectral relate to the enum used a property).

Warning was generated by the tag-description rule.


./v2/schemas/xxxx/openapi.yaml: validated in 88ms

Woohoo! Your OpenAPI definition is valid. 🎉
You have 1 warning.

To Reproduce Create an object that uses enum (as an example) as it's property

properties:
  enum:
    type: object
    description: An object whose properties are the only possible values of a functionality.

Expected behavior The linter should not treat enum as the type but as a property

petkostas avatar Jul 05 '22 12:07 petkostas

@petkostas What version of spectral/ the individual spectral packages are you using? I'm having trouble reproducing this in the latest version of spectral

LukeMccon avatar Sep 04 '22 16:09 LukeMccon

Hello @LukeMccon, sorry for the late reply, I will run a test again today and get back to you if this has been solved in newer spectral versions.

petkostas avatar Oct 10 '22 08:10 petkostas