@ts-pf/openapi 0.1.9 → 0.1.11

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ts-pf/openapi",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "description": "Opt-in OpenAPI 3.1 document from catalog() (POST JSON RPC)",
5
5
  "keywords": [
6
6
  "ts-pf",
@@ -49,11 +49,11 @@
49
49
  "lint": "biome check src tests"
50
50
  },
51
51
  "dependencies": {
52
- "@ts-pf/docs": "0.1.9"
52
+ "@ts-pf/docs": "0.1.11"
53
53
  },
54
54
  "devDependencies": {
55
- "@ts-pf/contract": "0.2.1",
56
- "@ts-pf/stream": "0.2.1",
55
+ "@ts-pf/contract": "0.2.3",
56
+ "@ts-pf/stream": "0.2.3",
57
57
  "typebox": "^1.3.24",
58
58
  "zod": "^4.0.0"
59
59
  }
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: ts-pf-openapi
3
- description: Use when projecting a ts-pf catalog() to OpenAPI 3.1 with openapi(). Triggers: @ts-pf/openapi, openapi(), OpenAPI 3.1, POST JSON RPC spec.
3
+ description: "Use when projecting a ts-pf catalog() to OpenAPI 3.1 with openapi(). Triggers: @ts-pf/openapi, openapi(), OpenAPI 3.1, POST JSON RPC spec."
4
4
  ---
5
5
 
6
6
  # @ts-pf/openapi
@@ -29,6 +29,43 @@ Every path is `POST {prefix}/{router keys}`. Serve JSON in userland (`GET /opena
29
29
 
30
30
  Typed split-repo clients: `ts-pf-codegen`, not OpenAPI-TS.
31
31
 
32
+ ## Documenting a GET bridge or REST facade
33
+
34
+ `openapi()` stays POST only. If you serve the userland GET bridge (`ts-pf-server-http`, "Cacheable reads"), add the `get` operations to the returned document yourself. Each opted-in catalog entry carries its contract meta, and the GET reuses the POST's responses:
35
+
36
+ ```ts
37
+ import { catalog } from '@ts-pf/docs'
38
+ import { openapi } from '@ts-pf/openapi'
39
+ import { contract } from './contract.js'
40
+
41
+ const cat = catalog(contract, { prefix: '/rpc' })
42
+ const spec = openapi(cat, { info: { title: 'Planet API', version: '1.0.0' } })
43
+
44
+ for (const proc of cat.procedures) {
45
+ const http = proc.meta.http as { method?: string } | undefined
46
+ const item = proc.href === undefined ? undefined : spec.paths[proc.href]
47
+ if (http?.method !== 'GET' || !item?.post) continue
48
+ // `content` (a JSON-encoded parameter) is OpenAPI 3.1, wider than `PathItem`'s type.
49
+ Object.assign(item, {
50
+ get: {
51
+ operationId: `${item.post.operationId}Get`,
52
+ parameters: [{
53
+ name: 'input',
54
+ in: 'query',
55
+ content: {
56
+ 'application/json': {
57
+ schema: proc.input?.kind === 'json' ? proc.input.jsonSchema : {},
58
+ },
59
+ },
60
+ }],
61
+ responses: item.post.responses,
62
+ },
63
+ })
64
+ }
65
+ ```
66
+
67
+ A REST facade has its own paths and bodies, so it documents them by hand (or with your REST framework's generator). Reuse the schemas from `catalog()` entries instead of redeclaring them.
68
+
32
69
  ## API
33
70
 
34
71
  - `openapi`
@@ -41,6 +78,6 @@ Typed split-repo clients: `ts-pf-codegen`, not OpenAPI-TS.
41
78
 
42
79
  ## Don't
43
80
 
44
- - GET/PUT/path params or flattened REST bodies.
81
+ - GET/PUT/path params or flattened REST bodies from `openapi()` itself. Post-process the document in userland.
45
82
  - Serve the spec from `FetchHandler`.
46
83
  - Message transports (not HTTP) in this document.