mirror of
https://github.com/koxudaxi/datamodel-code-generator.git
synced 2024-03-18 14:54:37 +03:00
Add custom formatters (#1733)
* Support custom formatters for CodeFormatter * Add custom formatters argument * Add graphql to docs/supported-data-types.md * Add test custom formatter for custom-scalar-types.graphql; * Run poetry run scripts/format.sh * Add simple doc
This commit is contained in:
23
docs/custom-formatters.md
Normal file
23
docs/custom-formatters.md
Normal file
@@ -0,0 +1,23 @@
|
||||
# Custom Code Formatters
|
||||
|
||||
New features of the `datamodel-code-generator` it is custom code formatters.
|
||||
|
||||
## Usage
|
||||
To use the `--custom-formatters` option, you'll need to pass the module with your formatter. For example
|
||||
|
||||
**your_module.py**
|
||||
```python
|
||||
from datamodel_code_generator.format import CustomCodeFormatter
|
||||
|
||||
class CodeFormatter(CustomCodeFormatter):
|
||||
def apply(self, code: str) -> str:
|
||||
# processed code
|
||||
return ...
|
||||
|
||||
```
|
||||
|
||||
and run the following command
|
||||
|
||||
```sh
|
||||
$ datamodel-codegen --input {your_input_file} --output {your_output_file} --custom-formatters "{path_to_your_module}.your_module"
|
||||
```
|
||||
@@ -435,8 +435,11 @@ Template customization:
|
||||
Wrap string literal by using black `experimental-
|
||||
string-processing` option (require black 20.8b0 or
|
||||
later)
|
||||
--additional-imports Custom imports for output (delimited list input)
|
||||
|
||||
--additional-imports Custom imports for output (delimited list input).
|
||||
For example "datetime.date,datetime.datetime"
|
||||
--custom-formatters List of modules with custom formatter (delimited list input).
|
||||
--custom-formatters-kwargs A file with kwargs for custom formatters.
|
||||
|
||||
OpenAPI-only options:
|
||||
--openapi-scopes {schemas,paths,tags,parameters} [{schemas,paths,tags,parameters} ...]
|
||||
Scopes of OpenAPI model generation (default: schemas)
|
||||
|
||||
@@ -6,6 +6,7 @@ This code generator supports the following input formats:
|
||||
- JSON Schema ([JSON Schema Core](http://json-schema.org/draft/2019-09/json-schema-validation.html) /[JSON Schema Validation](http://json-schema.org/draft/2019-09/json-schema-validation.html))
|
||||
- JSON/YAML Data (it will be converted to JSON Schema)
|
||||
- Python dictionary (it will be converted to JSON Schema)
|
||||
- GraphQL schema ([GraphQL Schemas and Types](https://graphql.org/learn/schema/))
|
||||
|
||||
## Implemented data types and features
|
||||
|
||||
|
||||
Reference in New Issue
Block a user