Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
5ab00d5
Move codegen API to separate Elm package
adamdicarlo0 Jun 23, 2025
03a1662
Replace elm-placeholder-pkg with (to-be) real package
adamdicarlo0 Jun 23, 2025
f9e38db
Flesh out example project, add scripts & docs, clean up
adamdicarlo0 Jun 23, 2025
9d31e67
Clean up and simplify
adamdicarlo0 Jun 23, 2025
d103146
Minor CONTRIBUTING fixes
adamdicarlo0 Jun 23, 2025
ac42431
Add gnused dependency to avoid dev script havoc on macOS
adamdicarlo0 Jun 23, 2025
021d6f1
Add safety/better error message if wrong sed is present
adamdicarlo0 Jun 23, 2025
c452cac
Small doc fix
adamdicarlo0 Jun 23, 2025
af109e0
Add gitignore note
adamdicarlo0 Jun 23, 2025
51e1220
Don't run elm-format on generated elm-codegen code
adamdicarlo0 Jun 23, 2025
cd59d0f
Add findutils to shell.nix
adamdicarlo0 Jun 23, 2025
ead5a0b
Fix a couple things and start adding package docs
adamdicarlo0 Jun 23, 2025
4d02e39
Improve format script
adamdicarlo0 Jun 24, 2025
477c247
Scripts, CI
adamdicarlo0 Jun 24, 2025
1cbfea5
Add package docs, hopefully fix CI
adamdicarlo0 Jun 24, 2025
1a63738
Remove no-longer-needed codegen project, packages, etc.
adamdicarlo0 Jun 24, 2025
a8b469a
Use tools from nix devShell in CI
adamdicarlo0 Jun 24, 2025
efbe082
Dig in deeper / debug
adamdicarlo0 Jun 24, 2025
2eea035
Suppress error for unused placeholder module
adamdicarlo0 Jun 24, 2025
9a716b5
ci: Clean up, add 'build' step (to make sure it works)
adamdicarlo0 Jun 24, 2025
aef5460
Upgrade elm-pages
adamdicarlo0 Jun 24, 2025
e51cab4
Desperation
adamdicarlo0 Jun 24, 2025
0d53db2
Fix cache keys
adamdicarlo0 Jun 24, 2025
45e501f
Desperation
adamdicarlo0 Jun 24, 2025
b5e8111
Fix example-using-api in CI
adamdicarlo0 Jun 24, 2025
ded0297
Fix TestGenScript
adamdicarlo0 Jun 24, 2025
e80b96a
ci: Fix nix store caching
adamdicarlo0 Jun 24, 2025
5b07230
Clean up, add back elm-codegen for package folder script
adamdicarlo0 Jun 25, 2025
4764546
Fix readme typo
adamdicarlo0 Jun 25, 2025
9bb0776
Remove the sync-elm-codegen hack
adamdicarlo0 Jun 25, 2025
fa349f8
elm-open-api-codegen: Auto-remove unused Gen modules in codegen script
adamdicarlo0 Jul 1, 2025
1d4cdb2
Resolve security vulnerabilities in dependencies
adamdicarlo0 Jul 3, 2025
0dad6d0
Simplify example-using-api, improve new READMEs
adamdicarlo0 Jul 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
4 changes: 2 additions & 2 deletions codegen/elm.codegen.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"elm/json": "1.1.3",
"elm-community/json-extra": "4.3.0",
"elm/url": "1.0.0",
"dillonkearns/elm-pages": "10.1.0",
"dillonkearns/elm-pages": "10.2.2",
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and similar upgrades were necessary for the example-using-api project to be able to compile.

"justinmimbs/time-extra": "1.2.0",
"justinmimbs/date": "4.1.0",
"elm/time": "1.0.0",
Expand All @@ -20,4 +20,4 @@
"helpers"
]
}
}
}
51 changes: 39 additions & 12 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,53 @@ The general flow of the app is:

## Getting Started

Make sure you have Nix installed with flakes enabled so you can use the
project's development shell. The easiest way to install Nix is with the
[Determinate Nix Installer][determinate-nix])

- Clone this repo
- Inside your cloned repo, run `direnv allow`
- Inside your cloned repo, run `direnv allow` or, if you don't use direnv, run
`nix develop` to manually enter a development shell
- Start coding!
- Run `npm run dev <path to oas spec>`
- e.g. `npm run dev ./example/github-spec.json` will produce: `generated/GithubV3RestApi/APi.elm`, `generated/GithubV3RestApi/Json.elm`, `generated/GithubV3RestApi/Types.elm`, and `generated/OpenApi/Common.elm`
- Please run `npm run test:gen` when making a pull request to ensure that the generated code is correct. _(would be nice to have this as part of the CI checks in the future)_

[determinate-nix]: https://github.com/DeterminateSystems/nix-installer?tab=readme-ov-file#determinate-nix-installer

## Working on the elm-open-api-codegen package

In order for your local code for `elm-open-api-cli` and the example project
(`example-using-api`) to use your local `elm-open-api-codegen` code, you'll
need to trick the Elm/Lamdera compiler by running a special script:

./scripts/link-local-package

This will modify some `elm.json` files locally. Make sure not to commit these
changes.

When you want to undo the link.run

./scripts/unlink-local-package

## Project structure

The top-level project is a command-line interface to the functionality in the
`elm-open-api-codegen` package.

