Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
api-client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Arkindex
api-client
Commits
86c2b0bc
Verified
Commit
86c2b0bc
authored
Sep 9, 2021
by
Erwan Rouchet
Browse files
Options
Downloads
Patches
Plain Diff
Detect x-paginated in the API schema
parent
866a883d
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!207
Detect x-paginated in the API schema
Pipeline
#29131
passed
Sep 17, 2021
Stage: release
Changes
4
Pipelines
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
arkindex/client.py
+11
-3
11 additions, 3 deletions
arkindex/client.py
tests/schema.json
+131
-0
131 additions, 0 deletions
tests/schema.json
tests/test_init.py
+2
-0
2 additions, 0 deletions
tests/test_init.py
tests/test_pagination.py
+13
-0
13 additions, 0 deletions
tests/test_pagination.py
with
157 additions
and
3 deletions
arkindex/client.py
+
11
−
3
View file @
86c2b0bc
...
...
@@ -116,6 +116,10 @@ class ArkindexClient(apistar.Client):
operation
=
_find_operation
(
schema
,
link_info
.
link
.
name
)
link_info
.
link
.
deprecated
=
operation
.
get
(
"
deprecated
"
,
False
)
# Detect paginated links
if
"
x-paginated
"
in
operation
:
link_info
.
link
.
_paginated
=
operation
[
"
x-paginated
"
]
# Remove domains from each endpoint; allows APIStar to properly handle our base URL
# https://github.com/encode/apistar/issues/657
original_url
=
urlsplit
(
link_info
.
link
.
url
)
...
...
@@ -176,14 +180,18 @@ class ArkindexClient(apistar.Client):
# Add the Referer header to allow Django CSRF to function
self
.
transport
.
headers
.
setdefault
(
"
Referer
"
,
self
.
document
.
url
)
def
paginate
(
self
,
*
args
,
**
kwargs
):
def
paginate
(
self
,
operation_id
,
*
args
,
**
kwargs
):
"""
Perform a usual request as done by APIStar, but handle paginated endpoints.
:return: An iterator for a paginated endpoint.
:rtype: arkindex.pagination.ResponsePaginator
:rtype:
Union[
arkindex.pagination.ResponsePaginator
, dict, list]
"""
return
ResponsePaginator
(
self
,
*
args
,
**
kwargs
)
link
=
self
.
lookup_operation
(
operation_id
)
# If there was no x-paginated, trust the caller and assume the endpoint is paginated
if
getattr
(
link
,
"
_paginated
"
,
True
):
return
ResponsePaginator
(
self
,
operation_id
,
*
args
,
**
kwargs
)
return
self
.
request
(
operation_id
,
*
args
,
**
kwargs
)
def
login
(
self
,
email
,
password
):
"""
...
...
This diff is collapsed.
Click to expand it.
tests/schema.json
+
131
−
0
View file @
86c2b0bc
...
...
@@ -223,6 +223,137 @@
}
}
}
},
"/api/v1/element/{id}/metadata/"
:
{
"get"
:
{
"operationId"
:
"ListElementMetaData"
,
"description"
:
"List all metadata linked to an element."
,
"parameters"
:
[
{
"in"
:
"path"
,
"name"
:
"id"
,
"schema"
:
{
"type"
:
"string"
,
"format"
:
"uuid"
},
"required"
:
true
}
],
"tags"
:
[
"elements"
],
"security"
:
[
{
"cookieAuth"
:
[]
},
{
"tokenAuth"
:
[]
},
{
"agentAuth"
:
[]
}
],
"responses"
:
{
"200"
:
{
"content"
:
{
"application/json"
:
{
"schema"
:
{
"type"
:
"array"
,
"items"
:
{
"type"
:
"object"
,
"description"
:
"Allow editing MetaData"
,
"properties"
:
{
"id"
:
{
"type"
:
"string"
,
"format"
:
"uuid"
,
"readOnly"
:
true
},
"type"
:
{
"enum"
:
[
"text"
,
"markdown"
,
"date"
,
"location"
,
"reference"
,
"numeric"
],
"type"
:
"string"
},
"name"
:
{
"type"
:
"string"
,
"maxLength"
:
250
},
"value"
:
{
"type"
:
"string"
},
"dates"
:
{
"type"
:
"array"
,
"items"
:
{
"type"
:
"object"
,
"description"
:
"Serialize a list of interpreted dates linked to a metadata"
,
"properties"
:
{
"type"
:
{
"enum"
:
[
"exact"
,
"lower"
,
"upper"
,
"unknown"
],
"type"
:
"string"
},
"year"
:
{
"type"
:
"integer"
,
"minimum"
:
0
},
"month"
:
{
"type"
:
"integer"
,
"maximum"
:
12
,
"minimum"
:
1
,
"nullable"
:
true
},
"day"
:
{
"type"
:
"integer"
,
"maximum"
:
31
,
"minimum"
:
1
,
"nullable"
:
true
}
},
"required"
:
[
"day"
,
"month"
,
"type"
,
"year"
]
},
"readOnly"
:
true
},
"entity"
:
{
"type"
:
"string"
,
"format"
:
"uuid"
,
"nullable"
:
true
},
"worker_version"
:
{
"type"
:
"string"
,
"format"
:
"uuid"
,
"nullable"
:
true
}
},
"required"
:
[
"dates"
,
"id"
,
"name"
,
"type"
,
"value"
]
}
}
}
},
"description"
:
""
}
},
"x-paginated"
:
false
}
}
},
"components"
:
{
...
...
This diff is collapsed.
Click to expand it.
tests/test_init.py
+
2
−
0
View file @
86c2b0bc
...
...
@@ -67,6 +67,7 @@ def test_schema_url():
assert
[
link
.
name
for
link
in
cli
.
document
.
walk_links
()]
==
[
"
UploadDataFile
"
,
"
elements:ListElements
"
,
"
elements:ListElementMetaData
"
,
"
imports:ListProcessElements
"
,
]
...
...
@@ -77,5 +78,6 @@ def test_local_path():
assert
[
link
.
name
for
link
in
cli
.
document
.
walk_links
()]
==
[
"
UploadDataFile
"
,
"
elements:ListElements
"
,
"
elements:ListElementMetaData
"
,
"
imports:ListProcessElements
"
,
]
This diff is collapsed.
Click to expand it.
tests/test_pagination.py
+
13
−
0
View file @
86c2b0bc
...
...
@@ -214,3 +214,16 @@ def test_cursor_pagination_zero_results(mock_schema):
assert
len
(
paginator
)
==
0
assert
list
(
paginator
)
==
[]
assert
len
(
responses
.
calls
)
==
2
def
test_paginate_x_paginated
(
mock_schema
):
responses
.
add
(
responses
.
GET
,
"
https://dummy.test/api/v1/element/element_id/metadata/
"
,
match_querystring
=
True
,
json
=
[
"
a
"
,
"
b
"
],
)
cli
=
ArkindexClient
(
"
t0k3n
"
,
base_url
=
"
https://dummy.test
"
)
assert
cli
.
paginate
(
"
ListElementMetaData
"
,
id
=
"
element_id
"
)
==
[
"
a
"
,
"
b
"
]
assert
len
(
responses
.
calls
)
==
2
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment