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

Receiving warning: oasOpParams expects a resolved object #88

Closed
cbetta opened this issue Feb 4, 2019 · 10 comments · Fixed by #112
Closed

Receiving warning: oasOpParams expects a resolved object #88

cbetta opened this issue Feb 4, 2019 · 10 comments · Fixed by #112
Labels

Comments

@cbetta
Copy link

cbetta commented Feb 4, 2019

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()
@marbemac
Copy link
Contributor

marbemac commented 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!

@cbetta
Copy link
Author

cbetta commented Feb 6, 2019

Ah yes that works. The documentation wasn't quite up to date on this indeed.

@tbarn
Copy link
Contributor

tbarn commented Feb 13, 2019

I'm adding a FAQ (or maybe putting it in the code sample) for this right now.

@cbetta
Copy link
Author

cbetta commented Feb 14, 2019

Did I miss something? I don't see anything added.

@tbarn
Copy link
Contributor

tbarn commented Feb 14, 2019

PR #89 isn't merged yet, but that should help some. We might be adding one more thing to it.

@cbetta
Copy link
Author

cbetta commented Feb 15, 2019

Ah excellent, just confused cause you said "right now". I hadn't spotted the PR.

philsturgeon pushed a commit that referenced this issue Mar 19, 2019
Users were not expecting to need to pass in the optional resolvedTarget, and it would provide
warnings on some rules even when there were no $ref's in there. This will automatically resolve
local refs and dereference them too, which is then an object some rules can chose to look at instead
of the original object.

BREAKING CHANGE: The spectral.run() method is now async, so the await keyword must be prepended.

fix #88
philsturgeon pushed a commit that referenced this issue Mar 19, 2019
Users were not expecting to need to pass in the optional resolvedTarget, and it would provide
warnings on some rules even when there were no $ref's in there. This will automatically resolve
local refs and dereference them too, which is then an object some rules can chose to look at instead
of the original object.

BREAKING CHANGE: The spectral.run() method is now async, so the await keyword must be prepended.

fix #88
philsturgeon pushed a commit that referenced this issue Mar 20, 2019
…ct (#99)

* feat(run): run is async, no longer need resolvedTarget

Users were not expecting to need to pass in the optional resolvedTarget, and it would provide
warnings on some rules even when there were no $ref's in there. This will automatically resolve
local refs and dereference them too, which is then an object some rules can chose to look at instead
of the original object.

BREAKING CHANGE: The spectral.run() method is now async, so the await keyword must be prepended.

fix #88
@philsturgeon philsturgeon mentioned this issue Mar 27, 2019
2 tasks
@philsturgeon
Copy link
Contributor

Hey folks, just to give you an update: the release/2.0 is getting more mature, so if you would like to check it out your troubles should be over. run now returns a promise, so make sure you add await. It is no longer an object with .results, it just an array.

Before

const spectral = new Spectral();
results = spectral.run(obj);
console.log(results.results);

v2.0

const spectral = new Spectral();
results = await spectral.run(obj);
console.log(results);

Please post new issues with any new bugs you find in there, but this is considered done (and will be closed when v2.0 is merged).

philsturgeon pushed a commit that referenced this issue Mar 28, 2019
…ct (#99)

* feat(run): run is async, no longer need resolvedTarget

Users were not expecting to need to pass in the optional resolvedTarget, and it would provide
warnings on some rules even when there were no $ref's in there. This will automatically resolve
local refs and dereference them too, which is then an object some rules can chose to look at instead
of the original object.

BREAKING CHANGE: The spectral.run() method is now async, so the await keyword must be prepended.

fix #88
@stoplight-bot
Copy link
Collaborator

🎉 This issue has been resolved in version 2.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@cbetta
Copy link
Author

cbetta commented Apr 12, 2019

Upgraded and all works 👍

@tbarn
Copy link
Contributor

tbarn commented Apr 12, 2019

@cbetta Glad to hear the improvements worked.

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

Successfully merging a pull request may close this issue.

5 participants