concentricsky / django-tastypie-swagger Goto Github PK
View Code? Open in Web Editor NEWAn adapter to use swagger-ui with django-tastypie.
License: Other
An adapter to use swagger-ui with django-tastypie.
License: Other
PyPi version currently broken but your github repo is all sweet
(mapping.py def of get_resource_base_uri - I think that's the only thing?)
I'm using the 1.3 version, and I can't display endpoint with / in their names :
Here is my extra_actions :
extra_actions = [
{
'name': 'engine/reload',
'http_method': 'GET',
'fields': {}
},
{
'name': 'scheduler/reload',
'http_method': 'GET',
'fields': {}
},
{
'name': 'intents',
'http_method': 'GET',
'fields': {}
},
]
The intents endpoint will display with no problems, but the two first will crash with a javascript error :
Uncaught Error: Syntax error, unrecognized expression: /google_post_4_content jquery-1.8.0.min.js:2
Z.error jquery-1.8.0.min.js:2
bg jquery-1.8.0.min.js:2
Z.compile jquery-1.8.0.min.js:2
bm jquery-1.8.0.min.js:2
h.querySelectorAll.bm jquery-1.8.0.min.js:2
Z jquery-1.8.0.min.js:2
p.fn.extend.find jquery-1.8.0.min.js:2
p.fn.p.init jquery-1.8.0.min.js:2
p jquery-1.8.0.min.js:2
OperationView.toggleOperationContent swagger-ui.js:1692
p.event.dispatch jquery-1.8.0.min.js:2
g.handle.h
eg: For a CharField we shouldn't see the __day
filter...
It seems to be allowed/tolerated by both django and tastypie ... So I don't know if we should address this or not.
Would like to hear from you guyz ;-)
Hi,
can you please tell me the preferred way to contribute a change to tastypie_swagger's swagger-ui.js
?
On the background of this issue and the actual change I want to contribute:
I put the tastypie_swagger static files into a directory accessible via the URL configured in django's settings.STATIC_URL
. That worked fine, as the files are referenced in the templates/tastypie_swagger/index.html
via the STATIC_URL
.
It did, however, not work for the file throbber.gif
, which is still expected to be found under /doc/images/
(with /doc/
being the configured url for tastypie_swagger).
I managed to make it work by applying a change to swagger-ui.js
, in which I add an additional field swagger_static_url
to the SwaggerUI.prototype
. This field can then be set to the STATIC_URL
when the object is initialized from templates/tastypie_swagger/index.html
.
My question now is, how would I submit this as a patch? The swagger-ui.js seems to be generated by Coffeescript, and the patch would need to go into the regular and the minified version. Also, I don't know if tastypie_swagger includes a generic swagger-ui.js or if there were some adaptations made to it.
Thanks,
flo
This was introduced in pull #45 and brought to my attention by this StackOverflow question.
If I put a filter on a resource which only allows 'id' and/or 'pk', tastypie has a shortcut that lets you specify the query parameter 'resourcename=id' instead of 'resourcename__id=id' (since it is just a propagation of django's shortcut).
We should allow the swagger documentation to display that instead, possibly as a setting
hi,
From my swagger is trying to get this http://localhost:8000/api/v1/doc/schema/profile?api_key=special-key but unfortunately its giving me 500 error.
Here is the complete stack trace.
Environment:
Request Method: GET
Request URL: http://localhost:8000/api/v1/doc/schema/profile/
Django Version: 1.7b1
Python Version: 2.7.4
Installed Applications:
('django.contrib.admin',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'mongoengine.django.mongo_auth',
'tastypie',
'tastypie_mongoengine',
'tastypie_swagger')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')
Traceback:
File "/home/synerzip/educator-env/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
response = wrapped_callback(request, _callback_args, *_callback_kwargs)
return self.dispatch(request, _args, *_kwargs)
return handler(request, _args, *_kwargs)
context = self.get_context_data(**kwargs)
mapping = ResourceSwaggerMapping(resource)
self.resource_pk_type = self.get_pk_type()
django_internal_type = self.resource._meta.object_class._meta.pk.get_internal_type()
Exception Type: AttributeError at /api/v1/doc/schema/profile/
Exception Value: 'MetaDict' object has no attribute 'pk'
I'm just wondering if anyone is still following the project or should we start a fork ?
@minism ?? Are you still active dude ?
Swagger encodes the values of '&' and all other special characters passed in special-key area due to which tastypie understands only api_key parameter.
I have added custom api using extra_action such as
class Meta:
extra_actions = [
{
'name': 'login',
'http_method': 'POST',
'resource_type':'list',
'fields':{
'username': {
'type': 'string',
'required': True,
'description':'Unique username required.'
},
'password': {
'type': 'string',
'required': True,
'description':'password required'
}
}
}
]
This display the api in doc as mentioned in attached picture.
But when i fill all mentioned fields and press "Try it Out" than it gives me error such as
{
"error_message": "The format indicated 'text/plain' had no available deserialization method. Please check your formats
and content_types
on your Serializer.",
"traceback": "Traceback (most recent call last):\n\n File "/home/synerzip/educator-env/local/lib/python2.7/site-packages/tastypie/resources.py", line 195, in wrapper\n response = callback(request, _args, *_kwargs)\n\n File "/home/synerzip/Dropbox/Educator/educator-backend/educator/users/api.py", line 121, in login\n data = self.deserialize(request, request.body, format=request.META.get('CONTENT_TYPE', 'application/json'))\n\n File "/home/synerzip/educator-env/local/lib/python2.7/site-packages/tastypie/resources.py", line 375, in deserialize\n deserialized = self._meta.serializer.deserialize(data, format=request.META.get('CONTENT_TYPE', 'application/json'))\n\n File "/home/synerzip/educator-env/local/lib/python2.7/site-packages/tastypie/serializers.py", line 219, in deserialize\n raise UnsupportedFormat("The format indicated '%s' had no available deserialization method. Please check your formats
and content_types
on your Serializer." % format)\n\nUnsupportedFormat: The format indicated 'text/plain' had no available deserialization method. Please check your formats
and content_types
on your Serializer.\n"
}
Please refer the attached image.
Thanks,
AbdulWahid
After attempting to install django-tastypie-swagger I get this error when trying to check out the url
I get this exception "Could not parse the remainder: '('tastypie_swagger:resources')' from 'url('tastypie_swagger:resources')'"
Environment:
Request Method: GET
Request URL: http://winter.local/apidoc/
Django Version: 1.4
Python Version: 2.6.5
Installed Applications:
('django.contrib.auth',
'django.contrib.admin',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.admindocs',
'django.contrib.sites',
'django.contrib.staticfiles',
'django.contrib.humanize',
'django.contrib.messages',
'iondb.rundb',
'tastypie',
'django_extensions',
'djcelery',
'tastypie_swagger',
'south')
Installed Middleware:
('iondb.rundb.middleware.ChangeRequestMethodMiddleware',
'django.middleware.common.CommonMiddleware',
'iondb.rundb.middleware.DeleteSessionOnLogoutMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.RemoteUserMiddleware',
'iondb.rundb.middleware.LocalhostAuthMiddleware',
'iondb.bin.startup_housekeeping.StartupHousekeeping')
Traceback:
File "/usr/lib/pymodules/python2.6/django/core/handlers/base.py" in get_response
136. response = response.render()
File "/usr/lib/pymodules/python2.6/django/template/response.py" in render
104. self._set_content(self.rendered_content)
File "/usr/lib/pymodules/python2.6/django/template/response.py" in rendered_content
79. template = self.resolve_template(self.template_name)
File "/usr/lib/pymodules/python2.6/django/template/response.py" in resolve_template
55. return loader.select_template(template)
File "/usr/lib/pymodules/python2.6/django/template/loader.py" in select_template
187. return get_template(template_name)
File "/usr/lib/pymodules/python2.6/django/template/loader.py" in get_template
145. template, origin = find_template(template_name)
File "/usr/lib/pymodules/python2.6/django/template/loader.py" in find_template
134. source, display_name = loader(name, dirs)
File "/usr/lib/pymodules/python2.6/django/template/loader.py" in __call__
42. return self.load_template(template_name, template_dirs)
File "/usr/lib/pymodules/python2.6/django/template/loaders/cached.py" in load_template
46. template, origin = self.find_template(template_name, template_dirs)
File "/usr/lib/pymodules/python2.6/django/template/loaders/cached.py" in find_template
33. template, display_name = loader(name, dirs)
File "/usr/lib/pymodules/python2.6/django/template/loader.py" in __call__
42. return self.load_template(template_name, template_dirs)
File "/usr/lib/pymodules/python2.6/django/template/loader.py" in load_template
48. template = get_template_from_string(source, origin, template_name)
File "/usr/lib/pymodules/python2.6/django/template/loader.py" in get_template_from_string
156. return Template(source, origin, name)
File "/usr/lib/pymodules/python2.6/django/template/base.py" in __init__
125. self.nodelist = compile_string(template_string, origin)
File "/usr/lib/pymodules/python2.6/django/template/base.py" in compile_string
153. return parser.parse()
File "/usr/lib/pymodules/python2.6/django/template/base.py" in parse
246. filter_expression = self.compile_filter(token.contents)
File "/usr/lib/pymodules/python2.6/django/template/base.py" in compile_filter
346. return FilterExpression(token, self)
File "/usr/lib/pymodules/python2.6/django/template/base.py" in __init__
563. "from '%s'" % (token[upto:], token))
Exception Type: TemplateSyntaxError at /apidoc/
Exception Value: Could not parse the remainder: '('tastypie_swagger:resources')' from 'url('tastypie_swagger:resources')'
any ideas on the best way to solve this todo
mappings.py
def build_models(self):
#TODO this should be extended to allow the creation of a custom objects for extra_actions.
@krimkus @concentricsky @johnraz
Let's setup a contributing document for people. I just merged #51 directly into master but don't feel good about that as a common practice. Need some milestones, possible test coverage (#19) and some rules of the road, aka what we want this library to provide and what the goals of the project are.
Hello,
How can I autodetect the fields for post and get on a particular resource?
Thanks a lot,
Joรฃo graรงa
I have trouble while displaying api docs and i followed every single steps mentioned on http://django-tastypie-swagger.readthedocs.org/en/latest/. But failed to load resource api doc. Need your help to fix this.
Here are my details
===========Packages===============
Django - 1.7b1
Python - 2.7.4
django-tastypie-mongoengine - 0.4.5 - active
django-tastypie-swagger - 0.1.3 - active
django-tastypie - 0.11.0
mongoengine - 0.8.7
================api.py=========================
from mongoengine import *
from mongoengine.django.auth import User
class Profile(Document):
GENDER = (('male','Male'),('female','Female'))
MARITAL_STATUS = (('single','Single'),('married','Married'))
user = ReferenceField(User)
dob = DateTimeField()
dob_image = ImageField(collection_name='images', thumbnail_size=(100,114))
gender = StringField(max_length=10, choices=GENDER)
marital_status = StringField(max_length=10, choices=MARITAL_STATUS)
contact_number = StringField(max_length=12)
alternate_number = StringField(max_length=12)
==============urls.py===========================
from django.conf.urls import patterns, include, url
from django.contrib import admin
from tastypie.api import Api
from users.api import UserResource, ProfileResource
v1_api = Api(api_name='v1')
v1_api.register(UserResource())
v1_api.register(ProfileResource())
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'educator.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^api/', include(v1_api.urls)),
url(r'api/v1/doc/', include('tastypie_swagger.urls', namespace='tastypie_swagger'),kwargs={'tastypie_api_module':v1_api, 'namespace':'tastypie_swagger'}),
)
====================setttings.py=================
TASTYPIE_API_MODULE = 'educator.urls.v1_api'
Below is what i am getting while hitting the url "http://localhost:8000/api/v1/doc/".
500 : INTERNAL SERVER ERROR /api/v1/doc/resources/?api_key=special-key
I included this package in my project and everything works fine if ones does a session authentication. But if I want to use this app with tastypie's api key authetication I fail, because I can enter only "special-key" (see screenshot)
It would be great if there would be the possibility of having the support for tastypie's authentication style (username=<>&api_key=<>)
Hello,
While the PUT is well displayed, it seems the PATCH command is not listed on the Tastypie-swagger interface.
Here is an example of this command : http://django-tastypie.readthedocs.org/en/latest/interacting.html#partially-updating-an-existing-resource-patch
Hello,
@johnraz as you tried in #72 to fix the problem, I got a different error now :
2014-06-08 19:34:59+0200 [HTTPChannel,4,127.0.0.1] Internal Server Error: /api/docs/schema/lisa/
2014-06-08 19:34:59+0200 [HTTPChannel,4,127.0.0.1] Traceback (most recent call last):
2014-06-08 19:34:59+0200 [HTTPChannel,4,127.0.0.1] File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 112, in get_response
2014-06-08 19:34:59+0200 [HTTPChannel,4,127.0.0.1] response = wrapped_callback(request, *callback_args, **callback_kwargs)
2014-06-08 19:34:59+0200 [HTTPChannel,4,127.0.0.1] File "/usr/local/lib/python2.7/dist-packages/django/views/generic/base.py", line 69, in view
2014-06-08 19:34:59+0200 [HTTPChannel,4,127.0.0.1] return self.dispatch(request, *args, **kwargs)
2014-06-08 19:34:59+0200 [HTTPChannel,4,127.0.0.1] File "/usr/local/lib/python2.7/dist-packages/django/views/generic/base.py", line 87, in dispatch
2014-06-08 19:34:59+0200 [HTTPChannel,4,127.0.0.1] return handler(request, *args, **kwargs)
2014-06-08 19:34:59+0200 [HTTPChannel,4,127.0.0.1] File "/usr/local/lib/python2.7/dist-packages/django/views/generic/base.py", line 154, in get
2014-06-08 19:34:59+0200 [HTTPChannel,4,127.0.0.1] context = self.get_context_data(**kwargs)
2014-06-08 19:34:59+0200 [HTTPChannel,4,127.0.0.1] File "/usr/local/lib/python2.7/dist-packages/tastypie_swagger/views.py", line 133, in get_context_data
2014-06-08 19:34:59+0200 [HTTPChannel,4,127.0.0.1] mapping = ResourceSwaggerMapping(resource)
2014-06-08 19:34:59+0200 [HTTPChannel,4,127.0.0.1] File "/usr/local/lib/python2.7/dist-packages/tastypie_swagger/mapping.py", line 43, in __init__
2014-06-08 19:34:59+0200 [HTTPChannel,4,127.0.0.1] self.resource_pk_type = self.get_pk_type()
2014-06-08 19:34:59+0200 [HTTPChannel,4,127.0.0.1] File "/usr/local/lib/python2.7/dist-packages/tastypie_swagger/mapping.py", line 57, in get_pk_type
2014-06-08 19:34:59+0200 [HTTPChannel,4,127.0.0.1] return self._get_native_field_type(self.resource.id)
2014-06-08 19:34:59+0200 [HTTPChannel,4,127.0.0.1] File "/usr/local/lib/python2.7/dist-packages/tastypie/resources.py", line 186, in __getattr__
2014-06-08 19:34:59+0200 [HTTPChannel,4,127.0.0.1] raise AttributeError(name)
2014-06-08 19:34:59+0200 [HTTPChannel,4,127.0.0.1] AttributeError: id
Trying a dir(self.resource) :
['Meta', '__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattr__', '__getattribute__', '__hash__', '__init__', '__metaclass__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_build_reverse_url', '_get_object_type', '_get_resource_from_class', '_get_type_from_class', '_handle_500', '_meta', '_reset_collection', '_wrap_polymorphic', '_wrap_request', 'alter_deserialized_detail_data', 'alter_deserialized_list_data', 'alter_detail_data_to_serialize', 'alter_list_data_to_serialize', 'api_field_from_django_field', 'api_field_from_mongo_field', 'api_field_options', 'api_name', 'apply_authorization_limits', 'apply_filters', 'apply_sorting', 'authorized_create_detail', 'authorized_create_list', 'authorized_delete_detail', 'authorized_delete_list', 'authorized_read_detail', 'authorized_read_list', 'authorized_update_detail', 'authorized_update_list', u'base_fields', 'base_urls', 'build_bundle', 'build_filters', 'build_schema', 'cached_obj_get', 'cached_obj_get_list', 'can_create', 'can_delete', 'can_update', 'check_filtering', 'create_identifier', 'create_response', u'declared_fields', 'dehydrate', 'dehydrate_resource_type', 'dehydrate_resource_uri', 'delete_detail', 'delete_list', 'deserialize', 'detail_uri_kwargs', 'determine_format', 'dispatch', 'dispatch_detail', 'dispatch_list', 'dispatch_subresource', 'error_response', 'fields', 'filter_value_to_python', 'full_dehydrate', 'full_hydrate', 'generate_cache_key', 'get_bundle_detail_data', 'get_detail', 'get_fields', 'get_list', 'get_multiple', 'get_object_list', 'get_resource_uri', 'get_schema', 'get_via_uri', 'hydrate', 'hydrate_m2m', 'is_authenticated', 'is_valid', 'log_throttled_access', 'lookup_kwargs_with_identifiers', 'method_check', 'obj_create', 'obj_delete', 'obj_delete_list', 'obj_delete_list_for_update', 'obj_get', 'obj_get_list', 'obj_update', 'override_urls', 'patch_detail', 'patch_list', 'post_detail', 'post_list', 'prepend_urls', 'put_detail', 'put_list', 'remove_api_resource_names', 'resource_uri_kwargs', 'rollback', 'save', 'save_m2m', 'save_related', 'serialize', 'should_skip_field', 'throttle_check', 'unauthorized_result', 'update_in_place', 'urls', 'wrap_view']
Have you an idea ? I got this on each of my endpoints exposed
Thanks
I'm getting a Caught NoReverseMatch while rendering: u"'tastypie_swagger" is not a registered namespace
For some reason it thinks the namespace is nor registered. Any ideas of workaround. Error is happening in tastypie_swagger/index.html, error at line 48
We should build a decent sphinx doc and host it @ readthedocs.org.
We should cover:
*Requirements & dependencies
*Install
*Usage / Available options + examples
Example Resource:
class SomeResource(ModelResource):
parent = fields.ToOneField('app.api.SomeResource',
'parent', null=True)
class Meta:
filtering = {
# Technically possible, but API docs
# generation currently crashes here
"parent": ALL_WITH_RELATIONS
}
I'm used to work with VM's on my mac and I'm sure i'm not alone.
I would like to make a provision script out of my initial dev setup so other people can easily jump in to contribute and have a basic setup ready to hack.
@concentricsky/django-tastypie-swagger-collab : what about this ?
I believe the problem is happening here:
https://github.com/concentricsky/django-tastypie-swagger/blob/master/tastypie_swagger/views.py#L26
My tastypie API object is defined in my_application/urls.py so I'm using 'my_application.urls.api' as the TASTYPIE_SWAGGER_API_MODULE in my settings module, but 'my_application.urls' is not defined in sys.modules. Should probably take this into account in the code.
I tried loading my_app.urls in my main urls.py and settings.py but had no luck.
We should have an input in the delete section of resources.
Hi guyz,
I create this issue to notify you that I'm currently integrating models description as well as list filter specific to tastypie (limit, offset).
You can follow progress on this branch https://github.com/johnraz/django-tastypie-swagger/commits/evolution
It's still a WIP.
Next step is to integrate error code support and it should come by tomorrow.
Hello,
I found this issue when trying tastypie swagger on some Resources created from inherited models.
This may be more general and related to the handling of OneToOne fields...
Here is the code:
from django.db import models
from tastypie.resources import ModelResource
class SampleModel(models.Model):
pass
class InheritedSampleModel(SampleModel):
pass
class SampleResource(ModelResource):
class Meta():
queryset = SampleModel.objects.all()
resource_name = "sample"
pass
class InheritedSampleResource(ModelResource):
class Meta():
queryset = InheritedSampleModel.objects.all()
resource_name = "inheritedsample"
pass
and the traceback:
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/api/v1/doc/schema/inheritedsample/?api_key=special-key
Django Version: 1.5.8
Python Version: 2.7.3
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'tastypie_swagger')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')
Traceback:
File "/home/pleveau/virtualenvs/vega-app/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
113. response = callback(request, *callback_args, **callback_kwargs)
File "/home/pleveau/virtualenvs/vega-app/local/lib/python2.7/site-packages/django/views/generic/base.py" in view
68. return self.dispatch(request, *args, **kwargs)
File "/home/pleveau/virtualenvs/vega-app/local/lib/python2.7/site-packages/django/views/generic/base.py" in dispatch
86. return handler(request, *args, **kwargs)
File "/home/pleveau/virtualenvs/vega-app/local/lib/python2.7/site-packages/django/views/generic/base.py" in get
153. context = self.get_context_data(**kwargs)
File "/home/pleveau/virtualenvs/vega-app/local/lib/python2.7/site-packages/tastypie_swagger/views.py" in get_context_data
125. mapping = ResourceSwaggerMapping(resource)
File "/home/pleveau/virtualenvs/vega-app/local/lib/python2.7/site-packages/tastypie_swagger/mapping.py" in __init__
71. self.resource_pk_type = self.get_pk_type()
File "/home/pleveau/virtualenvs/vega-app/local/lib/python2.7/site-packages/tastypie_swagger/mapping.py" in get_pk_type
77. return DJANGO_FIELD_TYPE.get(self.resource._meta.object_class._meta.pk.related_field, 'unknown')
Exception Type: AttributeError at /api/v1/doc/schema/inheritedsample/
Exception Value: 'OneToOneField' object has no attribute 'related_field'
Using tastypie v 0.11.1 and tastypie-swagger master (sha 3d3b2b4) . Resource that are related to parent models (SampleModel in the example) are working fine.
Thanks for all the good work!
Hello everyone,
concentricsky did a good work about this tastypie/swagger, but as said in the issue #32 there's no one assigned to the support of this lib.
There's no merge since a lot of months, and according to network graphs, it seems everyone has his own fork more advanced than the current master.
Should the "community" start a fork and merge all pull request which are waiting ? There's a lot of fixes / news features that everyone need. Should be sweet to continue this project !
What do you think ? Who want to maintain it ?
Thanks !
In views.py we have:
class ResourcesView(TastypieApiMixin, SwaggerApiDataMixin, JSONView):
"""
Provide a top-level resource listing for swagger
This JSON must conform to https://github.com/wordnik/swagger-core/wiki/Resource-Listing
"""
def get_context_data(self, *args, **kwargs):
context = super(ResourcesView, self).get_context_data(*args, **kwargs)
# Construct schema endpoints from resources
apis = [{'path': '/%s' % name} for name in sorted(self.tastypie_api._registry.keys())]
context.update({
'basePath': self.request.build_absolute_uri(reverse('%s:schema' % self.kwargs.get('namespace'))),
'apis': apis,
})
return context
it's creating links like /schema/resource
but in urls.py we have
url(r'^schema/(?P<resource>\S+)/$', SchemaView.as_view()),
note that it has a trailing slash
fix is to change the a line to:
apis = [{'path': '/%s/' % name} for name in sorted(self.tastypie_api._registry.keys())]
People aren't seeing the issue because there is usually middleware which adds a slash for when it 404s making it work.
fix probably in mapping.py:70
Hello,
I upgraded tastypie-swagger from 0.1.2 to 0.1.3, and now I have an error about namespace.
import tastypie_swagger
v1_api = Api(api_name='v1')
v1_api.register(UserResource())
v1_api.register(PluginResource())
v1_api.register(IntentResource())
v1_api.register(LisaResource())
urlpatterns += patterns('',
url(r'^api/', include(v1_api.urls)),
url(r'^api/docs/', include('tastypie_swagger.urls', namespace='tastypie_swagger')),
)
It worked with the 0.1.2, but now I have this error :
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
114. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/views/generic/base.py" in view
69. return self.dispatch(request, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/views/generic/base.py" in dispatch
87. return handler(request, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/views/generic/base.py" in get
154. context = self.get_context_data(**kwargs)
File "/usr/local/lib/python2.7/dist-packages/django_tastypie_swagger-0.1.3-py2.7.egg/tastypie_swagger/views.py" in get_context_data
87. context['discovery_url'] = reverse('%s:resources' % self.kwargs.get('namespace'))
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in reverse
528. key)
Exception Type: NoReverseMatch at /api/docs/
Exception Value: u'None' is not a registered namespace
I think it's a common issue with django but didn't found anything to solve my problem.
Any idea about this ? It worked when I was in 0.1.2.
Thanks !
build_detail_operation and build_parameters_from_extra_action assume a model's primary key is int.
It is misleading to have the Data Type listed for a path parameter as int when it is really string.
Swagger inserts an img with src="images/throbber.gif", which ends up getting resolved to api/doc/images/throbber.gif or something similar depending on the url set up to your API docs.
The image URL needs to point to static/tastypie_swagger/images/throbber.gif.
I'm more than willing to help commit a patch. What do you think is the best way to fix this since it is coming through from swagger-ui.js? Should we maintain an edited version that points the src to {{ STATIC_URL }}tastypie_swagger/images/throbber.gif? Not sure what the best option here is.
Also awesome work so far by the way. Looking forward to helping to contribute in the future. We use TastyPie for API communication with all of our mobile/web apps - yetihq.com
We should point the user to the right direction if he misconfigured the urls conf.
See #64
Hello,
Is it possible to give access to few contributors to the pypi to update the package according to new releases ?
Actually users will install https://pypi.python.org/pypi/django-tastypie-swagger .2 version and I need fixes in .3 ...
Thanks !
Hi,
I was wondering what was the way to have tastypie-swagger in place for multiple versions of an api.
It seems to me this is currently not supported, as the api module to be used is fixed in the settings variable TASTYPIE_SWAGGER_API_MODULE
.
I hacked together a solution where the api module to be used is passed as a kwarg to the view() method through urls.py, but this means that it is loaded on every call to the view() method instead of once per instantiation of the view-class.
Maybe I overlooked how it is intended to be done, I would be happy if someone could give me a hint on how to do it with the existing code. Otherwise I would be happy to contribute my current solution, even if it's only to point in the direction this could go, as it still is a bit hacky and might need some more work.
Thanks,
flo
As of swagger-core 1.2, the default resource listing has been moved from /resources.json to /api-docs.json (see https://github.com/wordnik/swagger-core/wiki/Resource-Listing). Also the default api listing path has moved to /api-docs.json/{path}.
While these are just defaults, the more frameworks that support the standards the better.
Is it possible to augment the swagger docs that are generated from here with extra endpoint information from custom endpoints? I don't see it documented and will add it with a PR if it isn't here but I just want to double check before I do that.
I'm using django 1.5 with tastypie 0.9
The Meta: queryset object is a manager class and yet i get this for every url
Response Class
ListView
class ListView( meta:Meta(), objects{})
class Meta
at the beginning of every expanded operation list and the help text is slammed in with everything else.
Is there a way to manipulate the formatting? I can't style this myself because there's no alternate styling method documented.
Have just installed django-tastypie-swagger and am up against a brick wall.
http://localhost:8000/tasty/doc/ serves the necessary HTML, but doesn't pull in any of the CSS or JS that's needed to make it work.
http://localhost:8000/tasty/doc/resources/ works and shows:
{
basePath: "http://localhost:8000/tasty/doc/schema/",
apis: [
{
path: "/snap"
},
{
path: "/user"
}
],
apiVersion: "0.1",
swaggerVersion: "1.1"
}
But all the others return 404 errors.
Example api where there are no fields (as far as django-tastypie-swagger sees them):
extra_actions = [
{
'name': 'chapters',
'http_method':'GET',
'resource_type':'view',
'description':'Return all chapters for specified book.'
}
{
'name': 'chapters',
'http_method':'GET',
'resource_type':'view',
'description':'Return all chapters for specified book.',
'fields':{}
}
If you have two resources, each of which has a reference to the other (e.g. One has a ToOne reference, one has a ToMany reference) and they're both defined with a filtering of ALL_WITH_RELATIONS, trying to load swagger causes an infinite recursion between the two models.
This happens on this line in tastypie_swagger/mapping.py:
parameters.extend(related_mapping.build_parameters_from_filters(prefix="%s%s__" % (prefix, name)))
Add simple access management for restricted access to whole docs.
Simple setinngs in settings.py
TASTYPIE_SWAGGER_ACCESS = None #, False or undefined - access for everyone
TASTYPIE_SWAGGER_ACCESS = "user" # Only authenticated user
TASTYPIE_SWAGGER_ACCESS = "group" # Only users from group tastypie_swagger
TASTYPIE_SWAGGER_ACCESS = "superuser" Only superusers
If you want, I can write it :)
Hello,
First of all, I'm a python noob so please excuse me if this has been covered somewhere else, I did some research but couldn't find a similar instance.
After installing and doing the basic config I'm getting the following when visiting /api/v1/doc/
[08/Jul/2013 15:21:05] "GET /api/v1/doc/ HTTP/1.1" 200 4297
Internal Server Error: /api/v1/doc/resources/
Traceback (most recent call last):
File "/var/www/identv/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 115, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "/var/www/identv/local/lib/python2.7/site-packages/django/views/generic/base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "/var/www/identv/local/lib/python2.7/site-packages/django/views/generic/base.py", line 86, in dispatch
return handler(request, *args, **kwargs)
File "/var/www/identv/local/lib/python2.7/site-packages/django/views/generic/base.py", line 153, in get
context = self.get_context_data(**kwargs)
File "/var/www/identv/local/lib/python2.7/site-packages/tastypie_swagger/views.py", line 88, in get_context_data
apis = [{'path': '/%s' % name} for name in sorted(self.tastypie_api._registry.keys())]
AttributeError: 'module' object has no attribute '_registry'
[08/Jul/2013 15:21:05] "GET /api/v1/doc/resources/?api_key=special-key HTTP/1.1" 500 10547
here are the relevant configs
urls.py
from api.api import GenreResource, MediaResource, ObjectSelectResource, PlayerResource, TeamResource
apiv1 = Api(api_name='v1')
apiv1.register(GenreResource())
apiv1.register(MediaResource())
apiv1.register(ObjectSelectResource())
apiv1.register(PlayerResource())
apiv1.register(TeamResource())
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'identv.views.home', name='home'),
# url(r'^identv/', include('identv.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
url(r'^api/v1/doc/', include('tastypie_swagger.urls', namespace='tastypie_swagger')),
url(r'^api/', include(apiv1.urls)),
)
settings.py
TASTYPIE_SWAGGER_API_MODULE = 'api.api'
and my api/api.py is pretty straight forward
Here is my filtering part:
class Meta:
...
filtering = {
"fromuid": ('exact', 'startwith',),
"touid": ('exact', 'startwith',),
#"fromuid": ['exact', 'startwith'],
#"touid": ['exact', 'startwith'],
#"fromuid": ALL,
#"touid": ALL,
}
did I miss something ?
I'm running Python 3.3 and Django 1.6.2 with TastyPie 0.11.0
When I add tastypie-swagger to my application, I get
Exception Type: ImportError
Exception Value: cannot import name force_unicode
Exception Location: /Users/smcphee/Development/python/lib/python3.3/site-packages/tastypie_swagger/mapping.py in <module>, line 4
I had a look at mapping.py and sure enough there's
from django.utils.encoding import force_unicode
Inspecting django/utils/encoding.py there is no force_unicode, except this;
(line 174 encoding.py)
if six.PY3:
smart_str = smart_text
force_str = force_text
else:
smart_str = smart_bytes
force_str = force_bytes
# backwards compatibility for Python 2
smart_unicode = smart_text
force_unicode = force_text
So I assume a Python 2.x only symbol? Ergo your package is not Python 3 compatible?
Hello,
I am using django-tastypie-swagger and one colleague of mine wanted to expose a client based on the swagger description.
For that reason he tried using swagger-codegen but it failed since it needs swagger 1.2 version.
Since the tastypie-swagger utilises the 1.1 version, I tried to upgrade with the swagger-codegen once again which also failed due to the paths that swagger gives internally.
The path shows to the API implementation and not the swagger description.
A sample of the implementation can be found here, http://openi.herokuapp.com/api/doc/schema/cbsconnector/?api_key=special-key .
Do you have any ideas on how to use this description with the swagger-codegen?
Thank you very much in advance!
Hi,
I am using tastypie with xml serializer instead of json so is there any way that our tastypie-swagger gives me UI to interact with api in xml format ??
Thanks,
Abdul Wahid
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.