fastapi-code-generator icon indicating copy to clipboard operation
fastapi-code-generator copied to clipboard

Confused how to set up an API key auth using this generator

Open maneeshsethi opened this issue 3 years ago • 1 comments

Hello! This looks very cool.

I can create the server fine, and load the jinja templates, but I'm not sure how to assign the correct Security to operations.

I want to add these:

  "BearerAuth": {
        "type": "http",
        "scheme": "bearer"
      },

or 

    API-key-header:
      in: header
      name: Authorization
      type: apiKey

How do I add this into the jinja template properly?

maneeshsethi avatar Aug 03 '21 04:08 maneeshsethi

@maneeshsethi I'm sorry for my late reply.

There is an example template for security.

https://github.com/koxudaxi/fastapi-code-generator/blob/master/tests/data/custom_template/security/main.jinja2

And, this is generated file. https://github.com/koxudaxi/fastapi-code-generator/blob/master/tests/data/expected/openapi/custom_template_security/custom_security/main.py

Does the example help you?

koxudaxi avatar Aug 09 '21 17:08 koxudaxi