opticdev / optic

OpenAPI linting, diffing and testing. Optic helps prevent breaking changes, publish accurate documentation and improve the design of your APIs.
https://useoptic.com
MIT License
1.35k stars 79 forks source link

`optic lint` gets confused when I set `OPTIC_TOKEN` instead of the default config #2804

Closed balint-backmaker closed 6 months ago

balint-backmaker commented 6 months ago

Describe the bug

I found out that when setting OPTIC_TOKEN, the commands that depend on downloading standards from Optic breaks.

Bonus: despite the WARNING message, it fails the exit code so the messaging is a bit confusing.

To Reproduce

  1. run optic login to get yourself a personal access token
  2. run optic lint docs/openapi/openapi.yaml to prove it passes
  3. run export OPTIC_TOKEN=$(jq -r .token ~/.config/optic/config.json) to simulate what our CI does in place of having the file
  4. run optic lint docs/openapi/openapi.yaml again to prove it doesn't work

Funny enough, it works in CircleCI, but fails when I want to run it locally on my PC (matching the command between CI and local)

❯ LOG_LEVEL=debug optic lint docs/openapi/openapi.yaml
Using Optic version 0.54.12 - npm/yarn
{
  isDefaultConfig: true,
  root: '/home/balint/git/buyback-funnel',
  configPath: undefined,
  ruleset: undefined,
  isAuthenticated: true,
  client: OpticBackendClient {
    fetch: [AsyncFunction: fetch],
    source: 'optic',
    handleJsonResponse: [AsyncFunction: handleJsonResponse],
    baseUrl: 'https://api.useoptic.com',
    getAuthToken: [Function (anonymous)]
  },
  isInCi: false,
  authenticationType: 'env',
  userId: 'my-secret-token=',
  vcs: {
    type: 'git',
    sha: '9043c0fa880ecee0521ada7e7723e7e9511ed431',
    diffSet: Set(0) {}
  }
}
Linting spec docs/openapi/openapi.yaml...
Initializing rule runner with the following options
{
  options: {
    rulesetArg: undefined,
    specRuleset: '@back-market/back-market-primary-standard',
    config: {
      isDefaultConfig: true,
      root: '/home/balint/git/buyback-funnel',
      configPath: undefined,
      ruleset: undefined,
      isAuthenticated: true,
      client: [OpticBackendClient],
      isInCi: false,
      authenticationType: 'env',
      userId: 'my-secret-token=',
      vcs: [Object]
    },
    specVersion: '3.1.x'
  },
  checksEnabled: true
}
Warning: Could not download standard @back-market/back-market-primary-standard. Please check the ruleset name and whether you are authenticated (run: optic login).
{ standard: [] }
{ rulesToFetch: [], localRulesets: {}, hostedRulesets: {} }
✔ OpenAPI is valid
 ~/git/buyback-funnel  main !1 ············································································································································· ▼  3.12.0 Py  20.11.0 Node  17:18:03 
❯

Expected behavior I expect the two runs to behave exactly the same.

Screenshots N/A

Details (please complete the following information):

Additional context I'm developing a workflow where I'm using the official docker container that has both optic and spectral. I originally blamed docker for this (networking, or env variables etc), but then I ran it in my shell directly and it produced the same issue.

balint-backmaker commented 6 months ago

well, muppets be muppets. Missed it's base64 encoded