Skip to main content

Marshmallow schema to OpenAPI 3.0.x-3.1 spec. Fork of marshmallow-jsonschema by Stephen J. Fuhry.

Project description

marshmallow-jsonschema-3

Transform marshmallow schemas into correct OpenAPI3.0.x-3.1 definitions. Fork of marshmallow-jsonschema by Stephen J. Fuhry.

Why fork?

  • Add support for marshmallow fields.Constant (missing in marshmallow-jsonschema 0.13.0)
  • Add enum handling for the future? At least not as useless as current approach. Flags use_repr_enums= to convert enums into list of 1=a, 2=b or use_new_enums= to create 3.1 suggested enums.
  • Put schema references into #/components/schemas/<name> instead of #/definitions/<name> source
  • Add old nullable: true attribute using use_nullable= flag.

Installation

pip install marshmallow-jsonschema-3 in >=Python3.8

Usage

from marshmallow import Schema, fields
from marshmallow_jsonschema_3 import JSONSchema

class UserSchema(Schema):
    username = fields.String()
    age = fields.Integer()
    birthday = fields.Date()

user_schema = UserSchema()
json_schema = JSONSchema(use_repr_enums=True, use_nullable=True)
json_schema.dump(user_schema)

Deployment

  1. Make your changes
  2. Create ~/.pypirc file for twine
[distutils]
index-servers =
    pypi
    testpypi

[pypi]
username = pypiusername
password = pypipsw

[testpypi]
username = pypiusername
password = pypipsw
  1. make pypitest to deploy to https://test.pypi.org
  2. Use pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi. org/simple marshmallow-jsonschema-3 to install test package in your projects using real pypi dependencies. The default pip install provided by test.pypi will only look for dependencies in test.pypi, and will fail to find actual versions of dependencies...

Use make pypi for real pypi and use pip install marshmallow-jsonschema-3 to install published package.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

marshmallow-jsonschema-3-1.0.9.tar.gz (10.5 kB view hashes)

Uploaded Source

Built Distribution

marshmallow_jsonschema_3-1.0.9-py3-none-any.whl (10.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page