Embraser01 / typoas

Open API (OAS 3.0) Typescript generator
MIT License
38 stars 5 forks source link

variableConfiguration Documentations and Examples #55

Closed fulvio-diller closed 4 months ago

fulvio-diller commented 5 months ago

Hi there great tool, but the documentation and examples for variableConfiguration are a bit limited:

Can you add Documentation about Auth, Headers etc?

Thanks.

Embraser01 commented 5 months ago

Hi thanks, I agree, there isn't a lot of documentation yet. The TSDoc should give some information but it's not ideal.

I'm not sure on what you mean by variableConfiguration?

fulvio-diller commented 5 months ago

When we create a new context, like so:

    const ctx = createContext({
      serverConfiguration: new ServerConfiguration(
        process.env.BASE_URL || "",
        {} //variableConfiguration
      ),
    });
Embraser01 commented 5 months ago

I see

The variableConfiguration object is here to map to the OpenAPI spec in the server object. Most of the time you don't really need to specify it (you can leave an empty {}).

A simple example could be (using the OpenAPI spec example):

new ServerConfiguration(
  'https://{username}.gigantic-server.com:{port}/{basePath}"',
  { username: 'demo', port: '443', basePath: '/v2' },
);

Typoas will automatically set the variables in the base URL

PS: The ServerConfiguration system is not as good as I'd want, I should see to improve this

fulvio-diller commented 5 months ago

Thanks for the info, if we have ann Api Token how do we setup?

Embraser01 commented 5 months ago

Thanks for the info, if we have ann Api Token how do we setup?

This will not be related to ServerConfiguration but more on the authProviders object:

createContext({
  authProviders: {
    'my-auth-mode': {
      async getConfig() {
        return { token: 'My token' };
      },
    },
  },
});

Where my-auth-mode is the name of the securityScheme declared on the OpenAPI, each auth provider must provide a getConfig method that return a token or other (depending on the auth mode).

If the authProviders doesn't match your need, you can also just override the default fetcher and handle the authentication on the Fetcher level

fulvio-diller commented 5 months ago

Thanks for the help, you can close this issue :smile:

Embraser01 commented 5 months ago

I'll keep this open for now, so people can find a small example and so I don't forget that it needs a better documentation with more examples and explaination

Embraser01 commented 4 months ago

I added some example on the configuration of createContext to be a little bit more easy to customize