Skip to content

Commit 650bfd9

Browse files
authored
feat: v3 - Make polyfactory an optional dependency (#4062)
Remove polyfactory from default dependencies
1 parent 37d9f11 commit 650bfd9

File tree

6 files changed

+47
-22
lines changed

6 files changed

+47
-22
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from litestar import Litestar
2+
from litestar.openapi.config import OpenAPIConfig
3+
4+
app = Litestar(
5+
openapi_config=OpenAPIConfig(
6+
title="My API",
7+
version="0.1.0",
8+
create_examples=True,
9+
),
10+
)

docs/getting-started.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ Installation
6262
:doc:`Mako Templating </usage/templating>`
6363
:code:`pip install litestar[mako]`
6464

65+
:ref:`Polyfactory to generate OpenAPI examples <usage/openapi/schema_generation:Generating examples>`
66+
:code:`pip install litestar[structlog]`
67+
6568
Standard Installation (includes Uvicorn and Jinja2 templating):
6669
:code:`pip install litestar[standard]`
6770

docs/release-notes/whats-new-3.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,3 +281,11 @@ The unsupported ``body`` parameter of :class:`~.ASGIStreamingResponse`
281281
and :class:`.ASGIFileResponse` has been removed.
282282

283283
This does not change any behaviour, as this parameter was previously ignored.
284+
285+
286+
``polyfactory`` package removed from default dependencies
287+
----------------------------------------------------------
288+
289+
The `polyfactory <https://polyfactory.litestar.dev/>`_ library is not included by
290+
default anymore, and has been moved to the ``litestar[polyfactory]`` package extra. It
291+
is also included in ``litestar[full]``.

docs/usage/openapi/schema_generation.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,3 +319,17 @@ The above example will result in an OpenAPI schema object that looks like this:
319319
converter. To work around this, Litestar will honor an `alias` field provided to the
320320
`dataclass.field <https://docs.python.org/3/library/dataclasses.html#dataclasses.field>`_ metadata
321321
when generating the field name in the schema.
322+
323+
324+
Generating examples
325+
-------------------
326+
327+
Litestar can automatically generate examples for the ``example`` section of a schema.
328+
To enable this feature, you'll need to have the
329+
`polyfactory <https://polyfactory.litestar.dev/>`_ library installed, which is included
330+
as a package extra under ``litestar[polyfactory`` and ``litestar[full]``.
331+
332+
Once installed, you can turn on example generation via the OpenAPI config:
333+
334+
.. literalinclude:: /examples/openapi/customize_pydantic_model_name.py
335+
:language: python

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ dependencies = [
3737
"importlib-metadata; python_version < \"3.10\"",
3838
"msgspec>=0.19.0",
3939
"multidict>=6.0.2",
40-
"polyfactory>=2.6.3",
4140
"pyyaml",
4241
"typing-extensions",
4342
"click",
@@ -83,8 +82,8 @@ brotli = ["brotli"]
8382
cli = ["jsbeautifier", "uvicorn[standard]", "uvloop>=0.18.0; sys_platform != 'win32'"]
8483
cryptography = ["cryptography"]
8584
full = [
86-
"litestar[annotated-types,attrs,brotli,cli,cryptography,jinja,jwt,mako,minijinja,opentelemetry,piccolo,picologging,prometheus,pydantic,redis,sqlalchemy,standard,structlog,valkey]; python_version < \"3.13\"",
87-
"litestar[annotated-types,attrs,brotli,cli,cryptography,jinja,jwt,mako,minijinja,opentelemetry,piccolo,prometheus,pydantic,redis,sqlalchemy,standard,structlog,valkey]; python_version >= \"3.13\"",
85+
"litestar[annotated-types,attrs,brotli,cli,cryptography,jinja,jwt,mako,minijinja,opentelemetry,piccolo,polyfactory,picologging,prometheus,pydantic,redis,sqlalchemy,standard,structlog,valkey]; python_version < \"3.13\"",
86+
"litestar[annotated-types,attrs,brotli,cli,cryptography,jinja,jwt,mako,minijinja,opentelemetry,piccolo,polyfactory,prometheus,pydantic,redis,sqlalchemy,standard,structlog,valkey]; python_version >= \"3.13\"",
8887
]
8988
jinja = ["jinja2>=3.1.2"]
9089
jwt = ["cryptography", "pyjwt>=2.9.0"]
@@ -110,6 +109,7 @@ standard = [
110109
]
111110
structlog = ["structlog"]
112111
valkey = ["valkey[libvalkey]>=6.0.2"]
112+
polyfactory = ["polyfactory>=2.6.3"]
113113

114114
[project.scripts]
115115
litestar = "litestar.__main__:run_cli"

uv.lock

Lines changed: 9 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)