Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
[Jonathan Liuti](https://github.com/johnraz)
[David Wolever]([email protected])
[Joshua Kehn](https://github.com/joshkehn)
[David Miller]([email protected])
[David Miller]([email protected])
[Patrick Senti](https://github.com/miraculixx)
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,34 @@ To declare more than one endpoint, repeat the above URL definition and change th

Swagger documentation will be served up at the URL(s) you configured.

### Swagger V1 v.s. V2

The following URI are according to Swagger Spec 1.2:

* `/resources/`
* `/schema/`
* `/schema/<resource_name>`

The Swagger Spec V2.0 compliant `swagger.json` is served at the following URLs.
Both URLs return the same content.

* `/specs/`
* `/specs/swagger.json`

Note that the V2 specs are generated by mapping the V1 output to V2. This
ensures that existing Tastypie Apis continue to work unmodified.

### Testing

The `example` folder contains a Django app to test tastypie-swagger. Run tests
as follows:

```python
$ cd /path/to/tastypie_swagger
$ pip install -r requirements.txt
$ cd example
$ manage.py test
```

## Contributors

Expand Down
Empty file added example/demo/__init__.py
Empty file.
28 changes: 28 additions & 0 deletions example/demo/apis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from tastypie.api import Api
from tastypie.resources import ModelResource

from demo.models import FooModel, BarModel


class FooResource(ModelResource):

class Meta:
queryset = FooModel.objects.all()


class BarResource(ModelResource):

class Meta:
queryset = BarModel.objects.all()

api = Api('v1')
api.title = 'demo API'
api.description = 'lorem ipsum'
api.version = '1.9'
api.info = {
'license': {
'name': 'Apache',
'url': 'http://www.apache.org/licenses/LICENSE-2.0',
}}
api.register(FooResource())
api.register(BarResource())
23 changes: 23 additions & 0 deletions example/demo/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
]

operations = [
migrations.CreateModel(
name='FooModel',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('text', models.CharField(default=b'', max_length=100, null=True)),
],
options={
},
bases=(models.Model,),
),
]
30 changes: 30 additions & 0 deletions example/demo/migrations/0002_auto_20161010_1722.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
('demo', '0001_initial'),
]

operations = [
migrations.CreateModel(
name='BarModel',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('text', models.CharField(default=b'', max_length=100, null=True, help_text=b'Text for bar')),
],
options={
},
bases=(models.Model,),
),
migrations.AlterField(
model_name='foomodel',
name='text',
field=models.CharField(default=b'', max_length=100, null=True, help_text=b'Text for foo'),
preserve_default=True,
),
]
Empty file.
12 changes: 12 additions & 0 deletions example/demo/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.db import models
from django.db.models import fields


class FooModel(models.Model):
text = fields.CharField(max_length=100, default='', null=True,
help_text='Text for foo')


class BarModel(models.Model):
text = fields.CharField(max_length=100, default='', null=True,
help_text='Text for bar')
22 changes: 22 additions & 0 deletions example/demo/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from django.test.testcases import TestCase
from swagger_spec_validator.util import get_validator
from tastypie.test import ResourceTestCaseMixin


class TestSpecs(ResourceTestCaseMixin, TestCase):

def setUp(self):
super(TestSpecs, self).setUp()

def tearDown(self):
super(TestSpecs, self).tearDown()

def test_validate_specs(self):
for uri in ['/api/doc/specs/swagger.json',
'/api/doc/specs/']:
resp = self.client.get(uri,
format='json')
self.assertHttpOK(resp)
spec_json = self.deserialize(resp)
validator = get_validator(spec_json)
validator.validate_spec(spec_json)
Empty file added example/example/__init__.py
Empty file.
86 changes: 86 additions & 0 deletions example/example/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
"""
Django settings for example project.

For more information on this file, see
https://docs.djangoproject.com/en/1.7/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.7/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '6cf)=%c1ts&4gf*!%bn%&!3$oywu)ak&r3i0ilmps5mrxu9h@v'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

TEMPLATE_DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'demo',
'tastypie',
'tastypie_swagger',
)

MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'example.urls'

WSGI_APPLICATION = 'example.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}

# Internationalization
# https://docs.djangoproject.com/en/1.7/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.7/howto/static-files/

STATIC_URL = '/static/'
15 changes: 15 additions & 0 deletions example/example/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from django.conf.urls import patterns, include, url
from django.contrib import admin
from demo.apis import api

urlpatterns = patterns('',
url(r'^api/', include(api.urls)),
url(r'^api/doc/', include('tastypie_swagger.urls',
namespace='demo_api_swagger'),
kwargs={
"tastypie_api_module":"demo.apis.api",
"namespace":"demo_api_swagger",
"version": "0.1"}
),
url(r'^admin/', include(admin.site.urls)),
)
14 changes: 14 additions & 0 deletions example/example/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""
WSGI config for example project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/
"""

import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
10 changes: 10 additions & 0 deletions example/manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example.settings")

from django.core.management import execute_from_command_line

execute_from_command_line(sys.argv)
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
wsgiref==0.1.2
Django==1.7.11
argparse==1.2.1
django-tastypie==0.13.3
-e .
Loading