@apifuse/provider-sdk 2.1.0-beta.2 → 2.1.0-beta.21
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/AUTHORING.md +330 -8
- package/CHANGELOG.md +89 -1
- package/README.md +64 -17
- package/SUBMISSION.md +86 -0
- package/bin/apifuse-check.ts +60 -6
- package/bin/apifuse-dev.ts +58 -8
- package/bin/apifuse-pack-check.ts +32 -2
- package/bin/apifuse-pack-smoke.ts +133 -6
- package/bin/apifuse-perf.ts +142 -49
- package/bin/apifuse-record.ts +182 -104
- package/bin/apifuse-submit-check.ts +3243 -0
- package/bin/apifuse.ts +1 -1
- package/dist/auth.d.ts +76 -0
- package/dist/auth.js +436 -0
- package/dist/ceremonies/index.d.ts +41 -0
- package/dist/ceremonies/index.js +490 -0
- package/dist/choice-token.d.ts +24 -0
- package/dist/choice-token.js +74 -0
- package/dist/cli/commands.d.ts +10 -0
- package/dist/cli/commands.js +80 -0
- package/dist/cli/create.d.ts +47 -0
- package/dist/cli/create.js +777 -0
- package/dist/cli/templates/provider/.dockerignore.tpl +22 -0
- package/dist/cli/templates/provider/.gitignore.tpl +22 -0
- package/dist/cli/templates/provider/AGENTS.md.tpl +87 -0
- package/dist/cli/templates/provider/CLAUDE.md.tpl +1 -0
- package/dist/cli/templates/provider/Dockerfile.tpl +7 -0
- package/dist/cli/templates/provider/README.md.tpl +163 -0
- package/dist/cli/templates/provider/dev.ts.tpl +5 -0
- package/dist/cli/templates/provider/domain/README.md.tpl +3 -0
- package/dist/cli/templates/provider/index.test.ts.tpl +13 -0
- package/dist/cli/templates/provider/index.ts.tpl +15 -0
- package/dist/cli/templates/provider/mappers/README.md.tpl +3 -0
- package/dist/cli/templates/provider/meta.ts.tpl +7 -0
- package/dist/cli/templates/provider/operations/index.ts.tpl +5 -0
- package/dist/cli/templates/provider/operations/ping.ts.tpl +24 -0
- package/dist/cli/templates/provider/schemas/ping.ts.tpl +24 -0
- package/dist/cli/templates/provider/skills/fixtures-and-recording/SKILL.md.tpl +58 -0
- package/dist/cli/templates/provider/skills/health-checks-and-fail-closed/SKILL.md.tpl +65 -0
- package/dist/cli/templates/provider/skills/normalization-standards/SKILL.md.tpl +57 -0
- package/dist/cli/templates/provider/skills/pagination-and-counts/SKILL.md.tpl +52 -0
- package/dist/cli/templates/provider/skills/upstream-contract-verification/SKILL.md.tpl +45 -0
- package/dist/cli/templates/provider/skills/upstream-notes/README.md.tpl +13 -0
- package/dist/cli/templates/provider/start.ts.tpl +5 -0
- package/dist/cli/templates/provider/upstream/README.md.tpl +3 -0
- package/dist/config/loader.d.ts +107 -0
- package/dist/config/loader.js +935 -0
- package/dist/contract-json.d.ts +9 -0
- package/dist/contract-json.js +51 -0
- package/dist/contract-serialization.d.ts +4 -0
- package/dist/contract-serialization.js +78 -0
- package/dist/contract-types.d.ts +49 -0
- package/dist/contract-types.js +1 -0
- package/dist/contract.d.ts +6 -0
- package/dist/contract.js +156 -0
- package/dist/define.d.ts +100 -0
- package/dist/define.js +1383 -0
- package/dist/dev.d.ts +9 -0
- package/dist/dev.js +15 -0
- package/dist/errors.d.ts +59 -0
- package/dist/errors.js +97 -0
- package/dist/i18n/catalog.d.ts +29 -0
- package/dist/i18n/catalog.js +159 -0
- package/dist/i18n/index.d.ts +2 -0
- package/dist/i18n/index.js +2 -0
- package/dist/i18n/keys.d.ts +10 -0
- package/dist/i18n/keys.js +34 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.js +38 -0
- package/dist/lint.d.ts +74 -0
- package/dist/lint.js +729 -0
- package/dist/observability.d.ts +5 -0
- package/dist/observability.js +39 -0
- package/dist/provider.d.ts +11 -0
- package/dist/provider.js +9 -0
- package/dist/public-schema-field-lint.d.ts +2 -0
- package/dist/public-schema-field-lint.js +158 -0
- package/dist/recipes/gov-api.d.ts +19 -0
- package/dist/recipes/gov-api.js +72 -0
- package/dist/recipes/rest-api.d.ts +21 -0
- package/dist/recipes/rest-api.js +115 -0
- package/dist/runtime/auth-flow.d.ts +14 -0
- package/dist/runtime/auth-flow.js +46 -0
- package/dist/runtime/browser.d.ts +25 -0
- package/dist/runtime/browser.js +1237 -0
- package/dist/runtime/cache.d.ts +10 -0
- package/dist/runtime/cache.js +372 -0
- package/dist/runtime/choice.d.ts +15 -0
- package/dist/runtime/choice.js +435 -0
- package/dist/runtime/credential.d.ts +8 -0
- package/dist/runtime/credential.js +61 -0
- package/dist/runtime/env.d.ts +2 -0
- package/dist/runtime/env.js +10 -0
- package/dist/runtime/executor.d.ts +16 -0
- package/dist/runtime/executor.js +51 -0
- package/dist/runtime/http.d.ts +8 -0
- package/dist/runtime/http.js +726 -0
- package/dist/runtime/insights.d.ts +9 -0
- package/dist/runtime/insights.js +324 -0
- package/dist/runtime/instrumentation.d.ts +8 -0
- package/dist/runtime/instrumentation.js +269 -0
- package/dist/runtime/key-derivation.d.ts +24 -0
- package/dist/runtime/key-derivation.js +73 -0
- package/dist/runtime/keyring.d.ts +25 -0
- package/dist/runtime/keyring.js +93 -0
- package/dist/runtime/namespace.d.ts +9 -0
- package/dist/runtime/namespace.js +19 -0
- package/dist/runtime/otlp.d.ts +39 -0
- package/dist/runtime/otlp.js +103 -0
- package/dist/runtime/perf.d.ts +12 -0
- package/dist/runtime/perf.js +52 -0
- package/dist/runtime/prevalidate.d.ts +12 -0
- package/dist/runtime/prevalidate.js +173 -0
- package/dist/runtime/provider.d.ts +2 -0
- package/dist/runtime/provider.js +11 -0
- package/dist/runtime/proxy-errors.d.ts +21 -0
- package/dist/runtime/proxy-errors.js +83 -0
- package/dist/runtime/proxy-telemetry.d.ts +8 -0
- package/dist/runtime/proxy-telemetry.js +174 -0
- package/dist/runtime/redis.d.ts +17 -0
- package/dist/runtime/redis.js +82 -0
- package/dist/runtime/request-options.d.ts +3 -0
- package/dist/runtime/request-options.js +42 -0
- package/dist/runtime/state.d.ts +17 -0
- package/dist/runtime/state.js +344 -0
- package/dist/runtime/stealth.d.ts +21 -0
- package/dist/runtime/stealth.js +980 -0
- package/dist/runtime/stt.d.ts +22 -0
- package/dist/runtime/stt.js +480 -0
- package/dist/runtime/trace.d.ts +26 -0
- package/dist/runtime/trace.js +142 -0
- package/dist/runtime/waterfall.d.ts +12 -0
- package/dist/runtime/waterfall.js +147 -0
- package/dist/schema.d.ts +74 -0
- package/dist/schema.js +243 -0
- package/dist/serve.d.ts +1 -0
- package/dist/serve.js +1 -0
- package/dist/server/index.d.ts +3 -0
- package/dist/server/index.js +2 -0
- package/dist/server/serve.d.ts +64 -0
- package/dist/server/serve.js +1118 -0
- package/dist/server/types.d.ts +136 -0
- package/dist/server/types.js +86 -0
- package/dist/stealth/profiles.d.ts +4 -0
- package/dist/stealth/profiles.js +259 -0
- package/dist/stream.d.ts +44 -0
- package/dist/stream.js +151 -0
- package/dist/testing/helpers.d.ts +23 -0
- package/dist/testing/helpers.js +95 -0
- package/dist/testing/index.d.ts +2 -0
- package/dist/testing/index.js +2 -0
- package/dist/testing/run.d.ts +34 -0
- package/dist/testing/run.js +307 -0
- package/dist/types.d.ts +1467 -0
- package/dist/types.js +61 -0
- package/dist/utils/date.d.ts +6 -0
- package/dist/utils/date.js +101 -0
- package/dist/utils/parse.d.ts +16 -0
- package/dist/utils/parse.js +51 -0
- package/dist/utils/text.d.ts +4 -0
- package/dist/utils/text.js +14 -0
- package/dist/utils/transform.d.ts +8 -0
- package/dist/utils/transform.js +48 -0
- package/package.json +57 -29
- package/src/auth.ts +786 -0
- package/src/ceremonies/index.ts +8 -2
- package/src/choice-token.ts +165 -0
- package/src/cli/commands.ts +34 -11
- package/src/cli/create.ts +254 -128
- package/src/cli/templates/provider/.dockerignore.tpl +22 -0
- package/src/cli/templates/provider/.gitignore.tpl +22 -0
- package/src/cli/templates/provider/AGENTS.md.tpl +87 -0
- package/src/cli/templates/provider/CLAUDE.md.tpl +1 -0
- package/src/cli/templates/provider/README.md.tpl +87 -7
- package/src/cli/templates/provider/dev.ts.tpl +1 -1
- package/src/cli/templates/provider/domain/README.md.tpl +3 -0
- package/src/cli/templates/provider/index.ts.tpl +5 -47
- package/src/cli/templates/provider/mappers/README.md.tpl +3 -0
- package/src/cli/templates/provider/meta.ts.tpl +7 -0
- package/src/cli/templates/provider/operations/index.ts.tpl +5 -0
- package/src/cli/templates/provider/operations/ping.ts.tpl +24 -0
- package/src/cli/templates/provider/schemas/ping.ts.tpl +24 -0
- package/src/cli/templates/provider/skills/fixtures-and-recording/SKILL.md.tpl +58 -0
- package/src/cli/templates/provider/skills/health-checks-and-fail-closed/SKILL.md.tpl +65 -0
- package/src/cli/templates/provider/skills/normalization-standards/SKILL.md.tpl +57 -0
- package/src/cli/templates/provider/skills/pagination-and-counts/SKILL.md.tpl +52 -0
- package/src/cli/templates/provider/skills/upstream-contract-verification/SKILL.md.tpl +45 -0
- package/src/cli/templates/provider/skills/upstream-notes/README.md.tpl +13 -0
- package/src/cli/templates/provider/start.ts.tpl +1 -1
- package/src/cli/templates/provider/upstream/README.md.tpl +3 -0
- package/src/config/loader.ts +1224 -9
- package/src/contract-json.ts +75 -0
- package/src/contract-serialization.ts +89 -0
- package/src/contract-types.ts +52 -0
- package/src/contract.ts +216 -0
- package/src/define.ts +1820 -70
- package/src/errors.ts +27 -0
- package/src/i18n/catalog.ts +277 -0
- package/src/i18n/index.ts +2 -0
- package/src/i18n/keys.ts +64 -0
- package/src/index.ts +189 -9
- package/src/lint.ts +580 -73
- package/src/observability.ts +41 -0
- package/src/provider.ts +131 -4
- package/src/public-schema-field-lint.ts +237 -0
- package/src/runtime/auth-flow.ts +9 -0
- package/src/runtime/browser.ts +1054 -51
- package/src/runtime/cache.ts +528 -0
- package/src/runtime/choice.ts +760 -0
- package/src/runtime/executor.ts +32 -3
- package/src/runtime/http.ts +980 -195
- package/src/runtime/insights.ts +11 -11
- package/src/runtime/instrumentation.ts +12 -4
- package/src/runtime/key-derivation.ts +1 -1
- package/src/runtime/keyring.ts +4 -3
- package/src/runtime/proxy-errors.ts +132 -0
- package/src/runtime/proxy-telemetry.ts +253 -0
- package/src/runtime/redis.ts +116 -0
- package/src/runtime/request-options.ts +66 -0
- package/src/runtime/state.ts +563 -0
- package/src/runtime/stealth.ts +1336 -0
- package/src/runtime/stt.ts +629 -0
- package/src/runtime/trace.ts +1 -1
- package/src/schema.ts +363 -1
- package/src/server/serve.ts +1192 -75
- package/src/server/types.ts +37 -0
- package/src/stream.ts +210 -0
- package/src/testing/run.ts +40 -6
- package/src/types.ts +1283 -59
- package/src/runtime/tls.ts +0 -434
- package/src/types/playwright-stealth.d.ts +0 -9
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
node_modules/
|
|
2
|
+
|
|
3
|
+
# Environment and local secrets
|
|
4
|
+
.env
|
|
5
|
+
.env.*
|
|
6
|
+
!.env.example
|
|
7
|
+
|
|
8
|
+
# Build, coverage, cache, and local runtime artifacts
|
|
9
|
+
coverage/
|
|
10
|
+
dist/
|
|
11
|
+
.cache/
|
|
12
|
+
.turbo/
|
|
13
|
+
.bun/
|
|
14
|
+
*.tsbuildinfo
|
|
15
|
+
|
|
16
|
+
# Bounty submission output
|
|
17
|
+
submission-report.md
|
|
18
|
+
|
|
19
|
+
# OS/editor junk
|
|
20
|
+
.DS_Store
|
|
21
|
+
Thumbs.db
|
|
22
|
+
*.swp
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# APIFuse Provider Workspace — Agent Guide
|
|
2
|
+
|
|
3
|
+
You are building an APIFuse provider. APIFuse turns messy upstream APIs into
|
|
4
|
+
normalized, typed, evidence-backed public APIs. A provider that merely proxies
|
|
5
|
+
the upstream is a failed provider, even if every check passes.
|
|
6
|
+
|
|
7
|
+
This file is the core contract. Detailed procedures live in `skills/` — load
|
|
8
|
+
the matching skill BEFORE working on that area (index at the bottom).
|
|
9
|
+
|
|
10
|
+
## Non-negotiable principles
|
|
11
|
+
|
|
12
|
+
### 1. Normalize, don't proxy
|
|
13
|
+
Public output is an APIFuse contract, not the upstream's shape.
|
|
14
|
+
- Field names: `snake_case`, semantic, English. Never leak vendor keys
|
|
15
|
+
(`dutyTel1`, `hvec`, `MKioskTy7`) into public output.
|
|
16
|
+
- Timestamps: ISO 8601 in public output. Vendor formats (`20260707222855`)
|
|
17
|
+
are parsed inside mappers only. If a value cannot be parsed, omit/null it —
|
|
18
|
+
never pass the raw vendor string through.
|
|
19
|
+
- Enums: normalize vendor status text/codes (`Y` / `불가능` / `정보미제공`) into a
|
|
20
|
+
declared enum. Mixed raw-text passthrough is a contract failure.
|
|
21
|
+
- Units: every numeric field name states its unit (`distance_meters`), and the
|
|
22
|
+
mapper proves the conversion. Never relabel an upstream number without
|
|
23
|
+
verifying its unit against docs or live data.
|
|
24
|
+
|
|
25
|
+
### 2. Fail closed, never fabricate
|
|
26
|
+
- Never invent output values to satisfy a schema. Missing upstream data → null
|
|
27
|
+
field or structured error, never a plausible dummy.
|
|
28
|
+
- Parse failures are errors, not defaults. Returning `0`, `[]`, or `null`
|
|
29
|
+
when the upstream shape changed hides breakage from every downstream gate.
|
|
30
|
+
- If a non-empty upstream collection normalizes to zero rows, throw
|
|
31
|
+
`UPSTREAM_SCHEMA_ERROR` — silent empty success is the worst failure mode.
|
|
32
|
+
- Model the upstream's real value domain. Check live data before adding
|
|
33
|
+
constraints like `nonnegative()` — some upstreams legitimately return
|
|
34
|
+
negative counts (e.g. overcapacity) and a wrong constraint silently
|
|
35
|
+
nulls real data.
|
|
36
|
+
|
|
37
|
+
### 3. Preserve every input or fail loudly
|
|
38
|
+
- Every accepted input must be representable in the upstream request. If it
|
|
39
|
+
isn't, reject at the schema or throw — never silently drop it.
|
|
40
|
+
- Upstream parameter dependencies (param B ignored without param A) must be
|
|
41
|
+
enforced in YOUR schema. The upstream ignoring input silently is not an
|
|
42
|
+
excuse for your provider to do the same.
|
|
43
|
+
|
|
44
|
+
### 4. Evidence over assumption
|
|
45
|
+
- Upstream parameter names and response fields must be verified against the
|
|
46
|
+
official spec AND at least one live call. Do not guess casing or
|
|
47
|
+
underscores; do not copy from a sibling API without re-verifying.
|
|
48
|
+
- No speculative field probing (`row.distance ?? row.dist ?? row.Distance`).
|
|
49
|
+
Map exactly the fields you have evidence for. One verified name per field.
|
|
50
|
+
- Fixtures are recorded live evidence (`bun run record`), never hand-written.
|
|
51
|
+
Placeholder-looking values (`02-1234-5678`, "테헤란로 123") mean the fixture
|
|
52
|
+
is fabricated and the submission is not reviewable.
|
|
53
|
+
- An empty result set from a dense query (0 hospitals within 5km of a city
|
|
54
|
+
center) is a request bug, not a valid fixture. Investigate before recording.
|
|
55
|
+
|
|
56
|
+
### 5. Honest pagination and counts
|
|
57
|
+
- If you filter rows client-side, the upstream `totalCount` is no longer your
|
|
58
|
+
`total_count`. Either expose upstream semantics honestly (documented) or
|
|
59
|
+
don't expose a total at all. A count the caller cannot page against is a lie.
|
|
60
|
+
|
|
61
|
+
### 6. Health checks must detect real regressions
|
|
62
|
+
- `Array.isArray(data.items)` alone can never fail. Every list operation's
|
|
63
|
+
health check must also flag the zero-rows case for a query that is known to
|
|
64
|
+
return data (dense-area query), so a broken upstream contract degrades
|
|
65
|
+
visibly instead of passing forever.
|
|
66
|
+
|
|
67
|
+
## Verification loop (before every submit)
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
bun run check # apifuse check + type-check
|
|
71
|
+
bun run test # your tests — cover mappers, error paths, edge rows
|
|
72
|
+
bun run submit-check # structural score; a high score does NOT prove quality
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
`submit-check` is a structural gate. Every principle above can be violated
|
|
76
|
+
while scoring 95/100 — reviewers and CI audit for exactly these classes.
|
|
77
|
+
|
|
78
|
+
## Skill index — load before working on:
|
|
79
|
+
|
|
80
|
+
| Area | Load |
|
|
81
|
+
| --- | --- |
|
|
82
|
+
| Output schemas, mappers, field naming, timestamps, enums | `skills/normalization-standards/SKILL.md` |
|
|
83
|
+
| Upstream request params, new endpoint wiring, field mapping | `skills/upstream-contract-verification/SKILL.md` |
|
|
84
|
+
| Recording fixtures, writing tests against fixtures | `skills/fixtures-and-recording/SKILL.md` |
|
|
85
|
+
| List operations, paging, totals, client-side filtering | `skills/pagination-and-counts/SKILL.md` |
|
|
86
|
+
| healthCheck blocks, error classification, fail-closed guards | `skills/health-checks-and-fail-closed/SKILL.md` |
|
|
87
|
+
| Upstream-specific known pitfalls for THIS bounty | `skills/upstream-notes/` (read every file) |
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@AGENTS.md
|
|
@@ -8,6 +8,68 @@ Generated with `apifuse create`.
|
|
|
8
8
|
bun run dev
|
|
9
9
|
bun run check
|
|
10
10
|
bun run test
|
|
11
|
+
bun run submit-check -- --smoke
|
|
12
|
+
bunx apifuse perf . --operation <operation-id> --runs 3
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
## Module layout
|
|
17
|
+
|
|
18
|
+
The generated provider uses the recommended split layout:
|
|
19
|
+
|
|
20
|
+
```text
|
|
21
|
+
index.ts # composition root: defineProvider() and wiring only
|
|
22
|
+
meta.ts # provider metadata
|
|
23
|
+
operations/ # APIFuse operation contracts and handlers
|
|
24
|
+
schemas/ # public input/output schemas near operations
|
|
25
|
+
upstream/ # upstream ceremony: clients, auth, request builders
|
|
26
|
+
mappers/ # upstream-to-APIFuse normalization helpers
|
|
27
|
+
domain/ # shared provider-specific business ceremony
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Small providers may stay in one file, but larger providers are easier to
|
|
31
|
+
review when `index.ts` remains a short composition root.
|
|
32
|
+
|
|
33
|
+
## Pre-submission report
|
|
34
|
+
|
|
35
|
+
Before posting bounty evidence, run:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
bun run submit-check -- --smoke
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
This writes `submission-report.md` with a review-readiness score, blockers,
|
|
42
|
+
warnings, health coverage notes, fixture/schema evidence, and remediation. A
|
|
43
|
+
score is not a payout guarantee; blockers must be fixed before maintainer
|
|
44
|
+
review. The generated `ping` starter intentionally warns until you replace it
|
|
45
|
+
with real upstream-backed Operations. `APIFUSE__PROVIDER__*` env vars enable
|
|
46
|
+
live upstream calls; without them, structured provider errors can still verify
|
|
47
|
+
runtime routing. The full public-only checklist is shipped in
|
|
48
|
+
`node_modules/@apifuse/provider-sdk/SUBMISSION.md`.
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
## Operation guide
|
|
52
|
+
|
|
53
|
+
### Parameters
|
|
54
|
+
|
|
55
|
+
Starter `ping` accepts `{ "value": string }`. Replace this section with each
|
|
56
|
+
real operation's input schema, required fields, formats, limits, and examples
|
|
57
|
+
before submitting bounty evidence.
|
|
58
|
+
|
|
59
|
+
### Response
|
|
60
|
+
|
|
61
|
+
Starter `ping` returns `{ "ok": boolean, "message": string }`. Replace this
|
|
62
|
+
section with the normalized response fields, units, enum values, pagination,
|
|
63
|
+
and upstream caveats for each real operation.
|
|
64
|
+
|
|
65
|
+
### Example
|
|
66
|
+
|
|
67
|
+
```json
|
|
68
|
+
{
|
|
69
|
+
"requestId": "req_local_ping",
|
|
70
|
+
"input": { "value": "hello" },
|
|
71
|
+
"headers": {}
|
|
72
|
+
}
|
|
11
73
|
```
|
|
12
74
|
|
|
13
75
|
## Provider server contract
|
|
@@ -51,18 +113,18 @@ Structured errors return an `error` object with `code`, `message`,
|
|
|
51
113
|
`connection.secrets`, and read them with `ctx.credential`.
|
|
52
114
|
- Auth flow: call `/auth/start`, then `/auth/continue` with the same `flowId`;
|
|
53
115
|
carry returned `contextPatch` values into the next request's `context`.
|
|
54
|
-
-
|
|
55
|
-
|
|
56
|
-
`ctx.
|
|
57
|
-
`browser.engine: "playwright-stealth"`
|
|
58
|
-
then install local Chromium with
|
|
59
|
-
`
|
|
116
|
+
- Stealth/browser runtime: keep access-sensitive operations on `ctx.stealth.fetch()` with an
|
|
117
|
+
SDK stealth `profile`; the TypeScript stealth runtime uses `impit` internally.
|
|
118
|
+
`ctx.stealth` supports Chrome/Firefox-style profiles. For TypeScript browser
|
|
119
|
+
Providers or Safari-specific behavior use `browser.engine: "playwright-stealth"`
|
|
120
|
+
(`nodriver` is Python-runtime only), then install local Chromium with
|
|
121
|
+
`bunx playwright install chromium` or set `APIFUSE__CDP_POOL__URL`.
|
|
60
122
|
|
|
61
123
|
## Next steps
|
|
62
124
|
|
|
63
125
|
1. Replace the sample `ping` operation with real upstream logic.
|
|
64
126
|
2. Once the real operation declares `upstream.baseUrl` and uses `ctx.http` or
|
|
65
|
-
`ctx.
|
|
127
|
+
`ctx.stealth`, record a fixture with:
|
|
66
128
|
`bun run record -- --operation <operation> --params '<json-input>'`.
|
|
67
129
|
3. Replace the starter `healthCheckUnsupported` with a real `healthCheck` for read-only upstream operations when safe.
|
|
68
130
|
4. Extend tests and operation metadata until the provider is bounty-ready.
|
|
@@ -81,3 +143,21 @@ Every operation must declare exactly one of:
|
|
|
81
143
|
|
|
82
144
|
The generated `ping` operation uses `healthCheckUnsupported` only because it is
|
|
83
145
|
a local scaffold check, not a real upstream API probe.
|
|
146
|
+
|
|
147
|
+
`healthCheck.cases[].assertions` receives `{ data, status, durationMs, meta }`.
|
|
148
|
+
`data` is the parsed operation output. Use this shape in real operations:
|
|
149
|
+
|
|
150
|
+
```ts
|
|
151
|
+
healthCheck: {
|
|
152
|
+
interval: "5m",
|
|
153
|
+
cases: [{
|
|
154
|
+
name: "lookup baseline",
|
|
155
|
+
input: { q: "btc" },
|
|
156
|
+
assertions: ({ data, status, durationMs }) => {
|
|
157
|
+
if (status !== 200 || data.results.length === 0 || durationMs > 3000) {
|
|
158
|
+
return { status: "degraded", label: "lookup baseline changed" };
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
}],
|
|
162
|
+
}
|
|
163
|
+
```
|
|
@@ -1,23 +1,7 @@
|
|
|
1
|
-
import { defineProvider
|
|
1
|
+
import { defineProvider } from "@apifuse/provider-sdk/provider";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
value: z
|
|
6
|
-
.string()
|
|
7
|
-
.describe("Sample input value used to verify the generated provider scaffold is wired correctly."),
|
|
8
|
-
})
|
|
9
|
-
.describe("Input payload for the generated ping operation.");
|
|
10
|
-
|
|
11
|
-
const OutputSchema = z
|
|
12
|
-
.object({
|
|
13
|
-
ok: z
|
|
14
|
-
.boolean()
|
|
15
|
-
.describe("Whether the generated provider handled the sample request successfully."),
|
|
16
|
-
message: z
|
|
17
|
-
.string()
|
|
18
|
-
.describe("Human-readable confirmation that the generated provider round-tripped the sample payload."),
|
|
19
|
-
})
|
|
20
|
-
.describe("Output payload returned by the generated ping operation.");
|
|
3
|
+
import { providerMeta } from "./meta";
|
|
4
|
+
import { operations } from "./operations";
|
|
21
5
|
|
|
22
6
|
export default defineProvider({
|
|
23
7
|
id: "{{PROVIDER_ID}}",
|
|
@@ -26,32 +10,6 @@ export default defineProvider({
|
|
|
26
10
|
allowedHosts: ["api.example.com"],
|
|
27
11
|
reviewed: "community",
|
|
28
12
|
{{SECRETS_BLOCK}}{{CREDENTIAL_BLOCK}}auth: {{AUTH_BLOCK}},
|
|
29
|
-
meta:
|
|
30
|
-
|
|
31
|
-
description: "{{DISPLAY_NAME}} provider starter for ApiFuse community contributions.",
|
|
32
|
-
category: "{{CATEGORY}}",
|
|
33
|
-
tags: ["{{PROVIDER_ID}}", "starter", "community"],
|
|
34
|
-
},
|
|
35
|
-
operations: {
|
|
36
|
-
ping: {
|
|
37
|
-
description:
|
|
38
|
-
"Confirms the generated provider wiring is operational by echoing a small sample payload through the ApiFuse runtime contract. Use when validating local development, baseline checks, or first-pass bounty scaffolds. Do NOT use for production data retrieval or upstream-specific workflows because this starter operation exists only to prove the generated project compiles, serves, and round-trips input/output correctly. Returns a success flag plus a message containing the supplied value.",
|
|
39
|
-
input: InputSchema,
|
|
40
|
-
output: OutputSchema,
|
|
41
|
-
handler: async (_ctx, input) => {
|
|
42
|
-
return {
|
|
43
|
-
ok: true,
|
|
44
|
-
message: "{{DISPLAY_NAME}} received: " + input.value,
|
|
45
|
-
};
|
|
46
|
-
},
|
|
47
|
-
fixtures: {
|
|
48
|
-
request: { value: "hello" },
|
|
49
|
-
response: { ok: true, message: "{{DISPLAY_NAME}} received: hello" },
|
|
50
|
-
},
|
|
51
|
-
healthCheckUnsupported: {
|
|
52
|
-
reason:
|
|
53
|
-
"Generated local-only scaffold operation. Replace this with a real healthCheck for upstream-backed bounty operations when safe; keep healthCheckUnsupported only for destructive, paid, credential-sensitive, or otherwise unprobeable operations with a specific rationale.",
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
},
|
|
13
|
+
meta: providerMeta,
|
|
14
|
+
operations: operations,
|
|
57
15
|
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { defineOperation } from "@apifuse/provider-sdk/provider";
|
|
2
|
+
|
|
3
|
+
import { pingInputSchema, pingOutputSchema } from "../schemas/ping";
|
|
4
|
+
|
|
5
|
+
export const pingOperation = defineOperation({
|
|
6
|
+
descriptionKey: "operations.ping.description",
|
|
7
|
+
input: pingInputSchema,
|
|
8
|
+
output: pingOutputSchema,
|
|
9
|
+
handler: async ({{HANDLER_CTX}}, input) => {
|
|
10
|
+
{{BROWSER_HANDLER_BLOCK}}
|
|
11
|
+
return {
|
|
12
|
+
ok: true,
|
|
13
|
+
message: "{{DISPLAY_NAME}} received: " + input.value{{BROWSER_RESPONSE_FIELDS}},
|
|
14
|
+
};
|
|
15
|
+
},
|
|
16
|
+
fixtures: {
|
|
17
|
+
request: { value: "hello" },
|
|
18
|
+
response: { ok: true, message: "{{DISPLAY_NAME}} received: hello" },
|
|
19
|
+
},
|
|
20
|
+
healthCheckUnsupported: {
|
|
21
|
+
reason:
|
|
22
|
+
"Generated local-only scaffold operation. Replace this with a real healthCheck for upstream-backed bounty operations when safe; keep healthCheckUnsupported only for destructive, paid, credential-sensitive, or otherwise unprobeable operations with a specific rationale.",
|
|
23
|
+
},
|
|
24
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { describeKey, z } from "@apifuse/provider-sdk/provider";
|
|
2
|
+
|
|
3
|
+
export const pingInputSchema = describeKey(
|
|
4
|
+
z.object({
|
|
5
|
+
value: describeKey(z.string(), "schemaDescriptions.input.value"),
|
|
6
|
+
}),
|
|
7
|
+
"schemaDescriptions.input.root",
|
|
8
|
+
);
|
|
9
|
+
|
|
10
|
+
export const pingOutputSchema = describeKey(
|
|
11
|
+
z.object({
|
|
12
|
+
ok: describeKey(z.boolean(), "schemaDescriptions.output.ok"),
|
|
13
|
+
message: describeKey(z.string(), "schemaDescriptions.output.message"),
|
|
14
|
+
pageTitle: describeKey(
|
|
15
|
+
z.string().optional(),
|
|
16
|
+
"schemaDescriptions.output.pageTitle",
|
|
17
|
+
),
|
|
18
|
+
frameCount: describeKey(
|
|
19
|
+
z.number().int().nonnegative().optional(),
|
|
20
|
+
"schemaDescriptions.output.frameCount",
|
|
21
|
+
),
|
|
22
|
+
}),
|
|
23
|
+
"schemaDescriptions.output.root",
|
|
24
|
+
);
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: fixtures-and-recording
|
|
3
|
+
description: Recording live fixtures and writing trustworthy tests from them. Load before touching __fixtures__/ or writing operation tests.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Fixtures and recording
|
|
7
|
+
|
|
8
|
+
Fixtures are evidence, not examples. Reviewers treat fixtures as proof your
|
|
9
|
+
provider ran against the real upstream.
|
|
10
|
+
|
|
11
|
+
## Recording
|
|
12
|
+
- Always record from the live upstream: `bun run record -- --operation <op>
|
|
13
|
+
--params '<json>'` with the real service key configured.
|
|
14
|
+
- Record queries that RETURN DATA. Choose dense/known-good inputs (major city
|
|
15
|
+
district, a real entity id from a prior list call).
|
|
16
|
+
- Re-record after any request-param or mapper change; stale fixtures make
|
|
17
|
+
every downstream test meaningless.
|
|
18
|
+
|
|
19
|
+
## Forbidden fixture states
|
|
20
|
+
- **Hand-written fixtures.** Values like `02-1234-5678`, "테헤란로 123",
|
|
21
|
+
round-number coordinates, or sequential ids are fabrication tells. If it
|
|
22
|
+
wasn't returned by the upstream, it cannot be in `__fixtures__/`.
|
|
23
|
+
- **Empty-result fixtures for dense queries.** `items: [], total_count: 0`
|
|
24
|
+
for "hospitals within 5km of Gangnam" is not a fixture — it is an
|
|
25
|
+
unfixed request bug (wrong param name/format). Investigate first.
|
|
26
|
+
- **Fixtures that contradict each other.** If one operation's fixture proves
|
|
27
|
+
`total_count: 541` while returning 1 filtered row, your count semantics are
|
|
28
|
+
broken (see pagination skill), not your fixture.
|
|
29
|
+
|
|
30
|
+
## Fixture shape
|
|
31
|
+
`apifuse record` (`bun run record`) writes the captured RAW UPSTREAM payload
|
|
32
|
+
to `__fixtures__/raw.json` (secrets sanitized). With `--append` it
|
|
33
|
+
accumulates an array of raw payloads. The recorder does NOT write your
|
|
34
|
+
normalized output — raw.json is upstream evidence only.
|
|
35
|
+
|
|
36
|
+
Derive normalized expectations in TESTS, not in the fixture file: load the
|
|
37
|
+
recorded raw payload, run your mapper over it, and assert the exact expected
|
|
38
|
+
normalized rows inline in the test. If you keep expected-output snapshots,
|
|
39
|
+
generate them from the mapper and review them row by row — never hand-author
|
|
40
|
+
values that the upstream did not return.
|
|
41
|
+
|
|
42
|
+
## Tests to derive from fixtures
|
|
43
|
+
- Mapper: `map(recordedUpstreamRow)` equals the expected normalized row
|
|
44
|
+
(toEqual, not toMatchObject, for full rows — partial matching hides
|
|
45
|
+
dropped fields).
|
|
46
|
+
- Edge rows: single-item object vs array (`items.item` unwrapping), missing
|
|
47
|
+
optional fields, unpadded/numeric time values, vendor error headers.
|
|
48
|
+
- Error paths: upstream error `resultCode`, HTTP failure, missing secret,
|
|
49
|
+
NO_DATA — each asserts the structured `ProviderError` code.
|
|
50
|
+
- Handler-level: run the operation handler against a mock ctx that returns
|
|
51
|
+
the fixture upstream body; assert the full normalized envelope.
|
|
52
|
+
|
|
53
|
+
## Checklist
|
|
54
|
+
- [ ] Every fixture recorded live; no placeholder-looking values
|
|
55
|
+
- [ ] No empty-result fixture for a query that must have data
|
|
56
|
+
- [ ] normalized expectations derived from mapper(recorded raw), not
|
|
57
|
+
hand-authored
|
|
58
|
+
- [ ] Error and edge-shape rows covered, not just the happy row
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: health-checks-and-fail-closed
|
|
3
|
+
description: Writing health checks that can actually fail, and fail-closed guards at envelope and row level. Load before writing healthCheck blocks or error handling.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Health checks and fail-closed guards
|
|
7
|
+
|
|
8
|
+
## Health checks that can actually fail
|
|
9
|
+
`Array.isArray(data.items)` alone can never fail. Every list operation's
|
|
10
|
+
health check must be able to detect the zero-rows regression.
|
|
11
|
+
|
|
12
|
+
Assertion contract (per SDK `HealthCheckCase`): THROW to fail the case
|
|
13
|
+
(recorded as `down`); return `{ status: "degraded", label }` to flag without
|
|
14
|
+
failing; return nothing for `ok`. There is no `"down"` return value.
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
assertions: ({ status, data }) => {
|
|
18
|
+
if (status !== 200) {
|
|
19
|
+
throw new Error(`<op> request failed with status ${status}`);
|
|
20
|
+
}
|
|
21
|
+
if (!Array.isArray(data.items)) {
|
|
22
|
+
throw new Error("<op> missing items array");
|
|
23
|
+
}
|
|
24
|
+
// Dense query MUST return rows; zero rows = upstream contract drift
|
|
25
|
+
if (data.items.length === 0) {
|
|
26
|
+
return { status: "degraded", label: "<op> dense query returned 0 rows" };
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
- Choose health-check inputs that are guaranteed-dense (major city district,
|
|
32
|
+
a stable well-known entity id). Verify the id still exists when picking it.
|
|
33
|
+
- Also assert one semantic field on the first row (e.g. `items[0].name` is a
|
|
34
|
+
non-empty string) so a mapper regression that empties fields degrades too.
|
|
35
|
+
|
|
36
|
+
## Fail-closed: envelope level
|
|
37
|
+
- Upstream error headers/codes → structured `ProviderError` with a stable
|
|
38
|
+
`code` (`UPSTREAM_AUTH_ERROR`, `UPSTREAM_ERROR`, `NO_DATA`, ...).
|
|
39
|
+
- Non-JSON body, unexpected content type → `UPSTREAM_SCHEMA_ERROR`.
|
|
40
|
+
- HTTP non-2xx → classified error; never a fake empty success envelope.
|
|
41
|
+
Fixture-based tests cannot catch swallowed errors — write an explicit test:
|
|
42
|
+
mock a non-ok response and assert the handler REJECTS.
|
|
43
|
+
|
|
44
|
+
## Fail-closed: row level
|
|
45
|
+
Envelope guards are not enough. The silent killer is: response is valid,
|
|
46
|
+
array is non-empty, but every row normalizes to nothing.
|
|
47
|
+
- If a non-empty upstream collection produces zero normalized rows, throw
|
|
48
|
+
`UPSTREAM_SCHEMA_ERROR` instead of returning `items: []`.
|
|
49
|
+
- Identity fields (id, name) missing on a row → throw, don't skip the row
|
|
50
|
+
silently.
|
|
51
|
+
- Regression-test both layers separately: a bad envelope AND a good envelope
|
|
52
|
+
with unmappable rows.
|
|
53
|
+
|
|
54
|
+
## Error message hygiene
|
|
55
|
+
`ProviderError.message` reaches the tenant verbatim. Never interpolate
|
|
56
|
+
upstream free text that may contain personal data (names, phone numbers,
|
|
57
|
+
addresses); allowlist known code tokens and keep raw bodies in server-side
|
|
58
|
+
details/logs only.
|
|
59
|
+
|
|
60
|
+
## Checklist
|
|
61
|
+
- [ ] Every list op health check flags 0 rows on a dense query
|
|
62
|
+
- [ ] One semantic field asserted on a real row
|
|
63
|
+
- [ ] Swallowed-error test exists (non-ok mock → handler rejects)
|
|
64
|
+
- [ ] Non-empty upstream → zero normalized rows throws
|
|
65
|
+
- [ ] No upstream free text in customer-facing error messages
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: normalization-standards
|
|
3
|
+
description: Public output contract rules — field naming, timestamps, enums, units, nullability. Load before writing or editing any output schema or mapper.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Normalization standards
|
|
7
|
+
|
|
8
|
+
Public output is the product. Apply these to every schema + mapper pair.
|
|
9
|
+
|
|
10
|
+
## Field naming
|
|
11
|
+
- `snake_case`, English, semantic. `emergency_phone`, not `dutyTel3`.
|
|
12
|
+
- Never expose vendor key vocabularies (`hv1`..`hv12`, `MKioskTy*`, `duty*`)
|
|
13
|
+
as public field names OR as dynamic record keys. A
|
|
14
|
+
`z.record(z.string(), ...)` keyed by vendor codes is still a vendor leak —
|
|
15
|
+
map codes to a stable public vocabulary (enum keys or an array of
|
|
16
|
+
`{ code, label, status }` objects with normalized status).
|
|
17
|
+
|
|
18
|
+
## Timestamps and dates
|
|
19
|
+
- Public: ISO 8601 (`2026-07-07T22:28:55+09:00`, dates `2026-07-07`,
|
|
20
|
+
clock times `HH:MM`). Include the upstream's timezone offset; Korean public
|
|
21
|
+
APIs are KST (+09:00) — verify, then encode it.
|
|
22
|
+
- Vendor formats (`YYYYMMDDHHmmss`, `HHmm`, unpadded `900`) are parsed inside
|
|
23
|
+
the mapper. Unparseable → `null`, plus a test for that row shape.
|
|
24
|
+
- Never emit a raw vendor timestamp string in public output, including
|
|
25
|
+
fixtures.
|
|
26
|
+
|
|
27
|
+
## Enums
|
|
28
|
+
- Vendor status values (codes, `Y`/`N`, Korean labels like `불가능`,
|
|
29
|
+
`정보미제공`) → declared `z.enum`. Unknown value → explicit `unknown` member
|
|
30
|
+
or fail closed; never pass raw text through.
|
|
31
|
+
- Map from the OFFICIAL code table, not from guessing what live samples mean.
|
|
32
|
+
Add a regression test per enum member.
|
|
33
|
+
|
|
34
|
+
## Numbers and units
|
|
35
|
+
- Field name states the unit: `distance_meters`, `radius_meters`,
|
|
36
|
+
`price_krw`. Mapper proves the conversion (upstream km → `* 1000`).
|
|
37
|
+
- Verify the upstream unit from spec or live-data sanity check (a "distance"
|
|
38
|
+
of `1.2` from a nearby search is km, not meters). Sibling endpoints of the
|
|
39
|
+
same vendor may differ — verify each one.
|
|
40
|
+
- Value-domain constraints (`nonnegative`, `min`, `max`) must reflect the
|
|
41
|
+
upstream's REAL domain observed in live data, not what seems sensible.
|
|
42
|
+
A wrong `nonnegative()` turns real negative values into `null`/errors
|
|
43
|
+
silently.
|
|
44
|
+
|
|
45
|
+
## Nullability
|
|
46
|
+
- `null` means "upstream did not provide it" — never "parsing failed" and
|
|
47
|
+
never a placeholder for invented data.
|
|
48
|
+
- Required-for-identity fields (ids, names) missing → throw
|
|
49
|
+
`UPSTREAM_SCHEMA_ERROR`; do not emit partial rows.
|
|
50
|
+
|
|
51
|
+
## Checklist before submitting a schema/mapper change
|
|
52
|
+
- [ ] No vendor key visible in any public field name or record key
|
|
53
|
+
- [ ] All timestamps ISO 8601 with timezone; parsing tested for real vendor
|
|
54
|
+
shapes (padded/unpadded, string/number)
|
|
55
|
+
- [ ] All status-like strings are declared enums with official-table mapping
|
|
56
|
+
- [ ] Every numeric field's unit is in its name and conversion is tested
|
|
57
|
+
- [ ] Constraints checked against live data, not intuition
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: pagination-and-counts
|
|
3
|
+
description: total_count semantics, client-side filtering, and paging honesty. Load before implementing any list/search operation.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Pagination and counts
|
|
7
|
+
|
|
8
|
+
A caller uses `total_count`, `page`, and `limit` to plan iteration. If those
|
|
9
|
+
numbers don't describe what the caller can actually page through, the
|
|
10
|
+
operation is lying.
|
|
11
|
+
|
|
12
|
+
## The client-side filtering trap
|
|
13
|
+
If the upstream has no server-side filter for one of your inputs (e.g. no
|
|
14
|
+
radius param) and you filter rows after fetching:
|
|
15
|
+
|
|
16
|
+
- Upstream `totalCount` counts UNFILTERED rows. Returning it as your
|
|
17
|
+
`total_count` while returning filtered rows means: caller sees
|
|
18
|
+
`total_count: 541`, gets 1 row on page 1, and pages 2..28 return rows that
|
|
19
|
+
are outside the filter or empty. This is a contract failure, not a nuance.
|
|
20
|
+
|
|
21
|
+
Acceptable resolutions, in preference order:
|
|
22
|
+
1. **Don't accept the input.** If the upstream can't filter by it and you
|
|
23
|
+
can't enumerate all pages, drop the input from the schema and document the
|
|
24
|
+
upstream's real semantics (e.g. "results are distance-sorted; no radius
|
|
25
|
+
cutoff").
|
|
26
|
+
2. **Expose upstream semantics honestly.** Distance-sorted paging with a
|
|
27
|
+
documented "no radius filter" contract and no fake `radius` input.
|
|
28
|
+
3. **Filter AND fix the metadata.** If you must filter client-side, do not
|
|
29
|
+
return the upstream total. Return only what you can prove (`returned_count`
|
|
30
|
+
plus a `has_more` you can actually compute) and document that totals are
|
|
31
|
+
unavailable.
|
|
32
|
+
|
|
33
|
+
Never combine: accepted filter input + client-side filter + upstream total.
|
|
34
|
+
|
|
35
|
+
## Count integrity
|
|
36
|
+
- Parse failure of `totalCount` → `UPSTREAM_SCHEMA_ERROR`, not `0`.
|
|
37
|
+
A fail-open zero disguises upstream drift as an empty dataset.
|
|
38
|
+
- If `total_count > 0` but the page's row array normalizes to empty on
|
|
39
|
+
page 1, throw — that combination means broken extraction, not empty data.
|
|
40
|
+
|
|
41
|
+
## Page/limit echo
|
|
42
|
+
- Echo the EFFECTIVE values: if you clamp `limit` to the upstream max, return
|
|
43
|
+
the clamped value, not the requested one.
|
|
44
|
+
- `page`/`limit` semantics must match the upstream's paging model
|
|
45
|
+
(1-indexed vs 0-indexed) — verify with two live pages, checking the
|
|
46
|
+
returned rows actually differ.
|
|
47
|
+
|
|
48
|
+
## Checklist
|
|
49
|
+
- [ ] No input is filtered client-side while `total_count` comes from upstream
|
|
50
|
+
- [ ] totalCount parse failure fails closed
|
|
51
|
+
- [ ] Effective (clamped) limit echoed
|
|
52
|
+
- [ ] Two-page live check proves paging advances
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: upstream-contract-verification
|
|
3
|
+
description: How to establish evidence for upstream request params and response fields before coding. Load before wiring any new endpoint or mapping new fields.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Upstream contract verification
|
|
7
|
+
|
|
8
|
+
Most provider P0s come from guessed upstream contracts. Every param name and
|
|
9
|
+
response field needs evidence BEFORE it ships.
|
|
10
|
+
|
|
11
|
+
## Request parameters
|
|
12
|
+
1. Start from the official spec document (data.go.kr 활용가이드, vendor API
|
|
13
|
+
docs). Copy exact names — casing and underscores matter
|
|
14
|
+
(`WGS84_LAT` ≠ `WGS84LAT`; the wrong one is often silently ignored).
|
|
15
|
+
2. Confirm with ONE live call per endpoint. A param being ignored does not
|
|
16
|
+
produce an error — it produces plausible-looking wrong results, so compare:
|
|
17
|
+
- filtered vs unfiltered `totalCount` (identical → param ignored)
|
|
18
|
+
- a dense-area query returning 0 rows (→ param name/format wrong)
|
|
19
|
+
3. Do NOT copy param names from a sibling endpoint or sibling API of the same
|
|
20
|
+
vendor without re-verifying. Same vendor ≠ same contract; endpoints drift.
|
|
21
|
+
4. If a param only works together with another param (district requires
|
|
22
|
+
province), encode that dependency in the input schema with a clear error.
|
|
23
|
+
Test it: dependent-param-alone must be rejected, not silently national.
|
|
24
|
+
|
|
25
|
+
## Response fields
|
|
26
|
+
- Map exactly the field names present in your recorded live fixtures.
|
|
27
|
+
- No speculative fallback chains (`row.distance ?? row.dist ?? row.Distance`).
|
|
28
|
+
If two shapes genuinely exist, you need a recorded fixture proving EACH
|
|
29
|
+
branch plus a row-level test per branch; otherwise map one name only.
|
|
30
|
+
- Field presence varies by endpoint within the same vendor. Detail endpoints
|
|
31
|
+
often return more/differently-named fields than list endpoints — record
|
|
32
|
+
fixtures per endpoint, not per vendor.
|
|
33
|
+
|
|
34
|
+
## When results look wrong
|
|
35
|
+
- Same response body across different request payloads → the upstream is
|
|
36
|
+
ignoring your variation; stop tuning fields and re-check param names/auth.
|
|
37
|
+
- Empty result for a query that must have data (city-center radius search,
|
|
38
|
+
major-district listing) → treat as a request bug. Never record it as a
|
|
39
|
+
fixture and never ship it.
|
|
40
|
+
|
|
41
|
+
## Deliverables per endpoint
|
|
42
|
+
- [ ] Spec reference (URL or doc name + section) noted in the PR/commit
|
|
43
|
+
- [ ] One recorded live fixture proving request params take effect
|
|
44
|
+
- [ ] Negative evidence checked: filtered count differs from unfiltered
|
|
45
|
+
- [ ] Param dependencies enforced in the input schema with tests
|