Skip to content

Commit

Permalink
Add code highlight for docs (#1738)
Browse files Browse the repository at this point in the history
  • Loading branch information
denisart authored Nov 25, 2023
1 parent a46fe94 commit 7171842
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 36 deletions.
38 changes: 24 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# datamodel-code-generator

This code generator creates [pydantic v1 and v2](https://docs.pydantic.dev/) model, [dataclasses.dataclass](https://docs.python.org/3/library/dataclasses.html), [typing.TypedDict](https://docs.python.org/3/library/typing.html#typing.TypedDict) and [msgspec.Struct](https://github.com/jcrist/msgspec) from an openapi file and others.
This code generator creates [pydantic v1 and v2](https://docs.pydantic.dev/) model, [dataclasses.dataclass](https://docs.python.org/3/library/dataclasses.html), [typing.TypedDict](https://docs.python.org/3/library/typing.html#typing.TypedDict)
and [msgspec.Struct](https://github.com/jcrist/msgspec) from an openapi file and others.

[![PyPI version](https://badge.fury.io/py/datamodel-code-generator.svg)](https://pypi.python.org/pypi/datamodel-code-generator)
[![Conda-forge](https://img.shields.io/conda/v/conda-forge/datamodel-code-generator)](https://anaconda.org/conda-forge/datamodel-code-generator)
Expand All @@ -12,14 +13,12 @@ This code generator creates [pydantic v1 and v2](https://docs.pydantic.dev/) mod
[![Pydantic v1](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/pydantic/pydantic/main/docs/badge/v1.json)](https://pydantic.dev)
[![Pydantic v2](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/pydantic/pydantic/main/docs/badge/v2.json)](https://pydantic.dev)


## Help
See [documentation](https://koxudaxi.github.io/datamodel-code-generator) for more details.

## Sponsors
[![JetBrains](https://avatars.githubusercontent.com/u/60931315?s=200&v=4)](https://github.com/JetBrainsOfficial)


## Quick Installation

To install `datamodel-code-generator`:
Expand Down Expand Up @@ -238,7 +237,10 @@ class Apis(BaseModel):
</details>
## Projects that use datamodel-code-generator
These OSS projects use datamodel-code-generator to generate many models. See the following linked projects for real world examples and inspiration.
These OSS projects use datamodel-code-generator to generate many models.
See the following linked projects for real world examples and inspiration.
- [airbytehq/airbyte](https://github.com/airbytehq/airbyte)
- *[code-generator/Dockerfile](https://github.com/airbytehq/airbyte/blob/master/tools/code-generator/Dockerfile)*
- [apache/iceberg](https://github.com/apache/iceberg)
Expand Down Expand Up @@ -266,18 +268,19 @@ These OSS projects use datamodel-code-generator to generate many models. See the
- *[generate-types.sh](https://github.com/SeldonIO/MLServer/blob/master/hack/generate-types.sh)*

## Supported input types
- OpenAPI 3 (YAML/JSON, [OpenAPI Data Type](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.2.md#data-types))
- 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/CSV 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/))
- OpenAPI 3 (YAML/JSON, [OpenAPI Data Type](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.2.md#data-types));
- 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/CSV 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/));

## Supported output types
- [pydantic](https://docs.pydantic.dev/1.10/).BaseModel
- [pydantic_v2](https://docs.pydantic.dev/2.0/).BaseModel
- [dataclasses.dataclass](https://docs.python.org/3/library/dataclasses.html)
- [typing.TypedDict](https://docs.python.org/3/library/typing.html#typing.TypedDict)
- [msgspec.Struct](https://github.com/jcrist/msgspec)
- [pydantic](https://docs.pydantic.dev/1.10/).BaseModel;
- [pydantic_v2](https://docs.pydantic.dev/2.0/).BaseModel;
- [dataclasses.dataclass](https://docs.python.org/3/library/dataclasses.html);
- [typing.TypedDict](https://docs.python.org/3/library/typing.html#typing.TypedDict);
- [msgspec.Struct](https://github.com/jcrist/msgspec);
- Custom type from your [jinja2](https://jinja.palletsprojects.com/en/3.1.x/) template;

## Installation

Expand All @@ -292,6 +295,13 @@ If you want to resolve `$ref` for remote files then you should specify `http` ex
$ pip install 'datamodel-code-generator[http]'
```

### `graphql` extra option

If you want to generate data model from a GraphQL schema then you should specify `graphql` extra option.
```bash
$ pip install 'datamodel-code-generator[graphql]'
```

### Docker Image
The docker image is in [Docker Hub](https://hub.docker.com/r/koxudaxi/datamodel-code-generator)
```bash
Expand Down
40 changes: 25 additions & 15 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# datamodel-code-generator

This code generator creates [pydantic v1 and v2](https://docs.pydantic.dev/) model, [dataclasses.dataclass](https://docs.python.org/3/library/dataclasses.html), [typing.TypedDict](https://docs.python.org/3/library/typing.html#typing.TypedDict) and [msgspec.Struct](https://github.com/jcrist/msgspec)from an openapi file and others.

This code generator creates [pydantic v1 and v2](https://docs.pydantic.dev/) model, [dataclasses.dataclass](https://docs.python.org/3/library/dataclasses.html), [typing.TypedDict](https://docs.python.org/3/library/typing.html#typing.TypedDict) and [msgspec.Struct](https://github.com/jcrist/msgspec) from an openapi file and others.

[![PyPI version](https://badge.fury.io/py/datamodel-code-generator.svg)](https://pypi.python.org/pypi/datamodel-code-generator)
[![Conda-forge](https://img.shields.io/conda/v/conda-forge/datamodel-code-generator)](https://anaconda.org/conda-forge/datamodel-code-generator)
Expand All @@ -13,7 +12,6 @@ This code generator creates [pydantic v1 and v2](https://docs.pydantic.dev/) mod
[![Pydantic v1](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/pydantic/pydantic/main/docs/badge/v1.json)](https://pydantic.dev)
[![Pydantic v2](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/pydantic/pydantic/main/docs/badge/v2.json)](https://pydantic.dev)


## Sponsors
[![JetBrains](https://avatars.githubusercontent.com/u/60931315?s=200&v=4)](https://github.com/JetBrainsOfficial)

Expand Down Expand Up @@ -187,7 +185,7 @@ components:
<details>
<summary>model.py</summary>
```python
```py
# generated by datamodel-codegen:
# filename: api.yaml
# timestamp: 2020-06-02T05:28:24+00:00
Expand Down Expand Up @@ -235,7 +233,10 @@ class Apis(BaseModel):
</details>
## Projects that use datamodel-code-generator
These OSS projects use datamodel-code-generator to generate many models. See the following linked projects for real world examples and inspiration.
These OSS projects use datamodel-code-generator to generate many models.
See the following linked projects for real world examples and inspiration.
- [airbytehq/airbyte](https://github.com/airbytehq/airbyte)
- *[code-generator/Dockerfile](https://github.com/airbytehq/airbyte/blob/master/tools/code-generator/Dockerfile)*
- [apache/iceberg](https://github.com/apache/iceberg)
Expand Down Expand Up @@ -263,18 +264,20 @@ These OSS projects use datamodel-code-generator to generate many models. See the
- *[generate-types.sh](https://github.com/SeldonIO/MLServer/blob/master/hack/generate-types.sh)*

## Supported input types
- OpenAPI 3 (YAML/JSON, [OpenAPI Data Type](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#data-types))
- 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/CSV 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/))
- OpenAPI 3 (YAML/JSON, [OpenAPI Data Type](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#data-types));
- 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/CSV 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/));

## Supported output types
- [pydantic](https://docs.pydantic.dev/1.10/).BaseModel
- [pydantic_v2](https://docs.pydantic.dev/2.0/).BaseModel
- [dataclasses.dataclass](https://docs.python.org/3/library/dataclasses.html)
- [typing.TypedDict](https://docs.python.org/3/library/typing.html#typing.TypedDict)
- [msgspec.Struct](https://github.com/jcrist/msgspec)
- [pydantic](https://docs.pydantic.dev/1.10/).BaseModel;
- [pydantic_v2](https://docs.pydantic.dev/2.0/).BaseModel;
- [dataclasses.dataclass](https://docs.python.org/3/library/dataclasses.html);
- [typing.TypedDict](https://docs.python.org/3/library/typing.html#typing.TypedDict);
- [msgspec.Struct](https://github.com/jcrist/msgspec);
- Custom type from your [jinja2](https://jinja.palletsprojects.com/en/3.1.x) template;

## Installation

To install `datamodel-code-generator`:
Expand All @@ -288,6 +291,13 @@ If you want to resolve `$ref` for remote files then you should specify `http` ex
$ pip install 'datamodel-code-generator[http]'
```

### `graphql` extra option

If you want to generate data model from a GraphQL schema then you should specify `graphql` extra option.
```bash
$ pip install 'datamodel-code-generator[graphql]'
```

### Docker Image
The docker image is in [Docker Hub](https://hub.docker.com/r/koxudaxi/datamodel-code-generator)
```bash
Expand Down
12 changes: 6 additions & 6 deletions docs/supported-data-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

This code generator supports the following input formats:

- OpenAPI 3 (YAML/JSON, [OpenAPI Data Type](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#data-types))
- 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/))
- OpenAPI 3 (YAML/JSON, [OpenAPI Data Type](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#data-types));
- 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

Expand Down Expand Up @@ -39,4 +39,4 @@ Below are the data types and features recognized by datamodel-code-generator for
- anyOf (as typing.Union)
- oneOf (as typing.Union)
- $ref ([http extra](../#http-extra-option) is required when resolving $ref for remote files.)
- $id (for [JSONSchema](https://json-schema.org/understanding-json-schema/structuring.html#id)
- $id (for [JSONSchema](https://json-schema.org/understanding-json-schema/structuring.html#id))
9 changes: 8 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@ theme:
accent: 'light blue'
analytics:
gtag: 275257853

markdown_extensions:
- codehilite
- pymdownx.highlight:
anchor_linenums: true
line_spans: __span
pygments_lang_class: true
- pymdownx.inlinehilite
- pymdownx.snippets
- pymdownx.superfences
- admonition

repo_name: koxudaxi/datamodel-code-generator
Expand Down

0 comments on commit 7171842

Please sign in to comment.