Skip to content

Documentation: headers object should be getHeaders function in Client Options section of readme #82

Description

@aral

Hi there,

First off, thank you for making and sharing Massimo, it’s very elegant.

I’m using it to play with Hetzner’s OpenAPI spec:

npx massimo-cli https://docs.hetzner.cloud/cloud.spec.json --name hetzner

Based on the Client Options example in the readme, I initially wrote the following code:

import hetzner from 'hetzner'

const api = await hetzner({
  url: 'https://api.hetzner.cloud/v1/',
  headers: {
    Authorization: 'Bearer <actual token not shown but was entered correctly>'
  }
})

const result = await api.listDatacenters()
console.log(result)

This didn’t work (returns “token required” error).

Looking into the generated code, buildOpenAPIClient() is not passed a headers object from objects; only a getHeaders function.

The following, thus, works:

import hetzner from 'hetzner'

const api = await hetzner({
  url: 'https://api.hetzner.cloud/v1/',
  getHeaders: () => {
    return {
      Authorization: 'Bearer <actual token not shown but was entered correctly>'
    }
  }
})

const result = await api.listDatacenters()
console.log(result)

Unless I’m missing something, the Client Options section in the readme should be updated to reflect this.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions