Search code examples
openapiopenapi-generator

openapi generator Select Server Configuration


I'm using openapi 3.0 and openapi generator 5.4.0 to generate code for go. I have multiple servers configured. There is a "Select Server Configuration" part in README. It supplies example, but I'm unable to find out how and where to use it.

For using other server than the one defined on index 0 set context value sw.ContextServerIndex of type int.

ctx := context.WithValue(context.Background(), openapi.ContextServerIndex, 1)

Solution

  • Seems like you can do the following when you pass in the config options.

    import {
      Configuration,
      ConfigurationParameters,
      UsersApi, // Will be whatever you tagged your endpoints with and `Api`
    } from "your-sdk";
    const configParameters: ConfigurationParameters = {
      headers: {
        Authorization: sessionToken ? `Bearer ${sessionToken}` : "",
      },
      basePath: 'http://localhost:3022/rest/v1'
    };
    
    const configuration = new Configuration(configParameters);
    const userApi = new UsersApi(configuration);
    userApi.aPostMethod({aPostMethodRequest: {email: "an@email.com"}})
    

    For some reason I seem to need to prefix my params for a POST request with a name that matches the called method, but with Request after it