swagger-marshmallow-codegen


Nameswagger-marshmallow-codegen JSON
Version 0.6.5 PyPI version JSON
download
home_pagehttps://github.com/podhmo/swagger-marshmallow-codegen
Summary"generating marshmallow's schema from swagger definition file"
upload_time2023-06-11 11:31:58
maintainer
docs_urlNone
authorpodhmo
requires_python
license
keywords swagger codegen marshmallow code-generation schema
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            swagger-marshmallow-codegen ![Python package](https://github.com/podhmo/swagger-marshmallow-codegen/workflows/Python%20package/badge.svg) [![PyPi version](https://img.shields.io/pypi/v/swagger-marshmallow-codegen.svg)](https://pypi.python.org/pypi/swagger-marshmallow-codegen) [![](https://img.shields.io/badge/python-3.7+-blue.svg)](https://www.python.org/download/releases/3.7.0/) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://black.readthedocs.io/en/stable/)
========================================

concepts
--------

- Code generation is better than meta programming
- Don't touch me(generated code) if you can

todo: write down detail.

examples
--------

``` bash
$ swagger-marshmallow-codegen definition.yaml > definition.py
```

definition.yaml

``` yaml
# todo: gentle example
definitions:
  default:
    properties:
      string:
        type: string
        default: "default"
      integer:
        type: integer
        default: 10
      boolean:
        type: boolean
        default: true
      date:
        type: string
        format: date
        default: 2000-01-01
      datetime:
        type: string
        format: date-time
        default: 2000-01-01T01:01:01Z
      object:
        type: object
        properties:
          name:
            type: string
            default: foo
          age:
            type: integer
            default: 20
        default:
          name: foo
          age: 20
      array:
        type: array
        items:
          type: integer
        default:
          - 1
          - 2
          - 3

  length-validation:
    type: object
    properties:
      s0:
        type: string
      s1:
        type: string
        maxLength: 10
      s2:
        type: string
        minLength: 5
      s3:
        type: string
        maxLength: 10
        minLength: 5

  maximum-validation:
    type: object
    properties:
      n0:
        type: number
        maximum: 100
      n1:
        type: number
        maximum: 100
        exclusiveMaximum: true
      n2:
        type: number
        maximum: 100
        exclusiveMaximum: false
      m0:
        type: number
        minimum: 100
      m1:
        type: number
        minimum: 100
        exclusiveMinimum: true
      m2:
        type: number
        minimum: 100
        exclusiveMinimum: false

  regex-validation:
    type: object
    properties:
      team:
        type: string
        pattern: team[1-9][0-9]+
      team2:
        type: string
        pattern: team[1-9][0-9]+
        maxLength: 10

  array-validation:
    type: object
    properties:
      nums:
        type: array
        items:
          type: integer
        maxItems: 10
        minItems: 1
        uniqueItems: true

  color:
    type: string
    enum:
      - R
      - G
      - B
  yen:
    type: integer
    enum:
      - 1
      - 5
      - 10
      - 50
      - 100
      - 500
      - 1000
      - 5000
      - 10000
  huge-yen:
    typ
```


definition.py

``` python
# -*- coding:utf-8 -*-
# this is auto-generated by swagger-marshmallow-codegen
from marshmallow import (
    Schema,
    fields
)
import datetime
from collections import OrderedDict
from marshmallow.validate import (
    Length,
    OneOf,
    Regexp
)
from swagger_marshmallow_codegen.validate import (
    ItemsRange,
    MultipleOf,
    Range,
    Unique
)
import re


class Default(Schema):
    string = fields.String(missing=lambda: 'default')
    integer = fields.Integer(missing=lambda: 10)
    boolean = fields.Boolean(missing=lambda: True)
    date = fields.Date(missing=lambda: datetime.date(2000, 1, 1))
    datetime = fields.DateTime(missing=lambda: datetime.datetime(2000, 1, 1, 1, 1, 1))
    object = fields.Nested('DefaultObject', missing=lambda: OrderedDict([('name', 'foo'), ('age', 20)]))
    array = fields.List(fields.Integer(), missing=lambda: [1, 2, 3])


class DefaultObject(Schema):
    name = fields.String(missing=lambda: 'foo')
    age = fields.Integer(missing=lambda: 20)


class Length_validation(Schema):
    s0 = fields.String()
    s1 = fields.String(validate=[Length(min=None, max=10, equal=None)])
    s2 = fields.String(validate=[Length(min=5, max=None, equal=None)])
    s3 = fields.String(validate=[Length(min=5, max=10, equal=None)])


class Maximum_validation(Schema):
    n0 = fields.Number(validate=[Range(min=None, max=100, min_inclusive=True, max_inclusive=True)])
    n1 = fields.Number(validate=[Range(min=None, max=100, min_inclusive=True, max_inclusive=False)])
    n2 = fields.Number(validate=[Range(min=None, max=100, min_inclusive=True, max_inclusive=True)])
    m0 = fields.Number(validate=[Range(min=100, max=None, min_inclusive=True, max_inclusive=True)])
    m1 = fields.Number(validate=[Range(min=100, max=None, min_inclusive=False, max_inclusive=True)])
    m2 = fields.Number(validate=[Range(min=100, max=None, min_inclusive=True, max_inclusive=True)])


class Regex_validation(Schema):
    team = fields.String(validate=[Regexp(regex=re.compile('team[1-9][0-9]+'))])
    team2 = fields.String(validate=[Length(min=None, max=10, equal=None), Regexp(regex=re.compile('team[1-9][0-9]+'))])


class Array_validation(Schema):
    nums = fields.List(fields.Integer(), validate=[ItemsRange(min=1, max=10, min_inclusive=True, max_inclusive=True), Unique()])


class Enum_validation(Schema):
    name = fields.String(required=True)
    money = fields.Integer(validate=[OneOf(choices=[1, 5, 10, 50, 100, 500, 1000, 5000, 10000], labels=[])])
    deposit = fields.Integer(validate=[MultipleOf(n=10000)])
    color = fields.String(required=True, validate=[OneOf(choices=['R', 'G', 'B'], labels=[])])
```

customization:
--------------

todo: write down

<https://github.com/podhmo/swagger-marshmallow-codegen/issues/1>

todo:
-----

-  `x-marshmallow-name`

  [image]: https://travis-ci.org/podhmo/swagger-marshmallow-codegen.svg?branch=master
  [1]: https://travis-ci.org/podhmo/swagger-marshmallow-codegen



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/podhmo/swagger-marshmallow-codegen",
    "name": "swagger-marshmallow-codegen",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "swagger,codegen,marshmallow,code-generation,schema",
    "author": "podhmo",
    "author_email": "ababjam61+github@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/b0/4b/019a556dca8da975339ab7fd6814479b4981351d3ba4529fbbb367fd6b32/swagger-marshmallow-codegen-0.6.5.tar.gz",
    "platform": null,
    "description": "swagger-marshmallow-codegen ![Python package](https://github.com/podhmo/swagger-marshmallow-codegen/workflows/Python%20package/badge.svg) [![PyPi version](https://img.shields.io/pypi/v/swagger-marshmallow-codegen.svg)](https://pypi.python.org/pypi/swagger-marshmallow-codegen) [![](https://img.shields.io/badge/python-3.7+-blue.svg)](https://www.python.org/download/releases/3.7.0/) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://black.readthedocs.io/en/stable/)\n========================================\n\nconcepts\n--------\n\n- Code generation is better than meta programming\n- Don't touch me(generated code) if you can\n\ntodo: write down detail.\n\nexamples\n--------\n\n``` bash\n$ swagger-marshmallow-codegen definition.yaml > definition.py\n```\n\ndefinition.yaml\n\n``` yaml\n# todo: gentle example\ndefinitions:\n  default:\n    properties:\n      string:\n        type: string\n        default: \"default\"\n      integer:\n        type: integer\n        default: 10\n      boolean:\n        type: boolean\n        default: true\n      date:\n        type: string\n        format: date\n        default: 2000-01-01\n      datetime:\n        type: string\n        format: date-time\n        default: 2000-01-01T01:01:01Z\n      object:\n        type: object\n        properties:\n          name:\n            type: string\n            default: foo\n          age:\n            type: integer\n            default: 20\n        default:\n          name: foo\n          age: 20\n      array:\n        type: array\n        items:\n          type: integer\n        default:\n          - 1\n          - 2\n          - 3\n\n  length-validation:\n    type: object\n    properties:\n      s0:\n        type: string\n      s1:\n        type: string\n        maxLength: 10\n      s2:\n        type: string\n        minLength: 5\n      s3:\n        type: string\n        maxLength: 10\n        minLength: 5\n\n  maximum-validation:\n    type: object\n    properties:\n      n0:\n        type: number\n        maximum: 100\n      n1:\n        type: number\n        maximum: 100\n        exclusiveMaximum: true\n      n2:\n        type: number\n        maximum: 100\n        exclusiveMaximum: false\n      m0:\n        type: number\n        minimum: 100\n      m1:\n        type: number\n        minimum: 100\n        exclusiveMinimum: true\n      m2:\n        type: number\n        minimum: 100\n        exclusiveMinimum: false\n\n  regex-validation:\n    type: object\n    properties:\n      team:\n        type: string\n        pattern: team[1-9][0-9]+\n      team2:\n        type: string\n        pattern: team[1-9][0-9]+\n        maxLength: 10\n\n  array-validation:\n    type: object\n    properties:\n      nums:\n        type: array\n        items:\n          type: integer\n        maxItems: 10\n        minItems: 1\n        uniqueItems: true\n\n  color:\n    type: string\n    enum:\n      - R\n      - G\n      - B\n  yen:\n    type: integer\n    enum:\n      - 1\n      - 5\n      - 10\n      - 50\n      - 100\n      - 500\n      - 1000\n      - 5000\n      - 10000\n  huge-yen:\n    typ\n```\n\n\ndefinition.py\n\n``` python\n# -*- coding:utf-8 -*-\n# this is auto-generated by swagger-marshmallow-codegen\nfrom marshmallow import (\n    Schema,\n    fields\n)\nimport datetime\nfrom collections import OrderedDict\nfrom marshmallow.validate import (\n    Length,\n    OneOf,\n    Regexp\n)\nfrom swagger_marshmallow_codegen.validate import (\n    ItemsRange,\n    MultipleOf,\n    Range,\n    Unique\n)\nimport re\n\n\nclass Default(Schema):\n    string = fields.String(missing=lambda: 'default')\n    integer = fields.Integer(missing=lambda: 10)\n    boolean = fields.Boolean(missing=lambda: True)\n    date = fields.Date(missing=lambda: datetime.date(2000, 1, 1))\n    datetime = fields.DateTime(missing=lambda: datetime.datetime(2000, 1, 1, 1, 1, 1))\n    object = fields.Nested('DefaultObject', missing=lambda: OrderedDict([('name', 'foo'), ('age', 20)]))\n    array = fields.List(fields.Integer(), missing=lambda: [1, 2, 3])\n\n\nclass DefaultObject(Schema):\n    name = fields.String(missing=lambda: 'foo')\n    age = fields.Integer(missing=lambda: 20)\n\n\nclass Length_validation(Schema):\n    s0 = fields.String()\n    s1 = fields.String(validate=[Length(min=None, max=10, equal=None)])\n    s2 = fields.String(validate=[Length(min=5, max=None, equal=None)])\n    s3 = fields.String(validate=[Length(min=5, max=10, equal=None)])\n\n\nclass Maximum_validation(Schema):\n    n0 = fields.Number(validate=[Range(min=None, max=100, min_inclusive=True, max_inclusive=True)])\n    n1 = fields.Number(validate=[Range(min=None, max=100, min_inclusive=True, max_inclusive=False)])\n    n2 = fields.Number(validate=[Range(min=None, max=100, min_inclusive=True, max_inclusive=True)])\n    m0 = fields.Number(validate=[Range(min=100, max=None, min_inclusive=True, max_inclusive=True)])\n    m1 = fields.Number(validate=[Range(min=100, max=None, min_inclusive=False, max_inclusive=True)])\n    m2 = fields.Number(validate=[Range(min=100, max=None, min_inclusive=True, max_inclusive=True)])\n\n\nclass Regex_validation(Schema):\n    team = fields.String(validate=[Regexp(regex=re.compile('team[1-9][0-9]+'))])\n    team2 = fields.String(validate=[Length(min=None, max=10, equal=None), Regexp(regex=re.compile('team[1-9][0-9]+'))])\n\n\nclass Array_validation(Schema):\n    nums = fields.List(fields.Integer(), validate=[ItemsRange(min=1, max=10, min_inclusive=True, max_inclusive=True), Unique()])\n\n\nclass Enum_validation(Schema):\n    name = fields.String(required=True)\n    money = fields.Integer(validate=[OneOf(choices=[1, 5, 10, 50, 100, 500, 1000, 5000, 10000], labels=[])])\n    deposit = fields.Integer(validate=[MultipleOf(n=10000)])\n    color = fields.String(required=True, validate=[OneOf(choices=['R', 'G', 'B'], labels=[])])\n```\n\ncustomization:\n--------------\n\ntodo: write down\n\n<https://github.com/podhmo/swagger-marshmallow-codegen/issues/1>\n\ntodo:\n-----\n\n-  `x-marshmallow-name`\n\n  [image]: https://travis-ci.org/podhmo/swagger-marshmallow-codegen.svg?branch=master\n  [1]: https://travis-ci.org/podhmo/swagger-marshmallow-codegen\n\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "\"generating marshmallow's schema from swagger definition file\"",
    "version": "0.6.5",
    "project_urls": {
        "Homepage": "https://github.com/podhmo/swagger-marshmallow-codegen"
    },
    "split_keywords": [
        "swagger",
        "codegen",
        "marshmallow",
        "code-generation",
        "schema"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "07e5e0cd7ddfa3c8885fda6c3bb6cbed8a9c4ccc9374b220dd248dd69cb0f8cf",
                "md5": "896b430c4321a708592ec57d5c326e40",
                "sha256": "6052e2cc343a94192dc7ee1f4ee6e8a3bf5ac527cc5336765d6d78186dbcdd0c"
            },
            "downloads": -1,
            "filename": "swagger_marshmallow_codegen-0.6.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "896b430c4321a708592ec57d5c326e40",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 33669,
            "upload_time": "2023-06-11T11:32:01",
            "upload_time_iso_8601": "2023-06-11T11:32:01.627461Z",
            "url": "https://files.pythonhosted.org/packages/07/e5/e0cd7ddfa3c8885fda6c3bb6cbed8a9c4ccc9374b220dd248dd69cb0f8cf/swagger_marshmallow_codegen-0.6.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b04b019a556dca8da975339ab7fd6814479b4981351d3ba4529fbbb367fd6b32",
                "md5": "0b40180aeeed9fa6cf3793538e07825b",
                "sha256": "0e2a41ee43454ed3759965321343e0c3ded4ed535a3696f6303bdbc59cafc840"
            },
            "downloads": -1,
            "filename": "swagger-marshmallow-codegen-0.6.5.tar.gz",
            "has_sig": false,
            "md5_digest": "0b40180aeeed9fa6cf3793538e07825b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 22588,
            "upload_time": "2023-06-11T11:31:58",
            "upload_time_iso_8601": "2023-06-11T11:31:58.123684Z",
            "url": "https://files.pythonhosted.org/packages/b0/4b/019a556dca8da975339ab7fd6814479b4981351d3ba4529fbbb367fd6b32/swagger-marshmallow-codegen-0.6.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-11 11:31:58",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "podhmo",
    "github_project": "swagger-marshmallow-codegen",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": true,
    "lcname": "swagger-marshmallow-codegen"
}
        
Elapsed time: 0.08743s