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

$.header is undefined #1160

Closed
NicholasRasi opened this issue Jan 16, 2025 · 7 comments
Closed

$.header is undefined #1160

NicholasRasi opened this issue Jan 16, 2025 · 7 comments

Comments

@NicholasRasi
Copy link

NicholasRasi commented Jan 16, 2025

The value of $.header is undefined even if the header is sent with the request.

Test

counterfact https://petstore3.swagger.io/api/v3/openapi.json api

The DELETE /pet/{petId} sends the api_key header.

If I log the value of $.header to the console it is undefined.

api/routes/pet/{petId}.ts

export const DELETE: HTTP_DELETE = ($) => {
  console.log($.header)
  return $.response[400];
};

If I log $ the api_key header is present.:

{
  auth: undefined,
  body: {},
  context: Context {},
  headers: {
    host: 'localhost:3100',
    'user-agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:133.0) Gecko/20100101 Firefox/133.0',
    accept: '*/*',
    'accept-language': 'en-US,en;q=0.5',
    'accept-encoding': 'gzip, deflate, br, zstd',
    referer: 'http://localhost:3100/counterfact/swagger/',
    api_key: 'aaa',
    origin: 'http://localhost:3100',
    dnt: '1',
    connection: 'keep-alive',
    cookie: 'sxid=MTczNTI5NjY1NHxxQ3JRcjJFMFRab190SDA0RkM3SmhCMWZsSW5sNjJXMlNsZl9HWW5GM1ZyS1JucVNFRHNMaVZHcFl1U0lNZHVQUUZvVzkwNllyUkhkem9QN1k3bmFHYTMwaXd1WC1QcmVPZVI4cnpRS1g4bFpJd3M9fCk8W1YWYJ4QRaPk6tG_HnyW4vsmuKF8gzVlvZZDTEuP',
    'sec-fetch-dest': 'empty',
    'sec-fetch-mode': 'cors',
    'sec-fetch-site': 'same-origin',
    priority: 'u=0'
  },
  proxy: [AsyncFunction: proxy],
  query: {},
  response: {},
  tools: Tools {
    headers: {
      host: 'localhost:3100',
      'user-agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:133.0) Gecko/20100101 Firefox/133.0',
      accept: '*/*',
      'accept-language': 'en-US,en;q=0.5',
      'accept-encoding': 'gzip, deflate, br, zstd',
      referer: 'http://localhost:3100/counterfact/swagger/',
      api_key: 'aaa',
      origin: 'http://localhost:3100',
      dnt: '1',
      connection: 'keep-alive',
      cookie: 'sxid=MTczNTI5NjY1NHxxQ3JRcjJFMFRab190SDA0RkM3SmhCMWZsSW5sNjJXMlNsZl9HWW5GM1ZyS1JucVNFRHNMaVZHcFl1U0lNZHVQUUZvVzkwNllyUkhkem9QN1k3bmFHYTMwaXd1WC1QcmVPZVI4cnpRS1g4bFpJd3M9fCk8W1YWYJ4QRaPk6tG_HnyW4vsmuKF8gzVlvZZDTEuP',
      'sec-fetch-dest': 'empty',
      'sec-fetch-mode': 'cors',
      'sec-fetch-site': 'same-origin',
      priority: 'u=0'
    }
  },
  matchedPath: '/pet/{petId}',
  path: { petId: '1' },
  x: [Circular *1]
}

v1.1.5

Could you help me?

@dethell
Copy link
Collaborator

dethell commented Jan 16, 2025

It might need to be plural: $.headers.

If that doesn't work can you attempt to access it through $.x.headers:

console.log($.x.headers)

@NicholasRasi
Copy link
Author

With $.headers it works but the IDE reports this:

Property 'headers' does not exist on type 'OmitValueWhenNever<{ query: never; path: { petId: string; }; header: { api_key?: string | undefined; }; body: never; context: Context; response: ResponseBuilderFactory<{ 400: { headers: never; requiredHeaders: never; content: never; }; }>; x: WideOperationArgument; proxy: (url: string) => { ...; }; user: never; }>'. Did you mean 'header'?ts(2551)

Indeed, header is not defined:

export type HTTP_DELETE = (
  $: OmitValueWhenNever<{
    query: never;
    path: { petId: string };
    header: { api_key?: string };
    body: never;
    context: Context;
    response: ResponseBuilderFactory<{
      400: {
        headers: never;
        requiredHeaders: never;
        content: never;
      };
    }>;
    x: WideOperationArgument;
    proxy: (url: string) => COUNTERFACT_RESPONSE;
    user: never;
  }>,
)

@dethell
Copy link
Collaborator

dethell commented Jan 16, 2025

Yeah, I think this is a bug.

@NicholasRasi
Copy link
Author

NicholasRasi commented Jan 16, 2025

Yeah, I think this is a bug.

Yes, I think so.

@pmcelhaney if you think you will fix it, please let me know.

Thank you for this project, I'm using it to develop the mockup for an API and it is very useful and straightforward.

@pmcelhaney
Copy link
Owner

Thanks for bringing this to my attention. It should be fixed in 1.1.6 (as soon as #1161 is merged).

pmcelhaney added a commit that referenced this issue Jan 17, 2025
@pmcelhaney
Copy link
Owner

Fixed in 1.1.16

@NicholasRasi
Copy link
Author

@pmcelhaney in v1.1.16 the problem is fixed, now headers are accessible from $.headers.
However, if I send a header defined in the API as userId, the value is not accessible through $.headers.userId but $.headers.userid.

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

No branches or pull requests

3 participants