```
src/
├── JsonSchema/ Anything specific to JSON Schema code gen
│ └── Generate.elm
├── OpenApi/ Anything specific to OpenAPI code gen
│ └── Generate.elm
├── Util/ Utility functions for common Elm code,
│ │ similar to the common `Extra.*` packages
│ └── List.elm
├── Cli.elm The main entry point for the tool
├── CliMonad.elm An abstraction for wrapping code gen & warnings
├── Common.elm Common, shared types & functions
└── SchemaUtils.elm Utility functions for working with these Schemas
└── Cli.elm The main entry point for the tool
elm-open-api-codegen/
└── src/
├── JsonSchema/ Anything specific to JSON Schema code gen
│ └── Generate.elm
├── OpenApi/ Anything specific to OpenAPI code gen
│ └── Generate.elm
├── Util/ Utility functions for common Elm code,
│ │ similar to the common `Extra.*` packages
│ └── List.elm
├── CliMonad.elm An abstraction for wrapping code gen & warnings
├── Common.elm Common, shared types & functions
└── SchemaUtils.elm Utility functions for working with these Schemas
```
1 change: 1 addition & 0 deletions elm-open-api-codegen/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
codegen/Gen
24 changes: 24 additions & 0 deletions elm-open-api-codegen/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# elm-open-api-codegen

Generate Elm code for OpenAPI schemas. This powers
[elm-open-api-cli][elm-open-api-cli], but can be used directly for more powerful
customized code generation.

The main advantage of using this package directly is that you can define your
own custom formats in Elm, which means you can customize the types and generated
code based on the `format` listed in your OpenAPI schema.

See the [example of using this package][example], located in the `-cli`
repository.

When running `elm-codegen`--or in any other way modifying this package's
`codegen/elm.codegen.json` file--be sure to run this script afterward:

./scripts/sync-elm-codegen

This moves the `Gen.*` modules to the `src/` folder, which is necessary because
the code in this project is part of an Elm _package_, and unlike Elm
applications, Elm packages do not support specifying extra source directories.

[elm-open-api-cli]: https://github.com/wolfadex/elm-open-api-cli
[example]: https://github.com/wolfadex/elm-open-api-cli/tree/main/example-using-api
22 changes: 22 additions & 0 deletions elm-open-api-codegen/codegen/elm.codegen.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"elm-codegen-version": "0.6.1",
"codegen-helpers": {
"packages": {
"danfishgold/base64-bytes": "1.1.0",
"dillonkearns/elm-pages": "10.2.2",
"elm/bytes": "1.0.8",
"elm/core": "1.0.5",
"elm/http": "2.0.0",
"elm/json": "1.1.3",
"elm/parser": "1.1.0",
"elm/time": "1.0.0",
"elm/url": "1.0.0",
"justinmimbs/date": "4.1.0",
"justinmimbs/time-extra": "1.2.0",
"wolfadex/elm-rfc3339": "2.0.0"
},
"local": [
"helpers"
]
}
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NB: This file moved to the elm-open-api-codegen/ folder

33 changes: 33 additions & 0 deletions elm-open-api-codegen/codegen/elm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

{
"type": "application",
"source-directories": ["."],
"elm-version": "0.19.1",
"dependencies": {
"direct": {
"elm/browser": "1.0.2",
"elm/core": "1.0.5",
"elm/html": "1.0.0",
"elm/json": "1.1.3",
"mdgriffith/elm-codegen": "5.1.1"
},
"indirect": {
"elm/parser": "1.1.0",
"elm/time": "1.0.0",
"elm/url": "1.0.0",
"elm/virtual-dom": "1.0.2",
"elm-community/basics-extra": "4.1.0",
"elm-community/list-extra": "8.6.0",
"miniBill/elm-unicode": "1.0.2",
"rtfeldman/elm-hex": "1.0.0",
"stil4m/elm-syntax": "7.2.9",
"stil4m/structured-writer": "1.0.3",
"the-sett/elm-pretty-printer": "3.0.0"
}
},
"test-dependencies": {
"direct": {},
"indirect": {}
}
}

33 changes: 33 additions & 0 deletions elm-open-api-codegen/elm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"type": "package",
"name": "wolfadex/elm-open-api-codegen",
"summary": "Code generation used by elm-open-api-cli",
"license": "BSD-3-Clause",
"version": "1.0.0",
"exposed-modules": [
"Common",
"OpenApi.BackendTask",
"OpenApi.Config"
],
"elm-version": "0.19.0 <= v < 0.20.0",
"dependencies": {
"dillonkearns/elm-pages": "10.2.2 <= v < 11.0.0",
"elm/core": "1.0.5 <= v < 2.0.0",
"elm/json": "1.1.3 <= v < 2.0.0",
"elm/regex": "1.0.0 <= v < 2.0.0",
"elm/url": "1.0.0 <= v < 2.0.0",
"elmcraft/core-extra": "2.2.0 <= v < 3.0.0",
"json-tools/json-schema": "1.0.2 <= v < 2.0.0",
"json-tools/json-value": "1.0.1 <= v < 2.0.0",
"mdgriffith/elm-codegen": "5.2.0 <= v < 6.0.0",
"miniBill/elm-fast-dict": "1.2.4 <= v < 2.0.0",
"myrho/yaml": "1.0.0 <= v < 2.0.0",
"turboMaCk/non-empty-list-alias": "1.4.0 <= v < 2.0.0",
"wolfadex/elm-ansi": "3.0.0 <= v < 4.0.0",
"wolfadex/elm-open-api": "2.0.0 <= v < 3.0.0"
},
"test-dependencies": {
"elm-explorations/test": "2.2.0 <= v < 3.0.0",
"miniBill/elm-unicode": "1.1.1 <= v < 2.0.0"
}
}
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions elm-open-api-codegen/scripts/sync-elm-codegen
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -e

# In order for the package to be able to import Gen.* modules, we must put them
# in `src/`, since Elm packages do not support multiple source directories.
rm -rf src/Gen 2>/dev/null
npx --no -- elm-codegen install
mv codegen/Gen src/
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading
Loading