question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Schema Function Not Working with @key

See original GitHub issue

Describe the bug

The schema function doesn’t appear to work when field is '@key'. Here’s the rule I’m trying to create:

  response-code-type:
    message: Response codes must be strings
    recommended: true
    given: $.paths.*.*.responses
    then:
      field: '@key'
      function: schema
      functionOptions:
        schema:
          type: string

To Reproduce

Given this OpenAPI document

openapi: 3.0.2
info:
  title: Test Spec
  version: 0.0.0
paths:
  /foo:
    get:
      operationId: get-foo
      responses:
        200:
          description: ''

Run this CLI command

spectral lint test-spec.yaml -r my-rules.yaml

Expected behavior

The lint output should contain the following:

 9:17  warning  response-code-type    Response codes must be strings

It might be worth noting that if the rule is changed so that type is number or integer, the rule is triggered.

Environment

  • Library version: 4.2.0
  • OS: Windows 10

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
P0lipcommented, Dec 4, 2019

@dillonredding This one will be addressed as well, but in a slightly different manner. Spectral will warn you about property keys that are not JSON compliant (are no strings in other words). I hope that will do the trick for you.

0reactions
P0lipcommented, Dec 5, 2019

@dillonredding no rule will be needed. Each property key that could not be used in JSON will be reported automatically by Spectral

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mongoose Schema.method() is not working, and showing an ...
I run this code, it's working fine and am able to store encrypted password in this.encry_password property. But, the problem is that before ......
Read more >
Mongoose v6.8.1: Schemas
If you want to add additional keys later, use the Schema#add method. ... method will not have access to the document and the...
Read more >
Why does Mongoose remove the key when specified in the ...
When I specify the schema for an array of objects (may be doing this wrong), that particular key and all the data with...
Read more >
Documentation: 15: 5.9. Schemas - PostgreSQL
When you run an ordinary query, a malicious user able to create objects in a schema of your search path can take control...
Read more >
[Solved] DynamoDB Key element does not match the schema
it will fail because it does not have the "pk" attribute which is required. In case you're inserting an item with all the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found