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

Add JSON Schema misconfigurations rules #33

Merged
merged 4 commits into from
Apr 26, 2024

Conversation

@adamaltman adamaltman requested a review from tatomyr April 22, 2024 15:52
Copy link
Contributor

@tatomyr tatomyr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few comments.

Copy link
Contributor

@tatomyr tatomyr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good addition, thanks!

Copy link
Collaborator

@lornajane lornajane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice - and I immediately caught a problem with the Museum API while testing this :)

@lornajane lornajane force-pushed the json-schema-misconfigurations branch from fe772e4 to d91ad7c Compare April 26, 2024 10:47
@lornajane lornajane merged commit 6a7f075 into main Apr 26, 2024
2 checks passed
@lornajane lornajane deleted the json-schema-misconfigurations branch April 26, 2024 10:48
@jeremyfiel
Copy link
Contributor

jeremyfiel commented May 15, 2024

Nice!

did you omit severity and message on purpose?

@jeremyfiel
Copy link
Contributor

jeremyfiel commented May 15, 2024

this throws a false positive with the following schema

  rule/json-schema-array-misconfiguration:
    subject: 
      type: Schema
    where: 
      - subject: 
          type: Schema
          property: type
        assertions:  
          const: array
    assertions: 
      disallowed: 
        - properties
type: object
properties:
  thing:
    type: array
    items:
      type: object // if this line is present, the error goes away. But this is not mandatory by the JSON Schema spec. 
      properties: {}

also throws with this schema

allOf:
- type: object
- properties: {}

@jeremyfiel
Copy link
Contributor

This rule throws a false positive

  rule/json-schema-object-with-items:
    severity: warn
    message: '"items" SHOULD NOT be used with "type: object"'
    suggest: 
      - properties
    subject:
      type: Schema
    where:
      - subject:
          type: Schema
          property: type
        assertions:
          const: object
    assertions:
      disallowed:
        - items
type: object
properties:
  thing3:
    items:
      properties: {}

@adamaltman
Copy link
Member Author

These are good points and might be added to the README. However, if I'm the type of person who has advanced lint rules, I'm probably the type of person who requires type: object to be explicitly defined when defining properties. (At least, I'm that type of person.)

I did intentionally omit message and severity (defaults to error).

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

Successfully merging this pull request may close these issues.

None yet

4 participants