A tool for making Eve schema generation easier.
Python
Latest commit 3459f93 Jun 13, 2016 @ultimateboy ultimateboy committed on GitHub Removing un-used code to get 100% coverage.

README.md

Eve Genie

Documentation Build Status Coverage Status

A tool for making Eve schema generation easier.

Use case: You need to stand up an api quickly. You know what your data looks like in JSON but don't yet know the syntax for Eve/Cerberus.

Docs

Documentation is within the /docs directory or online at evegenie.readthedocs.org

Requirements

sudo pip install -r requirements.txt

Example Usage

Create a json file, sample.json:

{
  "sample-resource": {
    "sample-string": "asdf",
    "sample-integer": 42,
    "sample-float": 1.0,
    "sample-list": ["a", "b", "c"],
    "sample-dict": {
      "sample-embedded-list": ["a", "b", "c"],
      "sample-embedded-dict": {"sample-integer2": 20}
    }
  },
  "sample-resource2": {
    "sample-object-id": "objectid:sample-resource",
    "sample-intrange": "1-100",
    "sample-floatrange": "0.0-1.0",
    "sample-unknown": {
      "allow_unknown": true
    }
  }
}

Then generate your eve schemas using:

python geneve.py sample.json

This will create a sample.settings.py file with the following contents:

sample-resource = {
    'schema': {
        'sample-list': {
            'type': 'list',
            'schema': {
                'type': 'string'
            }
        },
        'sample-integer': {
            'type': 'integer'
        },
        'sample-float': {
            'type': 'float'
        },
        'sample-dict': {
            'type': 'dict',
            'schema': {
                'sample-embedded-list': {
                    'type': 'list',
                    'schema': {
                        'type': 'string'
                    }
                },
                'sample-embedded-dict': {
                    'type': 'dict',
                    'schema': {
                        'sample-integer2': {
                            'type': 'integer'
                        }
                    }
                }
            }
        },
        'sample-string': {
            'type': 'string'
        }
    }
}

sample-resource2 = {
    'schema': {
        'sample-object-id': {
            'type': 'objectid',
            'data_relation': {
                'field': '_id',
                'resource': 'sample-resource',
                'embeddable': True
            }
        },
        'sample-unknown': {
            'allow_unknown': True
        },
        'sample-intrange': {
            'max': 100,
            'type': 'integer',
            'min': 1
        },
        'sample-floatrange': {
            'max': 1.0,
            'type': 'float',
            'min': 0.0
        }
    }
}



eve_settings = {
    'MONGO_HOST': 'localhost',
    'MONGO_DBNAME': 'testing',
    'RESOURCE_METHODS': ['GET', 'POST', 'DELETE'],
    'BANDWIDTH_SAVER': False,
    'DOMAIN': {
        'sample-resource': sample-resource,
        'sample-resource2': sample-resource2,
    },
}