Dani
Dani

Reputation: 136

Authentication for Open API generator

I apologize if this has been answered already, but I can't find a clear answer.

Does the current generator support authentication?

I need to generate a client with 2 potential ways of authentication:

  1. Via API key, which means a required api_token parameter.
  2. Via an OAuth 2 authentication code flow.

If it does, how do I use it?

If it doesn't, what do you think is the best way to add authentication after generating the client?

Upvotes: 7

Views: 17838

Answers (1)

jacefarm
jacefarm

Reputation: 7461

Given that the OpenAPI Generator can interact with any server that exposes an OpenAPI document, it would follow that one first needs an OpenAPI document that utilizes the security scheme term for authentication and authorization. OpenAPI 3.0 (and 2.0) lets you describe the two desired auth approaches.

Once an OpenAPI document in .yaml or .json format has been created, I believe the Getting Started instructions describe the commands necessary to generate server stubs for authentication, based on the OpenAPI document that you have created for your auth flow.

For example, if your OpenAPI document would happen to be the Swagger Petstore example, you would "generate" thusly:

npx openapi-generator generate -i petstore.yaml -g ruby -o /tmp/test/

Upvotes: 1

Related Questions