Skip to content

Commit d350fcb

Browse files
committed
v1.2.4
1 parent c422a06 commit d350fcb

17 files changed

+234
-135
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ OpenAPI DevTools is a Chrome extension that generates OpenAPI specifications in
3636
- Automatically merges new request & response headers, bodies, and query parameters per endpoint
3737
- Click on a [path parameter](https://www.abstractapi.com/api-glossary/path-parameters) and the app will automatically merge existing and future matching requests
3838
- View the specification inside the tool using [Redoc](https://www.npmjs.com/package/redoc) and download with a click
39+
- Export and save a session at any time, or share it with others
3940

4041
<p align="right">(<a href="#readme-top">back to top</a>)</p>
4142

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"manifest_version": 3,
33
"name": "OpenAPI DevTools",
4-
"version": "1.2.2",
4+
"version": "1.2.4",
55
"devtools_page": "index.html",
66
"permissions": [],
77
"icons": {

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,5 @@
5252
"typescript": "^5.2.2",
5353
"vite": "^4.4.11",
5454
"vitest": "^0.34.6"
55-
},
56-
"overrides": {
57-
"@apidevtools/json-schema-ref-parser": "^11.1.0"
5855
}
5956
}

resources/dist.zip

534 Bytes
Binary file not shown.

src/lib/RequestStore.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,20 @@ it("can parameterise paths that exist along the same segment", () => {
171171
expect(getResBodyTypes(store, host, "/1/ANY/a")).toBe("string");
172172
expect(getResBodyTypes(store, host, "/1/ANY")).toBe("integer");
173173
});
174+
175+
it("parameterisation works after export and import", () => {
176+
const store = new RequestStore();
177+
const req = createSimpleRequest(`${base}/1/2/a`);
178+
store.insert(req, { foo: 1 });
179+
store.parameterise(2, "/1/2/a", host);
180+
const exported = store.export();
181+
store.import(exported);
182+
store.insert(req, { foo: 1 });
183+
const expected = {
184+
[host]: {
185+
'/1/2/:param2': expect.any(Object),
186+
}
187+
};
188+
// @ts-expect-error accessing private property
189+
expect(store.leafMap).toEqual(expected);
190+
});

src/lib/endpoints-to-oai31.helpers.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ import {
1212
ParameterObject,
1313
SecuritySchemeObject,
1414
} from "openapi3-ts/oas31";
15-
import { Authentication, AuthType } from "../utils/httpauthentication";
15+
import { Authentication, AuthType } from "../utils/types";
1616

1717
export const createSecuritySchemeTypes = (auth?: Authentication): SecuritySchemeObject | undefined => {
1818
if (!auth) return;
19-
const isBearer = auth.authType === AuthType.BEARER;
20-
const isBasic = auth.authType === AuthType.BASIC;
21-
const isDigest = auth.authType === AuthType.DIGEST;
19+
const isBearer = auth.id === AuthType.BEARER;
20+
const isBasic = auth.id === AuthType.BASIC;
21+
const isDigest = auth.id === AuthType.DIGEST;
2222
if (isBearer || isBasic || isDigest) {
2323
const securitySchemeObject: SecuritySchemeObject = {
2424
type: auth.type,

src/lib/endpoints-to-oai31.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import bearer from "./__fixtures__/bearer";
77
import basic from "./__fixtures__/basic";
88
import digest from "./__fixtures__/digest";
99
import { cloneDeep } from "lodash";
10-
import { AuthType } from "../utils/httpauthentication";
10+
import { AuthType } from "../utils/types";
1111
import { defaultOptions } from "./store-helpers/persist-options";
1212

1313
const createRequestStoreWithDefaults = () => {

src/lib/endpoints-to-oai31.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Endpoint } from "../utils/types";
1+
import { Endpoint, AuthType } from "../utils/types";
22
import {
33
OpenApiBuilder,
44
PathItemObject,
@@ -15,9 +15,9 @@ import {
1515
createResponseTypes,
1616
createSecuritySchemeTypes,
1717
} from "./endpoints-to-oai31.helpers";
18-
import { AuthType } from "../utils/httpauthentication";
1918
import { Options } from "./RequestStore";
2019
import { defaultOptions } from "./store-helpers/persist-options";
20+
import { isEmpty } from "lodash";
2121

2222
const endpointsToOAI31 = (endpoints: Array<Endpoint>, options: Options = defaultOptions): OpenApiBuilder => {
2323
const { enableMoreInfo } = options;
@@ -34,12 +34,14 @@ const endpointsToOAI31 = (endpoints: Array<Endpoint>, options: Options = default
3434

3535
const auth = endpoint.data.authentication;
3636
if (auth) {
37-
const securitySchema = createSecuritySchemeTypes(
38-
endpoint.data.authentication
39-
);
40-
if (securitySchema) {
41-
uniqueAuth.set(auth.authType, securitySchema);
42-
}
37+
Object.values(auth).forEach(value => {
38+
const securitySchema = createSecuritySchemeTypes(
39+
value
40+
);
41+
if (securitySchema) {
42+
uniqueAuth.set(value.id, securitySchema);
43+
}
44+
});
4345
}
4446

4547
for (const [method, statusCodes] of Object.entries(endpoint.data.methods)) {
@@ -55,10 +57,12 @@ const endpointsToOAI31 = (endpoints: Array<Endpoint>, options: Options = default
5557
statusCode,
5658
mostRecentResponse,
5759
);
58-
const security: SecurityRequirementObject[] | null = endpoint.data
59-
.authentication
60-
? [{ [endpoint.data.authentication.authType]: [] }]
61-
: null;
60+
const security: SecurityRequirementObject[] = [];
61+
if (!isEmpty(endpoint.data.authentication)) {
62+
Object.values(endpoint.data.authentication).forEach(value => {
63+
security.push({ [value.id]: [] });
64+
});
65+
}
6266
const operation: OperationObject = {
6367
summary: fullPath,
6468
description: `**Host**: http://${endpoint.host}`,
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// import { Authentication, AuthType } from "../../utils/types";
2+
// import { getAuthType } from "./authentication";
3+
4+
// /**
5+
// * Helpers and utilities for endpoint Authentication details
6+
// * Modelled on a Security Scheme Object https://spec.openapis.org/oas/v3.1.0#security-scheme-object
7+
// */
8+
// export interface APIKeyAuth extends Authentication {
9+
// type: "apiKey";
10+
// name: string;
11+
// }
12+
13+
// export interface APIKeyAuthHeader extends APIKeyAuth {
14+
// in: "header";
15+
// }
16+
17+
// export type APIKeyAuthHeaders = APIKeyAuthHeader | undefined;
18+
19+
// export const parseAPIKeyAuthHeader = (
20+
// header: chrome.devtools.network.Request["request"]["headers"][0]
21+
// ): APIKeyAuthHeaders => {
22+
// const authType = getAuthType(header.value);
23+
// if (authType === "basic") {
24+
// const basicAuth: BasicAuthHeader = {
25+
// id: AuthType.BASIC,
26+
// type: "http",
27+
// in: "header",
28+
// scheme: "Basic",
29+
// description: "",
30+
// };
31+
// return basicAuth;
32+
// } else if (authType === "bearer") {
33+
// const bearerAuth: BearerAuthHeader = {
34+
// id: AuthType.BEARER,
35+
// type: "http",
36+
// in: "header",
37+
// scheme: "Bearer",
38+
// description: "",
39+
// };
40+
// return bearerAuth;
41+
// } else if (authType === "digest") {
42+
// const digestAuth: DigestAuthHeader = {
43+
// id: AuthType.DIGEST,
44+
// type: "http",
45+
// in: "header",
46+
// scheme: "Digest",
47+
// description: "",
48+
// };
49+
// return digestAuth;
50+
// }
51+
// };
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { Authentication, AuthType } from "../../utils/types";
2+
import { getAuthType } from "./authentication";
3+
4+
/**
5+
* Helpers and utilities for endpoint Authentication details
6+
* Modelled on a Security Scheme Object https://spec.openapis.org/oas/v3.1.0#security-scheme-object
7+
*/
8+
export interface HTTPAuth extends Authentication {
9+
type: "http";
10+
}
11+
12+
export interface BearerAuthHeader extends HTTPAuth {
13+
scheme: "Bearer";
14+
in: "header";
15+
}
16+
17+
export interface BasicAuthHeader extends HTTPAuth {
18+
scheme: "Basic";
19+
in: "header";
20+
}
21+
22+
export interface DigestAuthHeader extends HTTPAuth {
23+
scheme: "Digest";
24+
in: "header";
25+
}
26+
27+
export type HTTPAuthHeaders =
28+
| DigestAuthHeader
29+
| BasicAuthHeader
30+
| BearerAuthHeader
31+
| undefined;
32+
33+
export const parseHTTPAuthHeader = (
34+
header: chrome.devtools.network.Request["request"]["headers"][0]
35+
): HTTPAuthHeaders => {
36+
const authType = getAuthType(header.value);
37+
if (authType === "basic") {
38+
const basicAuth: BasicAuthHeader = {
39+
id: AuthType.BASIC,
40+
type: "http",
41+
in: "header",
42+
scheme: "Basic",
43+
description: "",
44+
};
45+
return basicAuth;
46+
} else if (authType === "bearer") {
47+
const bearerAuth: BearerAuthHeader = {
48+
id: AuthType.BEARER,
49+
type: "http",
50+
in: "header",
51+
scheme: "Bearer",
52+
description: "",
53+
};
54+
return bearerAuth;
55+
} else if (authType === "digest") {
56+
const digestAuth: DigestAuthHeader = {
57+
id: AuthType.DIGEST,
58+
type: "http",
59+
in: "header",
60+
scheme: "Digest",
61+
description: "",
62+
};
63+
return digestAuth;
64+
}
65+
};

0 commit comments

Comments
 (0)