ogen-go / ogen

OpenAPI v3 code generator for go
https://ogen.dev
Apache License 2.0
1.46k stars 86 forks source link

security: Mechanism to get parameter name used within "apiKey" security schemes. #1280

Open jmalloc opened 4 months ago

jmalloc commented 4 months ago

Description

I'd like to be able to access the parameter name (cookie name, for example) defined in security schemes in my OpenAPI specification.

For example, I have the following sections in my spec:

components:
  securitySchemes:
    AuthenticatedSession:
      type: apiKey
      in: cookie
      name: auth_token

I also have a /login endpoint that sets the auth_token cookie. As it stands, I have hardcoded the name of the cookie in my login implementation, but it would be preferable to use a constant generated by ogen so that the YAML file is the single source of truth. I've had a release fail due to a mismatch between my code and the spec which was not caught by tests because when using the generated SecurityHandler and SecuritySource interfaces because they both refer to the cookie name in the spec.

References