cloudflare / cloudflare/chanfana

Security not applying to the securitySchemes or schema

Open
#140 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
766
Forks
70
Avg merge
25m
Merged PRs (30d)
4

Description

I have added an api key to my router so that when you go to docs a new authorise button appears, however when you try to make a request, it does not apply the API key you specify into the headers as expected, how do I fix this? I want to be able to have the docs show the same security etc as the main API.

```typescript
export const router = OpenAPIRouter({
docs_url: "/",
schema: {
info: {
title: "JCoNet LTD API",
version: "1",
},
},
});
router.registry.registerComponent("securitySchemes", "api_key", {
type: "apiKey",
in: "header",
name: "x-api-key",
});
```
![image](https://github.com/cloudflare/itty-router-openapi/assets/18666535/93b16591-15fb-4edd-b315-061e7c070d6d)
As you can see in the code the scheme is shown but is not being included in the docs examples so isn't applying the header, have I done something wrong or does the docs not display the headers you provide in authorise?

Contributor guide

Open the contributing guide

Research direction

Start with the OpenAPIRouter configuration and registry.registerComponent("securitySchemes", "api_key", ...) shown in the report, then reproduce the behavior in the generated documentation. Trace how the registered apiKey scheme reaches the request examples and verify that an authorized request includes the x-api-key header; done means the docs use the configured key when making requests.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, typescript
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.