From 71718421e49694d293e4f788301bbc48a5c2e7ea Mon Sep 17 00:00:00 2001 From: Denis Artyushin Date: Sat, 25 Nov 2023 16:02:03 +0300 Subject: [PATCH] Add code highlight for docs (#1738) --- README.md | 38 +++++++++++++++++++++------------- docs/index.md | 40 ++++++++++++++++++++++-------------- docs/supported-data-types.md | 12 +++++------ mkdocs.yml | 9 +++++++- 4 files changed, 63 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index 2a1609a4a..f0fd16b74 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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`: @@ -238,7 +237,10 @@ class Apis(BaseModel): ## 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) @@ -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 @@ -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 diff --git a/docs/index.md b/docs/index.md index 158c73360..b92d0529d 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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) @@ -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) @@ -187,7 +185,7 @@ components:
model.py -```python +```py # generated by datamodel-codegen: # filename: api.yaml # timestamp: 2020-06-02T05:28:24+00:00 @@ -235,7 +233,10 @@ class Apis(BaseModel):
## 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) @@ -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`: @@ -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 diff --git a/docs/supported-data-types.md b/docs/supported-data-types.md index adf9200ea..b67fe3b60 100644 --- a/docs/supported-data-types.md +++ b/docs/supported-data-types.md @@ -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 @@ -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)) diff --git a/mkdocs.yml b/mkdocs.yml index 34547e10a..c765cf3b2 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -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