|
13 | 13 | | [`--generate-pyproject-config`](#generate-pyproject-config) | Generate pyproject.toml configuration from CLI arguments. | |
14 | 14 | | [`--http-headers`](#http-headers) | Fetch schema from URL with custom HTTP headers. | |
15 | 15 | | [`--http-ignore-tls`](#http-ignore-tls) | Disable TLS certificate verification for HTTPS requests. | |
| 16 | +| [`--http-local-ref-path`](#http-local-ref-path) | Resolve HTTP references from local schema files. | |
16 | 17 | | [`--http-query-parameters`](#http-query-parameters) | Add query parameters to HTTP requests for remote schemas. | |
17 | 18 | | [`--http-timeout`](#http-timeout) | Set timeout for HTTP requests to remote hosts. | |
18 | 19 | | [`--ignore-pyproject`](#ignore-pyproject) | Ignore pyproject.toml configuration file. | |
@@ -1631,6 +1632,65 @@ environments with self-signed certificates. Not recommended for production. |
1631 | 1632 |
|
1632 | 1633 | --- |
1633 | 1634 |
|
| 1635 | +## `--http-local-ref-path` {#http-local-ref-path} |
| 1636 | + |
| 1637 | +Resolve HTTP references from local schema files. |
| 1638 | + |
| 1639 | +The `--http-local-ref-path` flag maps HTTP(S) `$ref` URLs to files under |
| 1640 | +a local schema store instead of fetching them from the network. The host and |
| 1641 | +URL path are used as the relative path under the schema store. |
| 1642 | + |
| 1643 | +!!! tip "Usage" |
| 1644 | + |
| 1645 | + ```bash |
| 1646 | + datamodel-codegen --input schema.json --url https://api.example.com/schema.json --http-local-ref-path schemas # (1)! |
| 1647 | + ``` |
| 1648 | + |
| 1649 | + 1. :material-arrow-left: `--http-local-ref-path` - the option documented here |
| 1650 | + |
| 1651 | +??? example "Examples" |
| 1652 | + |
| 1653 | + **Input Schema:** |
| 1654 | + |
| 1655 | + ```json |
| 1656 | + { |
| 1657 | + "$schema": "http://json-schema.org/draft-07/schema#", |
| 1658 | + "title": "Pet", |
| 1659 | + "type": "object", |
| 1660 | + "properties": { |
| 1661 | + "id": { |
| 1662 | + "type": "integer" |
| 1663 | + }, |
| 1664 | + "name": { |
| 1665 | + "type": "string" |
| 1666 | + }, |
| 1667 | + "tag": { |
| 1668 | + "type": "string" |
| 1669 | + } |
| 1670 | + } |
| 1671 | + } |
| 1672 | + ``` |
| 1673 | + |
| 1674 | + **Output:** |
| 1675 | + |
| 1676 | + ```python |
| 1677 | + # generated by datamodel-codegen: |
| 1678 | + # filename: https://api.example.com/schema.json |
| 1679 | + # timestamp: 2019-07-26T00:00:00+00:00 |
| 1680 | + |
| 1681 | + from __future__ import annotations |
| 1682 | + |
| 1683 | + from pydantic import BaseModel |
| 1684 | + |
| 1685 | + |
| 1686 | + class Pet(BaseModel): |
| 1687 | + id: int | None = None |
| 1688 | + name: str | None = None |
| 1689 | + tag: str | None = None |
| 1690 | + ``` |
| 1691 | + |
| 1692 | +--- |
| 1693 | + |
1634 | 1694 | ## `--http-query-parameters` {#http-query-parameters} |
1635 | 1695 |
|
1636 | 1696 | Add query parameters to HTTP requests for remote schemas. |
|
0 commit comments