koxudaxi / fastapi-code-generator

This code generator creates FastAPI app from an openapi file.
MIT License
1.06k stars 107 forks source link

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

Open maneeshsethi opened 3 years ago

maneeshsethi commented 3 years ago

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?

koxudaxi commented 3 years ago

@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?