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

Schema Required property check no longer working #1751

Open
savage-alex opened this issue Jul 21, 2021 · 6 comments
Open

Schema Required property check no longer working #1751

savage-alex opened this issue Jul 21, 2021 · 6 comments
Labels

Comments

@savage-alex
Copy link

savage-alex commented Jul 21, 2021

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

@dbryar
Copy link

dbryar commented Oct 13, 2021

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

@dbryar
Copy link

dbryar commented Oct 13, 2021

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

@dbryar
Copy link

dbryar commented Oct 15, 2021

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.

@JohnnysMartins
Copy link

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?

@nmoreaud
Copy link
Contributor

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]*$

@nmoreaud
Copy link
Contributor

nmoreaud commented Apr 3, 2023

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'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants