Skip to content

Repository files navigation

Schema-First

Validate and convert OpenAPI specification via Marshmallow schemas to Marshmallow schemas.

Features

  • OpenAPI specification validate.
  • Convert OpenAPI schemas to Marshmallow schemas.

Installation

Recommended using the latest version of Python. Schema-First supports Python 3.12 and newer.

Install and update using pip:

$ pip install -U schema_first

Example

Create specification - openapi.yaml:

openapi: 3.2.0
info:
  title: Example API for testing Schema-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.

Additional documentation

About

Validate and convert OpenAPI specification via Marshmallow schemas to Marshmallow schemas.

Topics

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages