Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Security not applying to the securitySchemes or schema #140

Open
jcodog opened this issue Mar 25, 2024 · 1 comment
Open

Security not applying to the securitySchemes or schema #140

jcodog opened this issue Mar 25, 2024 · 1 comment

Comments

@jcodog
Copy link

jcodog commented Mar 25, 2024

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.

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

@jcodog
Copy link
Author

jcodog commented Mar 25, 2024

Is this the correct way, this is what I have tried most recently.

code:

export const router = OpenAPIRouter({
	docs_url: "/",
	schema: {
		info: {
			title: "JCoNet LTD API",
			version: "1",
		},
		security: {
			api_key: [
				{
					type: "apiKey",
					in: "header",
					name: "x-api-key",
				},
			],
		},
	},
});
router.registry.registerComponent("securitySchemes", "api_key", {
	type: "apiKey",
	in: "header",
	name: "x-api-key",
});

console.log(router.schema);

console:

⎔ Reloading local server...
{
  openapi: '3.1.0',
  info: { title: 'JCoNet LTD API', version: '1' },
  security: { api_key: [ [Object] ] },
  components: {
    securitySchemes: { api_key: [Object] },
    schemas: {},
    parameters: {}
  },
  paths: {},
  webhooks: {}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant