openapi-typescript icon indicating copy to clipboard operation
openapi-typescript copied to clipboard

Redocly not using auth headers from env var when trying to pull a yaml from a private repo

Open haggs opened this issue 1 year ago • 3 comments

Description

I'm trying to use a redocly.yaml to fetch an OpenAPI yaml from a private company repo, and it doesn't seem that my env var with my access token is being used.

<redacted>/node_modules/@redocly/openapi-core/lib/resolve.js:123
                throw new ResolveError(error);
                      ^

ResolveError: Failed to load <redacted file url>: 404 Not Found

Here's my redocly yaml:

apis:
  core@v2:
    root: <redacted yaml URL>
    x-openapi-ts:
      output: ./generated.d.ts
resolve:
  http:
    headers:
      - matches: <redacted yaml URL domain with /**>
        name: PRIVATE-TOKEN
        envVariable: <redacted env var name>

Using the openapi-typescript debug env var, I can see that the redocly yaml is being loaded. I can also see that my env var exists and is correctly set when I run npx openapi-typescript I can curl the same url and the same PRIVATE-TOKEN header value and successfully fetch the file. It's almost as if my env var isn't being passed along to redocly.

Name Version
openapi-typescript 7.0.0-next.7
Node.js 20.10.0
OS + version macOS 13.6.3

Reproduction

Run npx openapi-typescript with the above redocly yaml, from a private repo.

Expected result

It should be able to fetch the file using the auth header defined by env var in redocly.yaml

Checklist

haggs avatar Feb 15 '24 18:02 haggs

I am also experiencing this. Looks like this is the cause:

// index.js

export default async function openapiTS(source, options = {}) {
    if (!source) {
        throw new Error("Empty schema. Please specify a URL, file path, or Redocly Config");
    }
    const redoc = options.redocly ?? // this should be options.redoc
        (await createConfig({
            rules: {
                "operation-operationId-unique": { severity: "error" },
            },
        }, { extends: ["minimal"] }));

kpervin avatar Feb 20 '24 16:02 kpervin

It's almost as if my env var isn't being passed along to redocly.

Ah that’s a very good guess; at least the right path of inquiry. Though the config gets resolved and loaded, it’s very likely that passing through openapi-typescript the env vars aren’t set properly. Would welcome a PR for anyone willing to investigate this! This is a good first issue for someone.

drwpow avatar Mar 06 '24 05:03 drwpow

Found a related Redocly config issue, fixed in #1635. Will push a release shortly that should fix this, hopefully? But let me know if the problem persists

drwpow avatar Apr 29 '24 04:04 drwpow