{"id":4666,"library":"openapi-schema-pydantic","title":"OpenAPI Schema Pydantic","description":"openapi-schema-pydantic provides Pydantic classes that represent the OpenAPI (v3) specification schema. It allows developers to construct OpenAPI documents using native Python objects with type hints and validation. The library's latest version is 1.2.4. Note: This library is no longer actively maintained, and `openapi-pydantic` is a community-maintained fork.","status":"maintenance","version":"1.2.4","language":"en","source_language":"en","source_url":"https://github.com/kuimono/openapi-schema-pydantic","tags":["openapi","pydantic","schema","api-generation","data-validation"],"install":[{"cmd":"pip install openapi-schema-pydantic","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core dependency for data validation and schema generation. Primarily supports Pydantic v1.x.","package":"pydantic","optional":false}],"imports":[{"note":"Standard import for OpenAPI v3.1.x components.","symbol":"OpenAPI, Info, PathItem, Operation, Response","correct":"from openapi_schema_pydantic import OpenAPI, Info, PathItem, Operation, Response"},{"note":"To explicitly work with OpenAPI v3.0.3, import from the specific submodule. The default import uses v3.1.x.","wrong":"from openapi_schema_pydantic import OpenAPI","symbol":"OpenAPI (for v3.0.3)","correct":"from openapi_schema_pydantic.v3.v3_0_3 import OpenAPI"}],"quickstart":{"code":"from openapi_schema_pydantic import OpenAPI, Info, PathItem, Operation, Response\n\n# Construct OpenAPI by pydantic objects\nopen_api = OpenAPI(\n    info=Info(\n        title='My own API',\n        version='v0.0.1',\n    ),\n    paths={\n        '/ping': PathItem(\n            get=Operation(\n                responses={\n                    '200': Response(description='pong')\n                }\n            )\n        )\n    },\n)\n\n# For Pydantic v1.x (which this library primarily supports), use .json()\nprint(open_api.json(by_alias=True, exclude_none=True, indent=2))","lang":"python","description":"This example demonstrates how to construct a basic OpenAPI document using the library's Pydantic models. It creates an `OpenAPI` object with an `Info` section and a simple `/ping` endpoint. The output is then serialized to JSON."},"warnings":[{"fix":"Consider migrating to `openapi-pydantic` (install with `pip install openapi-pydantic`) for active maintenance and Pydantic v2.x compatibility.","message":"The `openapi-schema-pydantic` library is no longer actively maintained. A community-maintained fork, `openapi-pydantic`, is recommended for ongoing projects, as it includes support for Pydantic v2.x and continued development.","severity":"breaking","affected_versions":"All versions"},{"fix":"Stick to Pydantic v1.x with this library, or migrate to the `openapi-pydantic` fork which explicitly supports Pydantic v1.x and v2.x.","message":"This library is primarily designed for Pydantic v1.x. Using it with Pydantic v2.x may lead to unexpected behavior or validation errors, especially regarding JSON Schema generation, as Pydantic v2.x aligns with OpenAPI v3.1.x's JSON Schema dialect by default, while Pydantic v1.x aligns with OpenAPI v3.0.x.","severity":"breaking","affected_versions":"All versions when used with Pydantic v2.x"},{"fix":"For OpenAPI v3.0.3: `from openapi_schema_pydantic.v3.v3_0_3 import OpenAPI, ...`. For v3.1.0 (default): `from openapi_schema_pydantic import OpenAPI, ...`.","message":"Since version 1.2.0, the library defaults to generating OpenAPI v3.1.0 specifications. If you need to generate OpenAPI v3.0.3, you must explicitly import models from `openapi_schema_pydantic.v3.v3_0_3`.","severity":"gotcha","affected_versions":">=1.2.0"},{"fix":"Review your data validation logic if you relied on unknown fields raising errors. If strict validation is needed, you might need to manually configure `extra=Extra.forbid` on your models (if the library allows or by inspecting source).","message":"In version 1.2.2, the default Pydantic `extra` configuration was changed from `Extra.forbid` to `Extra.ignore`. This means that unknown fields in input data, which previously would have raised a validation error, are now silently ignored. [GitHub Releases]","severity":"breaking","affected_versions":">=1.2.2"},{"fix":"Use `open_api.json(by_alias=True, exclude_none=True, indent=2)` for JSON serialization.","message":"When serializing OpenAPI models to JSON, for Pydantic v1.x (which this library primarily uses), you should call the `.json()` method. Using `.model_dump_json()` will not work as it's a Pydantic v2.x method.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}