@askills/openapi-explorer-cli 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # @askills/openapi-explorer-cli
2
+
3
+ ## 0.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 19adca9: fist ci
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 anuoua
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@askills/openapi-explorer-cli",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "CLI for progressive exploration of OpenAPI/Swagger API documentation",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -13,12 +13,6 @@
13
13
  "bin": {
14
14
  "openapi-explorer": "src/main.ts"
15
15
  },
16
- "scripts": {
17
- "start": "node src/main.ts",
18
- "test": "node --test test/*.test.ts",
19
- "test:watch": "node --test --watch test/*.test.ts",
20
- "typecheck": "tsc --noEmit"
21
- },
22
16
  "engines": {
23
17
  "node": ">=22.18.0"
24
18
  },
@@ -27,5 +21,11 @@
27
21
  },
28
22
  "devDependencies": {
29
23
  "@types/node": "^22.10.0"
24
+ },
25
+ "scripts": {
26
+ "start": "node src/main.ts",
27
+ "test": "node --test test/*.test.ts",
28
+ "test:watch": "node --test --watch test/*.test.ts",
29
+ "typecheck": "tsc --noEmit"
30
30
  }
31
- }
31
+ }
@@ -25,10 +25,16 @@ export async function cmdEndpoint(
25
25
  }
26
26
 
27
27
  const paramNames = getPathParams(path);
28
+ const opParams: any[] = op.parameters || [];
29
+ // Swagger 2.0 models the request body as a parameter with in:"body" + schema,
30
+ // separate from the path/query/header parameters.
31
+ const bodyParam = opParams.find((p: any) => p.in === "body");
32
+ const nonBodyParams = opParams.filter((p: any) => p.in !== "body");
33
+
28
34
  const mergedParams = [
29
35
  ...paramNames.map(
30
36
  (n) =>
31
- (op.parameters || []).find((p: any) => p.name === n) || {
37
+ nonBodyParams.find((p: any) => p.name === n) || {
32
38
  name: n,
33
39
  in: "path",
34
40
  required: true,
@@ -36,9 +42,62 @@ export async function cmdEndpoint(
36
42
  schema: { type: "string" },
37
43
  },
38
44
  ),
39
- ...(op.parameters || []).filter((p: any) => !paramNames.includes(p.name)),
45
+ ...nonBodyParams.filter((p: any) => !paramNames.includes(p.name)),
40
46
  ];
41
47
 
48
+ // Resolve $refs only under --full; otherwise leave schemas (with $ref) as-is.
49
+ const resolve = (schema: any): any =>
50
+ full && schema ? deepResolve(schema, spec) : schema;
51
+
52
+ // Request body: OpenAPI 3 requestBody wins; otherwise build one from a
53
+ // Swagger 2.0 body parameter so its schema renders in the Request Body
54
+ // section (instead of "object" in the parameters table).
55
+ let requestBody: any;
56
+ if (op.requestBody) {
57
+ requestBody = {
58
+ description: op.requestBody.description,
59
+ required: op.requestBody.required,
60
+ content: Object.fromEntries(
61
+ Object.entries(op.requestBody.content || {}).map(
62
+ ([ct, mt]: [string, any]) => [ct, { schema: resolve(mt.schema) }],
63
+ ),
64
+ ),
65
+ };
66
+ } else if (bodyParam) {
67
+ const ct =
68
+ (op.consumes || spec.consumes || ["application/json"])[0] ||
69
+ "application/json";
70
+ requestBody = {
71
+ description: bodyParam.description,
72
+ required: bodyParam.required,
73
+ content: { [ct]: { schema: resolve(bodyParam.schema) } },
74
+ };
75
+ }
76
+
77
+ // Responses: OpenAPI 3 uses response.content; Swagger 2.0 uses a bare
78
+ // response.schema + the operation's/root produces list.
79
+ const produces = op.produces || spec.produces || ["application/json"];
80
+ let responses: any;
81
+ if (op.responses) {
82
+ responses = Object.fromEntries(
83
+ Object.entries(op.responses).map(([code, resp]: [string, any]) => {
84
+ let content: any;
85
+ if (resp.content) {
86
+ content = Object.fromEntries(
87
+ Object.entries(resp.content).map(([ct, mt]: [string, any]) => [
88
+ ct,
89
+ { schema: resolve(mt.schema) },
90
+ ]),
91
+ );
92
+ } else if (resp.schema) {
93
+ const ct = produces[0] || "application/json";
94
+ content = { [ct]: { schema: resolve(resp.schema) } };
95
+ }
96
+ return [code, { description: resp.description, content }];
97
+ }),
98
+ );
99
+ }
100
+
42
101
  const ep: FormattedEndpoint = {
43
102
  path,
44
103
  method,
@@ -47,56 +106,9 @@ export async function cmdEndpoint(
47
106
  operationId: op.operationId,
48
107
  tags: op.tags || [],
49
108
  deprecated: op.deprecated || false,
50
- parameters: full
51
- ? mergedParams.map((p: any) => ({
52
- ...p,
53
- schema: p.schema ? deepResolve(p.schema, spec) : p.schema,
54
- }))
55
- : mergedParams,
56
- requestBody: op.requestBody
57
- ? {
58
- description: op.requestBody.description,
59
- required: op.requestBody.required,
60
- content: Object.fromEntries(
61
- Object.entries(op.requestBody.content).map(
62
- ([ct, mt]: [string, any]) => [
63
- ct,
64
- {
65
- schema:
66
- full && mt.schema
67
- ? deepResolve(mt.schema, spec)
68
- : mt.schema,
69
- },
70
- ],
71
- ),
72
- ),
73
- }
74
- : undefined,
75
- responses: op.responses
76
- ? Object.fromEntries(
77
- Object.entries(op.responses).map(([code, resp]: [string, any]) => [
78
- code,
79
- {
80
- description: resp.description,
81
- content: resp.content
82
- ? Object.fromEntries(
83
- Object.entries(resp.content).map(
84
- ([ct, mt]: [string, any]) => [
85
- ct,
86
- {
87
- schema:
88
- full && mt.schema
89
- ? deepResolve(mt.schema, spec)
90
- : mt.schema,
91
- },
92
- ],
93
- ),
94
- )
95
- : undefined,
96
- },
97
- ]),
98
- )
99
- : undefined,
109
+ parameters: mergedParams.map((p: any) => ({ ...p, schema: resolve(p.schema) })),
110
+ requestBody,
111
+ responses,
100
112
  security: op.security,
101
113
  };
102
114
 
package/src/main.ts CHANGED
File without changes
package/src/types.ts CHANGED
@@ -15,6 +15,8 @@ export interface OpenAPISpec {
15
15
  host?: string;
16
16
  basePath?: string;
17
17
  schemes?: string[];
18
+ consumes?: string[];
19
+ produces?: string[];
18
20
  }
19
21
 
20
22
  export interface EndpointSummary {