Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove embedded API doc #2343

Merged
merged 3 commits into from
Nov 19, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
61 changes: 0 additions & 61 deletions js/front/apidoc.js

This file was deleted.

5 changes: 2 additions & 3 deletions js/locales/udata.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@
"Restore": "Restore",
"Retry failed - you have reached your file limit.": "Retry failed - you have reached your file limit.",
"Reuse": "Reuse",
"Reused datasets": "Reused datasets",
"Reuses": "Reuses",
"Reuses about your data (including your organizations)": "Reuses about your data (including your organizations)",
"Role": "Role",
Expand All @@ -326,6 +325,7 @@
"Scheduling": "Scheduling",
"Score:": "Score:",
"Search": "Search",
"Search an user": "Search an user",
"Search in your data: {q}": "Search in your data: {q}",
"See in the administration": "See in the administration",
"See on the site": "See on the site",
Expand Down Expand Up @@ -374,6 +374,7 @@
"The user {fullname} has been successfully deleted": "The user {fullname} has been successfully deleted",
"This harvest source has not been validated": "This harvest source has not been validated",
"This is a cron expressions. See {url} for more details.": "This is a cron expressions. See {url} for more details.",
"This item has been deleted": "This item has been deleted",
"This key is needed if you want to use the API.": "This key is needed if you want to use the API.",
"This resource is hosted on an external server": "This resource is hosted on an external server",
"This resource is hosted on our servers": "This resource is hosted on our servers",
Expand Down Expand Up @@ -476,7 +477,6 @@
"Your harvester is now pending for team review.": "Your harvester is now pending for team review.",
"Your harvester is ready": "Your harvester is ready",
"Your issue has been sent to the team": "Your issue has been sent to the team",
"Your mapping has been updated.": "Your mapping has been updated.",
"Your organization has been created": "Your organization has been created",
"Your organization has been updated.": "Your organization has been updated.",
"Your post has been updated.": "Your post has been updated.",
Expand All @@ -486,7 +486,6 @@
"Your resource has been updated.": "Your resource has been updated.",
"Your reuse has been created": "Your reuse has been created",
"Your reuse has been updated.": "Your reuse has been updated.",
"Your source has been updated.": "Your source has been updated.",
"Your topic has been updated.": "Your topic has been updated.",
"and": "and",
"by": "by",
Expand Down
17 changes: 0 additions & 17 deletions less/apidoc.less

This file was deleted.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@
"source-sans-pro": "^2.0.10",
"string_score": "^0.1.22",
"swagger-client": "2.1.13",
"swagger-ui": "2.2.10",
"tv4": "^1.2.7",
"url-search-params-polyfill": "^1.2.0",
"velocity-animate": "^1.2.3",
Expand Down
45 changes: 5 additions & 40 deletions udata/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import itertools
import logging
import urllib

from bson import ObjectId
from functools import wraps

from flask import (
Expand All @@ -14,16 +12,13 @@
from flask_fs import UnauthorizedFileType
from flask_restplus import Api, Resource, cors

from udata import search, theme, tracking
from udata import tracking, theme
from udata.app import csrf
from udata.i18n import I18nBlueprint, get_locale
from udata.auth import (
current_user, login_user, Permission, RoleNeed, PermissionDenied
)
from udata.core.user.models import User
from udata.core.organization.factories import OrganizationFactory
from udata.core.organization.models import Organization
from udata.sitemap import sitemap
from udata.utils import safe_unicode

from . import fields, oauth2
Expand All @@ -35,7 +30,6 @@
apiv1 = Blueprint('api', __name__, url_prefix='/api/1')
apidoc = I18nBlueprint('apidoc', __name__)


DEFAULT_PAGE_SIZE = 50
HEADER_API_KEY = 'X-API-KEY'

Expand Down Expand Up @@ -149,7 +143,7 @@ def validate(self, form_cls, obj=None):
return form

def render_ui(self):
return redirect(url_for('apii18n.apidoc'))
return redirect(current_app.config.get('API_DOC_EXTERNAL_LINK'))

def unauthorized(self, response):
'''Override to change the WWW-Authenticate challenge'''
Expand Down Expand Up @@ -271,41 +265,12 @@ def handle_unauthorized_file_type(error):
@apidoc.route('/api/1/')
@api.documentation
def default_api():
return redirect(url_for('apidoc.swaggerui'))
return redirect(url_for('apidoc.apidoc_index'))


@apidoc.route('/apidoc/')
def swaggerui():
page_size = 10
params = {"datasets": "many"}
organizations = search.iter(Organization)
organizations = list(itertools.islice(organizations, page_size))
if len(organizations) < page_size:
# Fill with dummy values
needs = page_size - len(organizations)
extra_orgs = OrganizationFactory.build_batch(needs)
for org in extra_orgs:
org.id = ObjectId()
Organization.slug.generate()
organizations.extend(extra_orgs)
return theme.render('apidoc.html', specs_url=api.specs_url, organizations=organizations)


@sitemap.register_generator
def api_sitemap_urls():
yield 'apidoc.swaggerui_redirect', {}, None, 'weekly', 0.9


@apidoc.route('/apidoc/images/<path:path>')
def images(path):
return redirect(url_for('static',
filename='bower/swagger-ui/dist/images/' + path))


@apidoc.route('/static/images/throbber.gif')
def fix_apidoc_throbber():
return redirect(url_for('static',
filename='bower/swagger-ui/dist/images/throbber.gif'))
def apidoc_index():
return theme.render('apidoc.html')


class API(Resource): # Avoid name collision as resource is a core model
Expand Down
2 changes: 2 additions & 0 deletions udata/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,8 @@ class Defaults(object):
ARCHIVE_COMMENT_USER_ID = None
ARCHIVE_COMMENT_TITLE = _('This dataset has been archived')

API_DOC_EXTERNAL_LINK = 'https://doc.data.gouv.fr/api/reference/'


class Testing(object):
'''Sane values for testing. Should be applied as override'''
Expand Down