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.

Receiving warning: oasOpParams expects a resolved object

See original GitHub issue

I’m submitting a bug report

What is the current behavior?

I am currently migrating my API specification and running into this warning:

oasOpParams expects a resolved object, but none was provided. Results may not be correct.
oasPathParam expects a resolved object, but none was provided. Results may not be correct.

There are no $ref mentions in my spec, so I am confused as to why I am getting this error. The code is as follows.

What is the expected behavior?

For this not to error

Please tell us about your environment:

  • Version: @stoplight/spectral": "^1.0.1"
  • Framework: Node v11.7.0
  • Language: Node v11.7.0

Other information

My code:

// Load Spectral and its OAS3 validations
const { Spectral } = require('@stoplight/spectral')
const { oas3Functions, oas3Rules } = require('@stoplight/spectral/rulesets/oas3')

// Find all OpenAPI files
const fs = require('fs')
const glob = require('glob')

const lint = async () => {
  const fileNames = await new Promise((resolve, reject) => {
    glob('./v2.0/*.openapi.json', {}, (error, match) => {
      if (error) { reject(error) }
      else { resolve(match) }
    })
  })
  
  // Initialize Spectral
  const spectral = new Spectral()
  spectral.addFunctions(oas3Functions())
  spectral.addRules(oas3Rules())
  
  fileNames.forEach(fileName => {
    let specification = JSON.parse(fs.readFileSync(fileName))
    const results = spectral.run(specification)
    // console.dir(results)
  })  
}

lint()

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
marbemaccommented, Feb 4, 2019

Hi @cbetta - great question, and this is something that we could certainly be more clear about (will open a separate PR for readme).

Certain rules (like those param rules you mentioned above) need both the resolved and unresolved document in order to function. Since you don’t have any $refs in your document, you should be able to supply it as the resolved version like so:

const results = spectral.run(specification, { resolvedTarget: specification });

You can find the run signature here: https://github.com/stoplightio/spectral/blob/next/src/spectral.ts#L21.

I’m now wondering if we shouldn’t just default resolvedTarget to the passed in document if resolvedTarget is not explicitly set.

Let me know if the above works for you for now!

0reactions
tbarncommented, Apr 12, 2019

@cbetta Glad to hear the improvements worked.

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - Expect and should use the Promise object instead of ...
I found the mistake. The problem is that the correct syntax is not .should.to.be but has to be .should.eventually.be.
Read more >
The spectral from stoplightio - Giter VIP
oasOpParams expects a resolved object, but none was provided. Results may not be correct. oasPathParam expects a resolved object, but none was provided....
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