-
Notifications
You must be signed in to change notification settings - Fork 69
Open
Description
OpenAPI 3.0 has support for describing cookie authentication, it's a type of apiKey with in: cookie.
Since HTTP Snippet also support cookies, can we just leverage the cookies over here.
openapi-snippet/openapi-to-har.js
Lines 41 to 50 in b999cd0
| const har = { | |
| method: method.toUpperCase(), | |
| url: baseUrl + getFullPath(openApi, path, method), | |
| headers: getHeadersArray(openApi, path, method), | |
| queryString: getQueryStrings(openApi, path, method, queryParamValues), | |
| httpVersion: 'HTTP/1.1', | |
| cookies: [], | |
| headersSize: 0, | |
| bodySize: 0, | |
| }; |
Here's the fork I'm using for cookie authentication, I'm fairly new to OpenAPI stuff, so just assume where cookies can only been taken from security relative sections.
Test Input
const OpenAPISnippet = require("openapi-snippet");
const openApi = {
servers: [
{
url: "http://api.example.com/api/v1",
},
],
paths: {
"/books": {
post: {
security: [
{
cookieAuth: [],
},
],
},
},
},
components: {
securitySchemes: {
cookieAuth: {
type: "apiKey",
in: "cookie",
name: "my-session",
},
},
},
security: [
{
cookieAuth: [],
},
],
};
const targets = ["shell_curl"];
try {
// console.log(openApi);
const results2 = OpenAPISnippet.getEndpointSnippets(
openApi,
"/books",
"post",
targets
);
console.log(results2);
} catch (err) {
console.log(err);
}
Output
{
method: 'POST',
url: 'http://api.example.com/api/v1/books',
description: undefined,
resource: 'books',
snippets: [
{
id: 'shell_curl',
title: 'Shell + Curl',
content: 'curl --request POST \\\n' +
' --url http://api.example.com/api/v1/books \\\n' +
' --cookie my-session=REPLACE_KEY_VALUE'
}
]
}
Metadata
Metadata
Assignees
Labels
No labels