Skip to content

Commit

Permalink
wip: openapi
Browse files Browse the repository at this point in the history
  • Loading branch information
aaxelb committed Nov 2, 2023
1 parent 4eca7ff commit d70e2de
Show file tree
Hide file tree
Showing 2 changed files with 160 additions and 0 deletions.
135 changes: 135 additions & 0 deletions trove/openapi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import json


def get_trove_openapi_json() -> str:
return json.dumps(get_trove_openapi())


def get_trove_openapi() -> dict:
return { # following https://spec.openapis.org/oas/v3.1.0
'openapi': '3.1.0',
'info': {
'title': 'trove: a catalog of index-cards (of rdf metadata)',
# 'summary': '',
# 'description': '',
'termsOfService': 'https://github.com/CenterForOpenScience/cos.io/blob/HEAD/TERMS_OF_USE.md',
'contact': {
# 'name':
# 'url': web-browsable version of this
'email': '[email protected]',
},
# 'license':
'version': '23.2.0',
},
'servers': [{
'url': 'https://share.osf.io',
}],
'paths': {
'/trove/index-card-search': {
'summary': 'search for index-cards that match some iri filters and text',
# 'description':
'get': {
# 'tags':
# 'summary':
# 'description':
# 'externalDocs':
'operationId': 'index-card-search--get',
'parameters': [
{'$ref': '#/components/parameters/cardSearchText'},
{'$ref': '#/components/parameters/cardSearchFilter'},
{'$ref': '#/components/parameters/page'},
{'$ref': '#/components/parameters/page[size]'},
{'$ref': '#/components/parameters/sort'},
# {'$ref': '#/components/parameters/include'},
],
},
},
'/trove/index-value-search': {
'summary': 'search for iri-identified values for specific properties on index-cards that match some iri filters and text',
# 'description':
'get': {
# 'tags':
# 'summary':
# 'description':
# 'externalDocs':
'operationId': 'index-value-search--get',
'parameters': [
{'$ref': '#/components/parameters/valueSearchPropertyPath'},
{'$ref': '#/components/parameters/valueSearchText'},
{'$ref': '#/components/parameters/valueSearchFilter'},
{'$ref': '#/components/parameters/cardSearchText'},
{'$ref': '#/components/parameters/cardSearchFilter'},
{'$ref': '#/components/parameters/page'},
{'$ref': '#/components/parameters/page[size]'},
{'$ref': '#/components/parameters/sort'},
# {'$ref': '#/components/parameters/include'},
],
},
},
},
'components': {
'parameters': { # TODO: generate /components/parameters from search_param dataclasses (or vocab)?
'cardSearchText': {
'name': 'cardSearchText',
'in': 'query',
'required': False,
'description': 'TODO',
},
'cardSearchFilter': {
'name': 'cardSearchFilter[{propertyPaths}][{filterOperation}]',
'in': 'query',
'required': False,
'description': '''
## cardSearchFilter
each query parameter in the *cardSearchFilter* family may exclude index-cards from
the result set based on IRI values at specific locations in the index-card rdf tree.
### propertyPaths
''',
},
'valueSearchPropertyPath': {
'name': 'valueSearchPropertyPath',
'in': 'query',
'required': True,
'description': 'TODO',
},
'valueSearchText': {
'name': 'valueSearchText',
'in': 'query',
'required': False,
'description': 'TODO',
},
'valueSearchFilter': {
'name': 'valueSearchFilter[{propertyPaths}][{filterOperation}]',
'in': 'query',
'required': False,
'description': 'TODO',
},
'page': {
'name': 'page',
'in': 'query',
'required': False,
'description': 'TODO',
},
'page[size]': {
'name': 'page[size]',
'in': 'query',
'required': False,
'description': 'TODO',
},
'sort': {
'name': 'sort',
'in': 'query',
'required': False,
'description': 'TODO',
},
# 'include': {
# 'name': 'include',
# 'in': 'query',
# 'required': False,
# 'description': 'TODO',
# },
},
},
}
25 changes: 25 additions & 0 deletions trove/views/docs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from django import http
from django.views import View

from trove.openapi import get_trove_openapi_json


class OpenapiJsonView(View):
def get(self, request):
return http.HttpResponse(
content=get_trove_openapi_json(),
content_type='application/json',
)


class OpenapiUiView(View):
def get(self, request):
return http.HttpResponse(
content=render_from_rdf(
_search_gathering.leaf_a_record(),
_search_iri,
JSONAPI_MEDIATYPE,
),
content_type=JSONAPI_MEDIATYPE,
)

0 comments on commit d70e2de

Please sign in to comment.