Schema Required property check no longer working
I am running spectral 5.8.1 and given the following schema:
schemas: Car: type: object required: - id - manufacturerName properties: id: description: The ID of the car type: string example: 'a123-4d567-c123' manufacturName: description: The name of the manufacturer type: string example: Ford
spectral is not complaining that required property manufacturerName is missing (typoed) It DOES error IF this schema is used as part of an array and a top level schema example doesnt have the property but not at this level. I am sure this worked before but does no longer show via the CLI or VS code plugin.
Full def is here if you want it https://app.swaggerhub.com/apis/AdvancedComputerSoft/demo-advanced-car-inventory/1.0.0#/Car
Similar problem here too.
User:
type: object
x-examples:
example:
value:
firstName: James
lastName: Smith
email: [email protected]
defaultId: a0b1c2d3e4-aa00-bb11-cc22-aabbccddeeff
properties:
firstName:
type: string
lastName:
type: string
locale:
type: string
email:
type: string
format: email
phone:
type: string
defaultId:
type: string
format: uuid
lastLogin:
type: string
required:
- email
Spectral is complaining in Stoplight that "user" property must have required property "email", which it does.
IF the defnition uses a lowercase u for User, the problem does not appear. I can see in the example above, the schema is using Car with an uppercase C.
I believe something is testing a variable with out accounting for case-sensitivity
schemas: Car: type: object required: - id - manufacturerName properties: id: description: The ID of the car type: string example: 'a123-4d567-c123' manufacturName: description: The name of the manufacturer type: string example: Ford
Alex, use a triple backtick on its own line for a code block opening (and closing), so the markdown doesn't pull out the \n from your YAML
I found the issue in my case
In our YAML (3000+ lines) there was a pointer to the schema $ref: /schema/User in an example response to an endpoint, so the ref check was looping back on itself.
Hello Guys, I'm facing the same problem, do you have any updates about the resolution? if yes, can you show an example of your valid schema?
Is there any workaround?
I use this rule to check that I don't forget to rename required properties when I fix case issues:
must-use-snake-case-for-required-property-names:
message: Required property name has to be ASCII snake_case
severity: error
given: $.paths.*.*[responses,requestBody]..content..schema..required.*
then:
function: pattern
functionOptions:
match: ^[a-z_][a-z_0-9]*$
Here is a complete example. Could you please fix this issue? It is quite annoying.
openapi: "3.0.0"
info:
title: Example
version: 2.0.0
contact:
email: [email protected]
description: default
servers:
- url: "https://default.com/v1"
description: "Development server"
tags:
- name: user
paths:
/users:
get:
operationId: get_users
x-openapi-router-controller: project.controllers.user_controller
tags:
- user
description: get user
responses:
'200':
description: successful operation
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/User'
# schema:
# $ref: '#/components/schemas/User'
components:
schemas:
User:
type: object
required:
- id # unknown field
- description # unknown field
properties:
name:
description: name
type: string
example: 'Pathloss'