Skip to content

Commit 5ff603e

Browse files
committed
refactor(govinfo-sdk): simplify build process and update OpenAPI spec references
1 parent 6246cd8 commit 5ff603e

File tree

12 files changed

+104
-141
lines changed

12 files changed

+104
-141
lines changed

packages/govinfo-sdk/build.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ await $`rm -rf dist`;
1010
// Build ESM format
1111
console.log('Building ESM...');
1212
await Bun.build({
13-
entrypoints: ['./src/index.ts', './src/mcp/index.ts'],
13+
entrypoints: ['./src/index.ts'],
1414
outdir: './dist',
1515
format: 'esm',
1616
target: 'node',
@@ -26,7 +26,7 @@ await Bun.build({
2626
// Build CJS format
2727
console.log('Building CommonJS...');
2828
await Bun.build({
29-
entrypoints: ['./src/index.ts', './src/mcp/index.ts'],
29+
entrypoints: ['./src/index.ts'],
3030
outdir: './dist',
3131
format: 'cjs',
3232
target: 'node',

packages/govinfo-sdk/openapi.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"content": {
5858
"application/json": {
5959
"schema": {
60-
"$ref": "#/components/schemas/SearchRequest"
60+
"$ref": "#/components/schemas/SearchBody"
6161
},
6262
"example": {
6363
"query": "Federal documents",
@@ -1416,7 +1416,7 @@
14161416
},
14171417
"components": {
14181418
"schemas": {
1419-
"SearchRequest": {
1419+
"SearchBody": {
14201420
"type": "object",
14211421
"properties": {
14221422
"query": {
Lines changed: 25 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,46 @@
1-
import { defineConfig } from 'orval';
1+
import { defineConfig } from "orval";
22

33
export default defineConfig({
4-
// SDK configuration
5-
'govinfo-api': {
6-
input: './openapi.json',
4+
sdk: {
5+
input: "./openapi.json",
76
output: {
8-
mode: 'split',
9-
target: './src/api/generated/endpoints.ts',
10-
schemas: './src/api/generated/model',
11-
client: 'axios-functions',
12-
httpClient: 'axios',
13-
mock: false,
7+
mode: "split",
8+
target: "./src/api/generated/endpoints.ts",
9+
schemas: "./src/api/generated/model",
10+
client: "axios-functions",
11+
httpClient: "axios",
12+
mock: true,
1413
clean: true,
14+
docs: {
15+
out: "./docs",
16+
disableSources: true,
17+
},
1518
prettier: false,
1619
override: {
1720
operations: {
1821
Document: {
1922
mutator: {
20-
path: './src/api/client.ts',
21-
name: 'customInstance',
23+
path: "./src/api/client.ts",
24+
name: "customInstance",
2225
},
2326
},
2427
},
2528
mutator: {
26-
path: './src/api/client.ts',
27-
name: 'customInstance',
29+
path: "./src/api/client.ts",
30+
name: "customInstance",
2831
},
29-
header: () => [
30-
'/* eslint-disable */',
31-
'/* tslint:disable */',
32-
'// @ts-nocheck',
33-
'/**',
34-
' * Generated by orval 🍺',
35-
' * Do not edit manually.',
36-
' * GovInfo API Documentation',
37-
' * OpenAPI spec version: 3.0.0',
38-
' */',
39-
'',
40-
],
4132
},
4233
},
4334
},
44-
// MCP server configuration
45-
'govinfo-mcp': {
46-
input: './openapi.json',
35+
mcp: {
36+
input: "./openapi.json",
4737
output: {
48-
mode: 'single',
49-
client: 'mcp',
50-
baseUrl: 'https://api.govinfo.gov',
51-
target: './src/mcp/handlers.ts',
52-
schemas: './src/mcp/http-schemas',
53-
override: {
54-
header: () => [
55-
'/* eslint-disable */',
56-
'/* tslint:disable */',
57-
'// @ts-nocheck',
58-
'/**',
59-
' * Generated by orval 🍺',
60-
' * Do not edit manually.',
61-
' * GovInfo API Documentation',
62-
' * OpenAPI spec version: 3.0.0',
63-
' */',
64-
'',
65-
],
66-
},
67-
},
68-
hooks: {
69-
afterAllFilesWrite: 'bun run scripts/fix-mcp-types.ts',
38+
mode: "single",
39+
client: "mcp",
40+
baseUrl: "https://api.govinfo.gov",
41+
target: "./src/mcp/handlers.ts",
42+
schemas: "./src/mcp/http-schemas",
43+
clean: true,
7044
},
7145
},
7246
});

packages/govinfo-sdk/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@
6262
"test:e2e:mcp": "bun test tests/e2e/mcp-server.e2e.test.ts",
6363
"test:all": "bun test",
6464
"mcp:server": "bun run src/mcp/server.ts",
65-
"docs:generate": "bunx orval --config orval.config.ts --project docs"
65+
"docs:generate": "bunx typedoc"
6666
},
6767
"devDependencies": {
68-
"@biomejs/biome": "2.1.2",
68+
"@biomejs/biome": "2.1.3",
6969
"@types/bun": "latest",
7070
"@types/node": "^24.1.0",
7171
"@us-legal-tools/tsconfig": "workspace:*",
@@ -88,4 +88,4 @@
8888
"publishConfig": {
8989
"access": "public"
9090
}
91-
}
91+
}

packages/govinfo-sdk/scripts/download-openapi.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ async function downloadOpenAPISpec() {
1212
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
1313
}
1414

15-
const spec = await response.json();
15+
const spec = await response.json() as any;
1616

1717
// Fix apostrophes in descriptions to prevent syntax errors in generated code
1818
const fixApostrophes = (obj: any): any => {
@@ -34,8 +34,14 @@ async function downloadOpenAPISpec() {
3434

3535
const fixedSpec = fixApostrophes(spec);
3636

37+
// Rename SearchRequest to SearchBody to match MCP generator expectations
38+
const specString = JSON.stringify(fixedSpec, null, 2);
39+
const renamedSpec = specString
40+
.replace(/"SearchRequest"/g, '"SearchBody"')
41+
.replace(/#\/components\/schemas\/SearchRequest/g, '#/components/schemas/SearchBody');
42+
3743
// Write the spec to a file
38-
await writeFile('./openapi.json', JSON.stringify(fixedSpec, null, 2));
44+
await writeFile('./openapi.json', renamedSpec);
3945

4046
console.log('✅ OpenAPI specification downloaded successfully');
4147
console.log(`📄 Spec title: ${spec.info?.title}`);

packages/govinfo-sdk/scripts/fix-mcp-types.ts

Lines changed: 0 additions & 48 deletions
This file was deleted.

packages/govinfo-sdk/src/index.ts

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,12 @@
11
// GovInfo SDK
2+
import * as packageJson from '../package.json';
3+
4+
// Export the configured API client
25
export * from './api/client';
3-
// Re-export generated functions and types
4-
export * from './api/generated/endpoints';
5-
// Re-export additional types from model (SearchResult will come from endpoints)
6-
export type {
7-
CollectionContainer,
8-
CollectionSummary,
9-
GranuleContainer,
10-
GranuleMetadata,
11-
PackageInfo,
12-
SearchRequest,
13-
SearchResponse,
14-
SearchResultDownload,
15-
Sort,
16-
SortSortOrder,
17-
SummaryItem
18-
} from './api/generated/model';
196

20-
export default {
21-
name: 'GovInfo SDK',
22-
version: '0.1.0',
23-
description: 'TypeScript SDK and MCP server for the GovInfo API',
24-
};
7+
// Export package version
8+
export const VERSION = packageJson.version;
9+
10+
// Users can import generated types and functions directly:
11+
// import { search } from '@us-legal-tools/govinfo-sdk/api/generated/endpoints';
12+
// import type { SearchBody } from '@us-legal-tools/govinfo-sdk/api/generated/model';

packages/govinfo-sdk/src/mcp/index.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

packages/govinfo-sdk/tsconfig.build.json

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,18 @@
22
"extends": "@us-legal-tools/tsconfig/tsconfig.build.json",
33
"compilerOptions": {
44
"outDir": "./dist",
5-
"rootDir": "./src"
5+
"rootDir": "./src",
6+
"resolveJsonModule": true
67
},
7-
"include": ["src/**/*"],
8-
"exclude": ["src/**/*.test.ts", "src/**/*.spec.ts", "src/test-*.ts", "tests/**/*", "scripts/**/*"]
8+
"include": ["src/index.ts", "src/api/client.ts"],
9+
"exclude": [
10+
"src/**/*.test.ts",
11+
"src/**/*.spec.ts",
12+
"src/test-*.ts",
13+
"tests/**/*",
14+
"scripts/**/*",
15+
"src/api/generated/**/*",
16+
"src/api/endpoints/**/*",
17+
"src/mcp/**/*"
18+
]
919
}

packages/govinfo-sdk/tsconfig.json

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
{
22
"extends": "@us-legal-tools/tsconfig/tsconfig.json",
33
"compilerOptions": {
4-
"types": ["bun-types"]
4+
"types": ["bun-types"],
5+
"resolveJsonModule": true,
6+
"skipLibCheck": true
57
},
6-
"include": ["src/**/*", "scripts/**/*", "tests/**/*"],
7-
"exclude": ["node_modules", "dist"]
8+
"include": ["src/**/*", "tests/**/*"],
9+
"exclude": [
10+
"node_modules",
11+
"dist",
12+
"src/api/generated/model/**/*",
13+
"src/api/generated/endpoints.ts",
14+
"src/api/endpoints/docs.ts",
15+
"src/mcp/**/*",
16+
"scripts/**/*"
17+
]
818
}

0 commit comments

Comments
 (0)