swagger-typescript-api icon indicating copy to clipboard operation
swagger-typescript-api copied to clipboard

Feature Request: Basic http authentication support

Open Mr-sgreen opened this issue 4 years ago • 1 comments

Knife4j(a swagger doc server) can set up a basic http authentication with username and password which swagger-typescript-api can not fetch api.json without login.

Currently, i solve this problem with the code below

const axios = require('axios');
axios.default.defaults.auth = {
    username: 'xxx',
    password: 'xxx',
};
generateApi({
    name: 'api.ts', 
    url: 'http://www.example.com/', 
    templates: path.join(__dirname, '/templates'),
    //use axios
    httpClientType: 'axios',
})

it will be good if swagger-typescript-api can support this syntax

generateApi({
    name: 'api.ts', 
    url: 'http://www.example.com/', 
    templates: path.join(__dirname, '/templates'),
    //support auth options
    auth: {
      username: 'xxx',
      password: '123',
    }
})
npx swagger-typescript-api -p https://www.example.com/v3/api-docs?group=V1.0 -o ./src -n myApi.ts --auth username:password

Mr-sgreen avatar Jul 15 '21 09:07 Mr-sgreen

Instead of doing this we can simply achieve this with the current implementation add authorizationToken in you generateApi function use it like this

authorizationToken: `Basic ${btoa(
    'username:password'
  )}`,

matifriaz avatar Jan 10 '24 11:01 matifriaz