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

serve xml schema definitions #5

Merged
merged 2 commits into from
Dec 16, 2024
Merged
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
19 changes: 17 additions & 2 deletions oaipmh/requests/routes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import Dict
from flask import Blueprint, request
from flask import Blueprint, request, send_file

from oaipmh.requests.info_queries import identify, list_metadata_formats, list_sets
from oaipmh.requests.data_queries import get_record, list_data
Expand All @@ -10,7 +10,6 @@

blueprint = Blueprint('general', __name__)


@blueprint.route("/oai", methods=['GET', 'POST'])
def oai() -> Response:
"""
Expand Down Expand Up @@ -41,6 +40,22 @@ def oai() -> Response:

return response, code, headers

@blueprint.route("/OAI/arXivRaw.xsd", methods=['GET', 'POST'])
def schema_arXivRaw() -> Response:
file_path = "templates/schema/arXivRaw.xsd"
return send_file(file_path, mimetype="application/xml")


@blueprint.route("/OAI/arXiv.xsd", methods=['GET', 'POST'])
def schema_arXiv() -> Response:
file_path = "templates/schema/arXiv.xsd"
return send_file(file_path, mimetype="application/xml")

@blueprint.route("/OAI/arXivOld.xsd", methods=['GET', 'POST'])
def schema_arXivOld() -> Response:
file_path = "templates/schema/arXivOld.xsd"
return send_file(file_path, mimetype="application/xml")

@blueprint.route('/favicon.ico')
def favicon():
#TODO
Expand Down
70 changes: 70 additions & 0 deletions oaipmh/templates/schema/arXiv.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:arXiv="http://arxiv.org/OAI/arXiv/"
targetNamespace="http://arxiv.org/OAI/arXiv/"
elementFormDefault="qualified"
attributeFormDefault="unqualified">

<annotation>
<documentation>
Schema for arXiv metadata which includes author names separated
out, category and license information. See http://arxiv.org/help/oa .
Simeon Warner - [email protected] - 9Nov2000, 7Dec2000, 21Jan2001
Added categories, doi, proxy, license; removed subj-class.
Simeon Warner - [email protected] - 2008-08-05.
Added created (submission date of first version) and updated (submission
date of latest version if there are revisions), updated to use 2001
schema namespace http://www.w3.org/2001/XMLSchema.
Simeon Warner - 2008-11-04.
Added missing acm-class element (thanks @mitar) - 2014-06-24.
</documentation>
</annotation>

<element name="arXiv" type="arXiv:arXivType"/>

<complexType name="arXivType">
<choice minOccurs="0" maxOccurs="unbounded">
<element name="id" minOccurs="1" maxOccurs="1" type="string"/>
<element name="created" minOccurs="0" maxOccurs="1" type="string"/>
<element name="updated" minOccurs="0" maxOccurs="1" type="string"/>
<element name="authors" minOccurs="0" maxOccurs="1" type="arXiv:authorsType"/>
<element name="title" minOccurs="0" maxOccurs="1" type="string"/>
<element name="msc-class" minOccurs="0" maxOccurs="1" type="string"/>
<element name="acm-class" minOccurs="0" maxOccurs="1" type="string"/>
<element name="report-no" minOccurs="0" maxOccurs="1" type="string"/>
<element name="journal-ref" minOccurs="0" maxOccurs="1" type="string"/>
<element name="comments" minOccurs="0" maxOccurs="1" type="string"/>
<element name="abstract" minOccurs="0" maxOccurs="1" type="string"/>
<element name="categories" minOccurs="0" maxOccurs="1" type="string"/>
<element name="doi" minOccurs="0" maxOccurs="1" type="string"/>
<element name="proxy" minOccurs="0" maxOccurs="1" type="string"/>
<element name="license" minOccurs="0" maxOccurs="1" type="string"/>
</choice>
</complexType>

<complexType name="authorsType">
<sequence>
<element name="author" minOccurs="1" maxOccurs="unbounded" type="arXiv:authorType"/>
</sequence>
</complexType>

<!-- should we separate out suffixes (I, II, II, Jr, Sr) from the surname? -->
<!-- should there be a suffix field? what about other languages> -->
<!-- keyname is separated out as that is the key field on which one
would likely want to search. The keyname may include the space
character. In many cultures the keyname would correspond to the
surname -->
<!-- the forenames are all the names that would usually be written before
the keyname -->
<!-- the suffix should include all names and letters (eg. I, II, II, Jr, Sr)
that would usually be written after the keyname -->

<complexType name="authorType">
<sequence>
<element name="keyname" minOccurs="1" maxOccurs="1" type="string"/>
<element name="forenames" minOccurs="0" maxOccurs="1" type="string"/>
<element name="suffix" minOccurs="0" maxOccurs="1" type="string"/>
<element name="affiliation" minOccurs="0" maxOccurs="unbounded" type="string"/>
</sequence>
</complexType>

</schema>
36 changes: 36 additions & 0 deletions oaipmh/templates/schema/arXivOld.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:arXivOld="http://arxiv.org/OAI/arXivOld/"
targetNamespace="http://arxiv.org/OAI/arXivOld/"
elementFormDefault="qualified"
attributeFormDefault="unqualified">

<annotation>
<documentation>
Schema for arXiv internal metadata format.
See http://arxiv.org/help/oa .
Simeon Warner - 9Nov2000, 21Jan2001, 26Jan2001.
Fix namespace, add missing elements (thanks @mitar) - 2014-06-24.
</documentation>
</annotation>

<element name="arXivOld" type="arXivOld:arXivOldType"/>

<complexType name="arXivOldType">
<sequence>
<element name="id" minOccurs="1" maxOccurs="1" type="string"/>
<element name="title" minOccurs="0" maxOccurs="1" type="string"/>
<element name="authors" minOccurs="0" maxOccurs="1" type="string"/>
<element name="categories" minOccurs="0" maxOccurs="1" type="string"/>
<element name="comments" minOccurs="0" maxOccurs="1" type="string"/>
<element name="proxy" minOccurs="0" maxOccurs="1" type="string"/>
<element name="report-no" minOccurs="0" maxOccurs="1" type="string"/>
<element name="msc-class" minOccurs="0" maxOccurs="1" type="string"/>
<element name="acm-class" minOccurs="0" maxOccurs="1" type="string"/>
<element name="journal-ref" minOccurs="0" maxOccurs="1" type="string"/>
<element name="doi" minOccurs="0" maxOccurs="1" type="string"/>
<element name="abstract" minOccurs="0" maxOccurs="1" type="string"/>
<element name="license" minOccurs="0" maxOccurs="1" type="string"/>
</sequence>
</complexType>

</schema>
62 changes: 62 additions & 0 deletions oaipmh/templates/schema/arXivRaw.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:arXivRaw="http://arxiv.org/OAI/arXivRaw/"
targetNamespace="http://arxiv.org/OAI/arXivRaw/"
elementFormDefault="qualified"
attributeFormDefault="unqualified">

<annotation>
<documentation>
Schema for arXiv metadata in arXivRaw format. This format closely
matches the internal metadata format used at arXiv and will change
if that format changes. See http://arxiv.org/help/oa .
2007-05-01 - created.
2014-02-06 - added license.
2014-06-24 - added proxy (thanks @mitar).
</documentation>
</annotation>

<element name="arXivRaw" type="arXivRaw:arXivRaw_type"/>

<complexType name="arXivRaw_type">
<sequence>
<element name="id" minOccurs="1" maxOccurs="1" type="string"/>
<element name="submitter" minOccurs="1" maxOccurs="1" type="string"/>
<element name="version" minOccurs="1" maxOccurs="unbounded" type="arXivRaw:version_type"/>
<element name="title" minOccurs="0" maxOccurs="1" type="string"/>
<element name="authors" minOccurs="0" maxOccurs="1" type="string"/>
<element name="categories" minOccurs="1" maxOccurs="1" type="string"/>
<element name="comments" minOccurs="0" maxOccurs="1" type="string"/>
<element name="proxy" minOccurs="0" maxOccurs="1" type="string"/>
<element name="report-no" minOccurs="0" maxOccurs="1" type="string"/>
<element name="acm-class" minOccurs="0" maxOccurs="1" type="string"/>
<element name="msc-class" minOccurs="0" maxOccurs="1" type="string"/>
<element name="journal-ref" minOccurs="0" maxOccurs="1" type="string"/>
<element name="doi" minOccurs="0" maxOccurs="1" type="string"/>
<element name="license" minOccurs="0" maxOccurs="1" type="anyURI"/>
<element name="abstract" minOccurs="0" maxOccurs="1" type="string"/>
</sequence>
</complexType>

<complexType name="version_type">
<complexContent>
<extension base="arXivRaw:version_content_type">
<attribute name="version" type="arXivRaw:version_id_type"/>
</extension>
</complexContent>
</complexType>

<complexType name="version_content_type">
<sequence>
<element name="date" minOccurs="1" maxOccurs="1" type="string"/>
<element name="size" minOccurs="0" maxOccurs="1" type="string"/>
<element name="source_type" minOccurs="0" maxOccurs="1" type="string"/>
</sequence>
</complexType>

<simpleType name="version_id_type">
<restriction base="string">
<pattern value="v[0-9]+"/>
</restriction>
</simpleType>

</schema>
28 changes: 28 additions & 0 deletions tests/test_serve_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@


def test_schema_arXivRaw(test_client):
response = test_client.get("/OAI/arXivRaw.xsd")
assert response.status_code == 200
assert b"<schema" in response.data
assert b"</schema>" in response.data
assert b'xmlns:arXivRaw="http://arxiv.org/OAI/arXivRaw/"' in response.data
assert b'<element name="arXivRaw" type="arXivRaw:arXivRaw_type"/>' in response.data
assert b'<complexType name="version_type">' in response.data

def test_schema_arXivOld(test_client):
response = test_client.get("/OAI/arXivOld.xsd")
assert response.status_code == 200
assert b"<schema" in response.data
assert b"</schema>" in response.data
assert b'xmlns:arXivOld="http://arxiv.org/OAI/arXivOld/"' in response.data
assert b'<element name="arXivOld" type="arXivOld:arXivOldType"/>' in response.data
assert b'<complexType name="arXivOldType">' in response.data

def test_schema_arXiv(test_client):
response = test_client.get("/OAI/arXiv.xsd")
assert response.status_code == 200
assert b"<schema" in response.data
assert b"</schema>" in response.data
assert b'xmlns:arXiv="http://arxiv.org/OAI/arXiv/"' in response.data
assert b'<element name="arXiv" type="arXiv:arXivType"/>' in response.data
assert b'<complexType name="authorsType">' in response.data
Loading