All Projects → podhmo → swagger-marshmallow-codegen

podhmo / swagger-marshmallow-codegen

Licence: MIT license
generating marshmallow's schema from swagger definition file

Programming Languages

python
139335 projects - #7 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to swagger-marshmallow-codegen

Apispec
A pluggable API specification generator. Currently supports the OpenAPI Specification (f.k.a. the Swagger specification)..
Stars: ✭ 831 (+1529.41%)
Mutual labels:  marshmallow
Apifairy
A minimalistic API framework built on top of Flask, Marshmallow and friends.
Stars: ✭ 141 (+176.47%)
Mutual labels:  marshmallow
Flasgger
Easy OpenAPI specs and Swagger UI for your Flask API
Stars: ✭ 2,825 (+5439.22%)
Mutual labels:  marshmallow
Python Api Development Fundamentals
Develop a full-stack web application with Python and Flask
Stars: ✭ 44 (-13.73%)
Mutual labels:  marshmallow
Flask Restplus Server Example
Real-life RESTful server example on Flask-RESTplus
Stars: ✭ 1,240 (+2331.37%)
Mutual labels:  marshmallow
Aiohttp Apispec
Build and document REST APIs with aiohttp and apispec
Stars: ✭ 172 (+237.25%)
Mutual labels:  marshmallow
Environs
simplified environment variable parsing
Stars: ✭ 631 (+1137.25%)
Mutual labels:  marshmallow
marshmallow-validators
Use 3rd-party validators (e.g. from WTForms and colander) with marshmallow
Stars: ✭ 24 (-52.94%)
Mutual labels:  marshmallow
Marshmallow Oneofschema
Marshmallow library extension that allows schema (de)multiplexing
Stars: ✭ 94 (+84.31%)
Mutual labels:  marshmallow
Marshmallow Jsonapi
JSON API 1.0 (https://jsonapi.org/) formatting with marshmallow
Stars: ✭ 203 (+298.04%)
Mutual labels:  marshmallow
Hobbit Core
A flask project generator.
Stars: ✭ 49 (-3.92%)
Mutual labels:  marshmallow
Dynamorm
Python object & relation mapping library for Amazon's DynamoDB service
Stars: ✭ 72 (+41.18%)
Mutual labels:  marshmallow
Marshmallow Jsonschema
JSON Schema Draft v7 (http://json-schema.org/) formatting with marshmallow
Stars: ✭ 172 (+237.25%)
Mutual labels:  marshmallow
Runtimepermission
Simpliest way to ask runtime permissions on Android, no need to extend class or override permissionResult method, choose your way : Kotlin / Coroutines / RxJava / Java7 / Java8
Stars: ✭ 860 (+1586.27%)
Mutual labels:  marshmallow
MPContribs
Platform for materials scientists to contribute and disseminate their materials data through Materials Project
Stars: ✭ 30 (-41.18%)
Mutual labels:  marshmallow
Flask Marshmallow
Flask + marshmallow for beautiful APIs
Stars: ✭ 666 (+1205.88%)
Mutual labels:  marshmallow
Flama
🔥 Fire up your API with this flamethrower
Stars: ✭ 161 (+215.69%)
Mutual labels:  marshmallow
djburger
Framework for safe and maintainable web-projects.
Stars: ✭ 75 (+47.06%)
Mutual labels:  marshmallow
Instant-Face-Unlock
Xposed Module's InstantFaceUnlock Code
Stars: ✭ 23 (-54.9%)
Mutual labels:  marshmallow
Django Rest Marshmallow
Marshmallow schemas for Django REST framework
Stars: ✭ 198 (+288.24%)
Mutual labels:  marshmallow

swagger-marshmallow-codegen Python package PyPi version Code style: black

concepts

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

todo: write down detail.

examples

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

definition.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

# -*- 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

#1

todo:

  • x-marshmallow-name
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].