forked from CenterForOpenScience/SHARE
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
160 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
# }, | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) | ||
|