Skip to content

Commit

Permalink
Add more examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgadling committed Jul 15, 2024
1 parent cf571ca commit 56aecb6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ The libraries and tools that make Platformics work:

## HOWTO
- [Extend the generated API](docs/HOWTO-extend-generated-api.md)
- [Customize Codegen templates](docs/HOWTO-customize-templates.md)

## Contributing
This project adheres to the Contributor Covenant code of conduct. By participating, you are expected to uphold this code. Please report unacceptable behavior to [email protected].
Expand Down
23 changes: 23 additions & 0 deletions docs/HOWTO-customize-templates.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# How To: Customize codegen templates
Platformics supports replacing one codegen template with another, either globally or for a specific type.


## Use a different template by default
1. Find the template that you want to replace in the [base platformics template directory](https://github.com/chanzuckerberg/platformics/tree/main/platformics/codegen/templates)
2. Create a directory that will contain your overriden templates, such as `template_overrides`
3. Copy that template to your overrides directory with the same path relative to `templates` in the platformics repo. For example, if you want to override `platformics/codegen/templates/database/models/class_name.py.j2`, copy it to `template_overrides/database/models/class_name.py.j2`
4. Modify the template as much as you want
5. When you run codegen, include the overrides folder as a parameter to the codegen tool. For example, update the `codegen` target in the `Makefile` for your project directory to look like:
```
$(docker_compose_run) $(APP_CONTAINER) platformics api generate --schemafile ./schema/schema.yaml --template-override-paths template_overrides --output-prefix .
```

## Use a different template for a specific class
1. Find the template that you want to replace in the [base platformics template directory](https://github.com/chanzuckerberg/platformics/tree/main/platformics/codegen/templates). Note that this **only works for files named `class_name.*`**!
2. Create a directory that will contain your overriden templates, such as `template_overrides`
3. Copy that template to your overrides directory with the same path relative to `templates` in the platformics repo, but the **filename needs to reflect the camel_case class name**. For example, if you want to override `platformics/codegen/templates/database/models/class_name.py.j2`, for a class called `MyData`, copy it to `template_overrides/database/models/my_data.py.j2`
4. Modify the template as much as you want
5. When you run codegen, include the overrides folder as a parameter to the codegen tool. For example, update the `codegen` target in the `Makefile` for your project directory to look like:
```
$(docker_compose_run) $(APP_CONTAINER) platformics api generate --schemafile ./schema/schema.yaml --template-override-paths template_overrides --output-prefix .
```

0 comments on commit 56aecb6

Please sign in to comment.