spring-api-scanner 0.1.0
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/PLAN.md +142 -0
- package/README.md +60 -0
- package/dist/args.d.ts +9 -0
- package/dist/args.js +57 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +67 -0
- package/dist/openapi.d.ts +67 -0
- package/dist/openapi.js +94 -0
- package/dist/output.d.ts +6 -0
- package/dist/output.js +25 -0
- package/dist/resolver.d.ts +17 -0
- package/dist/resolver.js +206 -0
- package/dist/scanner.d.ts +22 -0
- package/dist/scanner.js +321 -0
- package/dist/ui.d.ts +36 -0
- package/dist/ui.js +407 -0
- package/docs/plans/2026-02-07-complete-remaining-tasks.md +61 -0
- package/package.json +23 -0
- package/spring-api-scanner-0.1.0.tgz +0 -0
- package/src/args.ts +76 -0
- package/src/index.ts +81 -0
- package/src/openapi.ts +191 -0
- package/src/output.ts +36 -0
- package/src/resolver.ts +274 -0
- package/src/scanner.ts +409 -0
- package/src/ui.ts +454 -0
- package/tests/args.test.d.ts +1 -0
- package/tests/args.test.ts +45 -0
- package/tests/fixtures/sample-service/src/main/kotlin/demo/UserController.kt +34 -0
- package/tests/fixtures/sample-service/src/main/kotlin/demo/UserDtos.kt +22 -0
- package/tests/golden/openapi.sample-service.json +164 -0
- package/tests/integration.test.ts +98 -0
- package/tests/openapi.test.d.ts +1 -0
- package/tests/openapi.test.ts +127 -0
- package/tests/output.test.ts +55 -0
- package/tests/resolver.test.ts +98 -0
- package/tests/scanner.test.ts +138 -0
- package/tests/ui.test.ts +85 -0
- package/tsconfig.json +15 -0
package/tests/ui.test.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { buildUiModel, renderUiHtml } from "../src/ui.js";
|
|
3
|
+
import type { OpenApiDocument } from "../src/openapi.js";
|
|
4
|
+
import type { ExtractedEndpoint } from "../src/scanner.js";
|
|
5
|
+
|
|
6
|
+
describe("buildUiModel", () => {
|
|
7
|
+
it("builds endpoint cards with curl and schema sections", () => {
|
|
8
|
+
const endpoints: ExtractedEndpoint[] = [
|
|
9
|
+
{
|
|
10
|
+
sourceFile: "UserController.kt",
|
|
11
|
+
operationName: "getUser",
|
|
12
|
+
httpMethod: "GET",
|
|
13
|
+
fullPath: "/users/{id}",
|
|
14
|
+
returnType: "UserDto",
|
|
15
|
+
pathVariables: [{ name: "id", type: "Long", required: true }],
|
|
16
|
+
queryParams: [{ name: "verbose", type: "Boolean?", required: false }],
|
|
17
|
+
headers: [{ name: "X-Trace-Id", type: "String", required: true }]
|
|
18
|
+
}
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
const openapi: OpenApiDocument = {
|
|
22
|
+
openapi: "3.0.3",
|
|
23
|
+
info: { title: "Demo", version: "1.0.0" },
|
|
24
|
+
paths: {
|
|
25
|
+
"/users/{id}": {
|
|
26
|
+
get: {
|
|
27
|
+
operationId: "getUser",
|
|
28
|
+
tags: ["UserController"],
|
|
29
|
+
parameters: [],
|
|
30
|
+
responses: {
|
|
31
|
+
"200": {
|
|
32
|
+
description: "OK",
|
|
33
|
+
content: {
|
|
34
|
+
"application/json": {
|
|
35
|
+
schema: { $ref: "#/components/schemas/UserDto" }
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
components: {
|
|
44
|
+
schemas: {
|
|
45
|
+
UserDto: {
|
|
46
|
+
type: "object",
|
|
47
|
+
properties: { id: { type: "integer", format: "int64" } },
|
|
48
|
+
required: ["id"]
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const model = buildUiModel({ endpoints, openapi });
|
|
55
|
+
|
|
56
|
+
expect(model.endpoints).toHaveLength(1);
|
|
57
|
+
expect(model.endpoints[0].controller).toBe("UserController");
|
|
58
|
+
expect(model.endpoints[0].curl).toContain("curl -X GET");
|
|
59
|
+
expect(model.endpoints[0].responseSchema).toEqual(openapi.components.schemas.UserDto);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe("renderUiHtml", () => {
|
|
64
|
+
it("renders search/filter/copy/download UI affordances", () => {
|
|
65
|
+
const html = renderUiHtml("Demo Docs");
|
|
66
|
+
|
|
67
|
+
expect(html).toContain("id=\"search\"");
|
|
68
|
+
expect(html).toContain("id=\"method-filter\"");
|
|
69
|
+
expect(html).toContain("id=\"controller-filter\"");
|
|
70
|
+
expect(html).toContain("Copy curl");
|
|
71
|
+
expect(html).toContain("Download OpenAPI JSON");
|
|
72
|
+
expect(html).toContain("navigator.clipboard.writeText");
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("supports embedded ui-data for file:// usage with fetch fallback", () => {
|
|
76
|
+
const html = renderUiHtml("Demo Docs", {
|
|
77
|
+
generatedAt: "2026-01-01T00:00:00.000Z",
|
|
78
|
+
endpoints: []
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
expect(html).toContain("id=\"embedded-ui-data\"");
|
|
82
|
+
expect(html).toContain("JSON.parse(embedded.textContent)");
|
|
83
|
+
expect(html).toContain("fetch('ui-data.json')");
|
|
84
|
+
});
|
|
85
|
+
});
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "NodeNext",
|
|
5
|
+
"moduleResolution": "NodeNext",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"declaration": true,
|
|
8
|
+
"outDir": "dist",
|
|
9
|
+
"rootDir": "src",
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"forceConsistentCasingInFileNames": true,
|
|
12
|
+
"skipLibCheck": true
|
|
13
|
+
},
|
|
14
|
+
"include": ["src/**/*.ts"]
|
|
15
|
+
}
|