fastmcp/docs/python-sdk/fastmcp-utilities-openapi-json_schema_converter.mdx
Jeremiah Lowin b501f05794
Switch to new OpenAPI parser as default (#2513)
* Switch to new OpenAPI parser as default

Remove the legacy OpenAPI parser and make the experimental parser the
default. The experimental parser (introduced in 2.11) offers better
performance, improved compatibility, and a more maintainable architecture.

- Delete legacy parser (server/openapi.py, utilities/openapi.py)
- Move experimental parser to main locations
- Remove enable_new_openapi_parser feature flag
- Update documentation to remove experimental references

* Add deprecation stubs for experimental OpenAPI imports

* Add deprecated enable_new_openapi_parser setting and deprecation tests

* SDK docs

* REview comments

* Fix docstrings

* Update docstring

* Review comments

* Fix broken links
2025-12-01 20:29:18 -05:00

62 lines
2.2 KiB
Text

---
title: json_schema_converter
sidebarTitle: json_schema_converter
---
# `fastmcp.utilities.openapi.json_schema_converter`
Clean OpenAPI 3.0 to JSON Schema converter for the experimental parser.
This module provides a systematic approach to converting OpenAPI 3.0 schemas
to JSON Schema, inspired by py-openapi-schema-to-json-schema but optimized
for our specific use case.
## Functions
### `convert_openapi_schema_to_json_schema` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi/json_schema_converter.py#L38" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```python
convert_openapi_schema_to_json_schema(schema: dict[str, Any], openapi_version: str | None = None, remove_read_only: bool = False, remove_write_only: bool = False, convert_one_of_to_any_of: bool = True) -> dict[str, Any]
```
Convert an OpenAPI schema to JSON Schema format.
This is a clean, systematic approach that:
1. Removes OpenAPI-specific fields
2. Converts nullable fields to type arrays (for OpenAPI 3.0 only)
3. Converts oneOf to anyOf for overlapping union handling
4. Recursively processes nested schemas
5. Optionally removes readOnly/writeOnly properties
**Args:**
- `schema`: OpenAPI schema dictionary
- `openapi_version`: OpenAPI version for optimization
- `remove_read_only`: Whether to remove readOnly properties
- `remove_write_only`: Whether to remove writeOnly properties
- `convert_one_of_to_any_of`: Whether to convert oneOf to anyOf
**Returns:**
- JSON Schema-compatible dictionary
### `convert_schema_definitions` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi/json_schema_converter.py#L322" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```python
convert_schema_definitions(schema_definitions: dict[str, Any] | None, openapi_version: str | None = None, **kwargs) -> dict[str, Any]
```
Convert a dictionary of OpenAPI schema definitions to JSON Schema.
**Args:**
- `schema_definitions`: Dictionary of schema definitions
- `openapi_version`: OpenAPI version for optimization
- `**kwargs`: Additional arguments passed to convert_openapi_schema_to_json_schema
**Returns:**
- Dictionary of converted schema definitions