Skip to content

Commit

Permalink
feat(fhir-ts-codegen): rewrite to target io-ts
Browse files Browse the repository at this point in the history
Rewrite the codegen to target io-ts runtime types rather than TypeScript
interfaces. Refactored to use lighter-weight CLI library. Generating
code through string interpolation rather than the TypeScript AST.
  • Loading branch information
tangdrew committed Feb 14, 2019
1 parent a9fa102 commit 8216864
Show file tree
Hide file tree
Showing 16 changed files with 490 additions and 46,216 deletions.
30 changes: 9 additions & 21 deletions packages/fhir-ts-codegen/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# fhir-ts-codegen

FHIR TypeScript definitions generator.
Generate [io-ts](https://github.com/gcanti/io-ts) runtime types from FHIR StructureDefinitions.

## Disclaimer

Expand All @@ -15,33 +15,21 @@ npm install @tangdrew/fhir-ts-codegen -g
## Usage

```sh
fhir-ts-codegen <pattern> <output-directory>
Usage: fhir-ts-codegen [options]

Options:
-i, --input <dir> input pattern to StructureDefinitions
-o, --output <dir> path to output directory
-V, --version output the version number
-h, --help output usage information
```

Example:

```sh
fhir-ts-codegen "structure-defintions/**.profile.json" "types"
fhir-ts-codegen "structure-definitions/**.profile.json" "types"
```

## Roadmap

- Resource Definitions
- [x] Interface declaration from snapshot
- [x] Property names
- [x] Property type names
- [x] Optional properties
- [x] Array properties
- [x] JSDoc comments
- [x] Backbone Element properties
- [ ] Interface declaration from differential
- [ ] Default values
- [x] Content reference
- Primitive types
- [x] Type aliases
- [x] Extensions
- CLI options

## License

[MIT licensed](./LICENSE).
19 changes: 19 additions & 0 deletions packages/fhir-ts-codegen/bin/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env node

const program = require("commander");
const config = require("../package.json");
const { Generator } = require("../dist");

program
.name("fhir-ts-codegen")
.option("-i, --input <dir>", "input pattern to StructureDefinitions")
.option("-o, --output <dir>", "path to output directory")
.version(config.version)
.parse(process.argv);

if (program.input && program.output) {
const generator = new Generator(program.input, program.output);
generator.run();
} else {
program.help()
}
23 changes: 0 additions & 23 deletions packages/fhir-ts-codegen/lib/commands/default.ts

This file was deleted.

60 changes: 60 additions & 0 deletions packages/fhir-ts-codegen/lib/conformance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* FHIR Conformance Types
*/

export enum FHIRPrimitives {
base64binary = "base64binary",
boolean = "boolean",
canonical = "canonical",
code = "code",
date = "date",
dateTime = "dateTime",
decimal = "decimal",
id = "id",
instant = "instant",
integer = "integer",
markdown = "markdown",
oid = "oid",
positiveInt = "positiveInt",
string = "string",
time = "time",
unsignedInt = "unsignedInt",
uri = "uri",
url = "url",
uuid = "uuid"
}

export interface StructureDefinition {
resourceType: string;
url: string;
version?: string;
name: string;
title?: string;
status: string;
experimental?: boolean;
date?: string;
description?: string;
fhirVersion?: string;
kind: string;
abstract: boolean;
contextType?: string;
context?: string[];
contextInvariant?: string[];
type: string;
baseDefinition?: string;
derivation?: string;
snapshot?: { element: ElementDefinition[] };
differential?: { element: ElementDefinition[] };
}

export interface ElementDefinition {
id?: string;
path: string;
min?: number;
max?: string;
type?: Array<{
code: string;
}>;
short?: string;
contentReference?: string;
}
201 changes: 0 additions & 201 deletions packages/fhir-ts-codegen/lib/generateDefinition.ts

This file was deleted.

Loading

0 comments on commit 8216864

Please sign in to comment.