fhir-openapi-translator 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 fhir-openapi-translator contributors
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/README.md ADDED
@@ -0,0 +1,100 @@
1
+ # fhir-openapi-translator
2
+
3
+ **Turn any FHIR resource into an OpenAPI spec — and generate typed models in any language.**
4
+
5
+ [![CI](https://github.com/krishgok/fhir-openapi-translator/actions/workflows/ci.yml/badge.svg)](https://github.com/krishgok/fhir-openapi-translator/actions/workflows/ci.yml)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
7
+ [![Node](https://img.shields.io/badge/node-%E2%89%A520-brightgreen.svg)](https://nodejs.org)
8
+ [![FHIR R4 · R4B · R5](https://img.shields.io/badge/FHIR-R4%20%C2%B7%20R4B%20%C2%B7%20R5-orange.svg)](https://hl7.org/fhir)
9
+
10
+ ![Generating an OpenAPI spec for Patient and CarePlan on FHIR R4, then exploring it in Swagger UI](docs/demo.gif)
11
+
12
+ HAPI FHIR and Firely give Java/.NET teams great FHIR models. Everyone else — Go, Rust, Kotlin, PHP, C++, TypeScript — has no equivalent. But every language has an OpenAPI code generator. This tool bridges the gap: give it a resource name and a FHIR version, get back a clean, self-contained OpenAPI document ready for `openapi-generator`.
13
+
14
+ ## Install
15
+
16
+ ```sh
17
+ npm install fhir-openapi-translator # library + `fhir-oas` CLI
18
+ ```
19
+
20
+ Node.js ≥ 20. FHIR definitions ship with the package — no network, no server.
21
+
22
+ ## Quick start
23
+
24
+ ```sh
25
+ # One resource, or many
26
+ fhir-oas generate Patient --fhir-version r4 -o patient.yaml
27
+
28
+ # Then generate a client in any language
29
+ npx @openapitools/openapi-generator-cli generate \
30
+ -i patient.yaml -g typescript-fetch -o ./client \
31
+ --additional-properties=modelPropertyNaming=original
32
+ ```
33
+
34
+ That's a complete spec — the `Patient` schema, its full dependency closure, the standard REST interactions, and every official search parameter — that any OpenAPI generator turns into typed models and clients.
35
+
36
+ ## Usage
37
+
38
+ ```sh
39
+ # Target OpenAPI 3.1 as JSON (default is 3.0.3 YAML, for widest codegen support)
40
+ fhir-oas generate Patient -f r5 --openapi-version 3.1 --format json -o patient.json
41
+
42
+ # Add the standard operations ($everything, $validate, ...)
43
+ fhir-oas generate Patient -f r4 --operations
44
+
45
+ # Apply an Implementation Guide profile (e.g. US Core)
46
+ fhir-oas generate Patient -f r4 --ig hl7.fhir.us.core@5.0.1 --profile us-core-patient
47
+
48
+ # Match one server's declared surface (reads its /metadata)
49
+ fhir-oas generate -f r4 --capability https://server.example.org/fhir
50
+
51
+ # Merge into an existing spec, preserving comments and key order
52
+ fhir-oas generate Questionnaire -f r4 --merge-into api.yaml
53
+
54
+ # CI drift guard: fail if a committed spec no longer matches generation
55
+ fhir-oas check Patient Observation -f r4 --file api.yaml
56
+
57
+ # List resources for a version, or profiles in an IG package
58
+ fhir-oas list --fhir-version r4b
59
+ ```
60
+
61
+ ```ts
62
+ import { generateOpenApi } from "fhir-openapi-translator";
63
+ const doc = generateOpenApi({ resources: ["Patient"], fhirVersion: "r4" });
64
+ ```
65
+
66
+ ## What it does
67
+
68
+ - **FHIR R4, R4B, R5** → **OpenAPI 3.0.3 or 3.1.0**, YAML or JSON.
69
+ - **Minimal output** — only the resources you ask for and what they reference.
70
+ - **Typed code enums** from required ValueSet bindings, not bare strings.
71
+ - **Custom operations** from the official OperationDefinitions.
72
+ - **Profiles / IGs** — apply US Core-style constraints from any IG package.
73
+ - **CapabilityStatement-driven** — generate exactly what a server supports.
74
+ - **Merge mode & drift guard** — coexist with hand-written specs, catch drift in CI.
75
+
76
+ ## Where it fits
77
+
78
+ | | fhir-openapi-translator | HAPI / Firely |
79
+ |---|:---:|:---:|
80
+ | Output | OpenAPI (→ any language) | Java / .NET models |
81
+ | Runtime needed | none (offline CLI) | a running server / SDK |
82
+ | US Core / IG profiles | ✅ | ✅ |
83
+ | Per-resource, codegen-tuned specs | ✅ | — |
84
+
85
+ **Complements a FHIR SDK, doesn't replace it.** Keep HAPI or Firely for server-side models and conformance — this produces the OpenAPI contract around them: for consumers in any language, and for the tooling you already run (gateways, mock servers, contract tests).
86
+
87
+ ## Docs
88
+
89
+ - **[Reference](docs/REFERENCE.md)** — full CLI, library API, codegen recipes, limitations
90
+ - **[Examples](examples/)** — worked walkthroughs for each feature
91
+
92
+ ## Legal & attribution
93
+
94
+ - **FHIR®** is a registered trademark of [Health Level Seven International (HL7®)](https://www.hl7.org). This project is **not affiliated with, endorsed by, or sponsored by HL7**; the name is used only to describe what the tool consumes.
95
+ - Bundled definitions derive from the official HL7 FHIR packages (the FHIR specification is published under [CC0 / public domain](https://build.fhir.org/license.html)) and [`@medplum/definitions`](https://www.npmjs.com/package/@medplum/definitions) (Apache-2.0). IG packages you pass to `--ig` are licensed by their own publishers.
96
+ - Generated specs describe the FHIR data model but do **not** guarantee FHIR conformance — validate payloads with a real FHIR validator. See [limitations](docs/REFERENCE.md#assumptions-and-known-limitations).
97
+
98
+ ## License
99
+
100
+ [MIT](LICENSE)