Skip to content

Commit

Permalink
Update API schema
Browse files Browse the repository at this point in the history
  • Loading branch information
axelboc committed Jan 29, 2024
1 parent de5ceee commit f06ba3e
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 34 deletions.
79 changes: 57 additions & 22 deletions docs/_static/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -270,50 +270,51 @@ components:
mixed:
description: Gets data[5, 0:10:2]
value: [5, '0:10:2']

schemas:
# Metadata schemas
attrMetadata:
type: object
description: Attribute metadata. Does not include the value.
properties:
dtype:
$ref: '#/components/schemas/dtype'
name:
type: string
example: 'attr1_name'
shape:
$ref: '#/components/schemas/shape'
type:
$ref: '#/components/schemas/type'
entityMetadata:
type: object
properties:
kind:
enum: ['other']
type: string
name:
type: string
example: 'entity_name'
type:
enum: ['other']
type: string
softLinkMetadata:
allOf:
- $ref: '#/components/schemas/entityMetadata'
- type: object
properties:
kind:
enum: ['soft_link']
type: string
target_path:
type: string
example: '/path/to/linked/entity'
type:
enum: ['soft_link']
type: string
externalLinkMetadata:
allOf:
- $ref: '#/components/schemas/softLinkMetadata'
- type: object
properties:
target_file:
type: string
type:
kind:
enum: ['external_link']
type: string
example: 'path/to/another/file.h5'
target_file:
type: string
resolvedEntityMetadata:
allOf:
- $ref: '#/components/schemas/entityMetadata'
Expand All @@ -328,25 +329,28 @@ components:
- $ref: '#/components/schemas/resolvedEntityMetadata'
- type: object
properties:
kind:
enum: ['dataset']
type: string
shape:
$ref: '#/components/schemas/shape'
type:
$ref: '#/components/schemas/type'
chunks:
$ref: '#/components/schemas/shape'
dtype:
$ref: '#/components/schemas/dtype'
filters:
type: array
items:
$ref: '#/components/schemas/filterInfo'
nullable: true
shape:
$ref: '#/components/schemas/shape'
type:
enum: ['dataset']
type: string
groupMetadata:
allOf:
- $ref: '#/components/schemas/resolvedEntityMetadata'
- type: object
properties:
kind:
enum: ['group']
type: string
children:
type: array
items:
Expand All @@ -356,18 +360,49 @@ components:
- $ref: '#/components/schemas/externalLinkMetadata'
- $ref: '#/components/schemas/resolvedEntityMetadata'
- $ref: '#/components/schemas/softLinkMetadata'
type:
enum: ['group']
type: string
childGroupMetadata:
allOf:
- $ref: '#/components/schemas/resolvedEntityMetadata'
- type: object
properties:
type:
kind:
enum: ['group']
type: string

# Other schemas
type:
type: object
properties:
class:
type: integer
dtype:
$ref: '#/components/schemas/dtype'
size:
type: integer
order:
type: integer
sign:
type: integer
cset:
type: integer
vlen:
type: boolean
tag:
type: string
dims:
$ref: '#/components/schemas/shape'
dims:
$ref: '#/components/schemas/shape'
members:
oneOf:
- type: object
additionalProperties:
$ref: '#/components/schemas/type'
- type: object
additionalProperties:
type: integer
base:
$ref: '#/components/schemas/type'
dtype:
oneOf:
- type: 'string'
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# -- Project information -----------------------------------------------------

project = "h5grove"
copyright = "2021, ESRF"
copyright = "2024, ESRF"
author = "ESRF"

# The full version, including alpha/beta/rc tags
Expand Down
1 change: 1 addition & 0 deletions h5grove/fastapi_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Helpers for usage with `FastAPI <https://fastapi.tiangolo.com/>`_"""

from fastapi import APIRouter, Depends, Response, Query, Request
from fastapi.routing import APIRoute
from pydantic_settings import BaseSettings
Expand Down
1 change: 1 addition & 0 deletions h5grove/flask_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Helpers for usage with `Flask <https://flask.palletsprojects.com/>`_"""

from werkzeug.exceptions import HTTPException
from flask import Blueprint, current_app, request, Response, Request
import os
Expand Down
1 change: 1 addition & 0 deletions h5grove/tornado_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Helpers for usage with `Tornado <https://www.tornadoweb.org>`_"""

import os
from typing import Any, Optional

Expand Down
20 changes: 11 additions & 9 deletions h5grove/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ def get_type_metadata(type_id: h5py.h5t.TypeID) -> TypeMetadata:

if isinstance(type_id, h5py.h5t.TypeEnumID):
for i in range(0, type_id.get_nmembers()):
members[
type_id.get_member_name(i).decode("utf-8")
] = type_id.get_member_value(i)
members[type_id.get_member_name(i).decode("utf-8")] = (
type_id.get_member_value(i)
)

return {
**base_metadata,
Expand Down Expand Up @@ -267,12 +267,14 @@ def get_array_stats(data: np.ndarray) -> Dict[str, Union[float, int, None]]:
strict_positive_data = data[data > 0]
positive_data = data[data >= 0]
return {
"strict_positive_min": cast(np.min(strict_positive_data))
if strict_positive_data.size != 0
else None,
"positive_min": cast(np.min(positive_data))
if positive_data.size != 0
else None,
"strict_positive_min": (
cast(np.min(strict_positive_data))
if strict_positive_data.size != 0
else None
),
"positive_min": (
cast(np.min(positive_data)) if positive_data.size != 0 else None
),
"min": cast(np.min(data)),
"max": cast(np.max(data)),
"mean": cast(np.mean(data)),
Expand Down
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ dev =
myst-parser
# Needed for fastapi tests. Could be removed by setting fastapi[all] as dep in the future.
httpx >= 0.23
pydantic_settings
pytest
pytest-benchmark
pytest-cov
Expand Down
2 changes: 1 addition & 1 deletion tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test(c, verbose=False, keyword="", cov_lines=False):
c.run(
"pytest --benchmark-skip"
+ (" -vv" if verbose else "")
+ ((" -k" + keyword) if keyword else "")
+ (f" -k{keyword}" if keyword else "")
+ (" --cov-report term-missing" if cov_lines else "")
)

Expand Down
1 change: 1 addition & 0 deletions test/base_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Base class for testing with different servers"""

import os
import stat
from typing import Generator
Expand Down
1 change: 1 addition & 0 deletions test/test_benchmark_data.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Benchmark data requests with server apps in example/ folder"""

import pathlib
from typing import Generator
from urllib.parse import urlencode
Expand Down
1 change: 1 addition & 0 deletions test/test_fastapi.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test fastapi_utils with fastapi testing"""

import pathlib
from typing import Callable
from fastapi import FastAPI
Expand Down
1 change: 1 addition & 0 deletions test/test_flask.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test flask_utils blueprint with Flask testing"""

import pathlib
from typing import Callable
from flask import Flask
Expand Down
1 change: 1 addition & 0 deletions test/test_tornado.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test tornado_utils using pytest-tornado"""

import pathlib
from typing import Callable
import pytest
Expand Down

0 comments on commit f06ba3e

Please sign in to comment.