Validate and convert OpenAPI specification via Marshmallow schemas to Marshmallow schemas.
- OpenAPI specification validate.
- Convert OpenAPI schemas to Marshmallow schemas.
Recommended using the latest version of Python. Schema-First supports Python 3.14 and newer.
Install and update using pip
:
$ pip install -U schema_first
Create specification - openapi.yaml
:
openapi: 3.1.1
info:
title: Example API for testing Flask-First
version: 1.0.1
paths:
/endpoint:
get:
operationId: endpoint
responses:
'200':
content:
application/json:
schema:
properties:
message:
type: string
type: object
description: OK
Create script - main.py
:
from pathlib import Path
from pprint import pprint
from schema_first.specification import Specification
spec_file = Path('openapi.yaml')
spec = Specification(spec_file)
spec.load()
pprint(spec.reassembly_spec)
print(
'Marshmallow schema generated from OpenAPI schema',
spec.reassembly_spec['paths']['/endpoint']['get']['responses']['200']['content'][
'application/json'
]['schema'],
)
More example see to ./example
folder.