danielgtaylor / openapi-cli-generator

Generate a CLI from an OpenAPI 3 specification
MIT License
179 stars 49 forks source link

How to setup the credentials file? #38

Open myrho opened 3 years ago

myrho commented 3 years ago

Hello, I can't figure out how to setup a credentials file. I'm a complete go newbie. This is my main.go:

package main

import (
    "github.com/danielgtaylor/openapi-cli-generator/cli"
    "github.com/danielgtaylor/openapi-cli-generator/apikey"
)

func main() {
    cli.Init(&cli.Config{
        AppName:   "example",
        EnvPrefix: "EXAMPLE",
        Version:   "1.0.0",
    })

  exampleRegister(false)
  apikey.Init("Authorization", apikey.LocationHeader)

   cli.Creds.Set("profiles.default.api_key", "mykey")

   cli.Root.Execute()
}

This works, but the api key is hardcorded. Where and how should I define the key in the credentials file? I've tried:

./.example/config.json:

{ "example":
    { "profiles":
        { "default":
            { "api_key": "mykey"
            }
        }
    }
}

Any help is appreciated!