From 0576b7dbf164f74d50487deb5c7559b8ece2bd07 Mon Sep 17 00:00:00 2001 From: Adrian Gonzalez-Martin Date: Fri, 14 Apr 2023 10:49:11 +0200 Subject: [PATCH] Move OpenAPI schemas into Python package (#1095) Co-authored-by: adriangonz --- Dockerfile | 2 ++ MANIFEST.in | 2 +- mlserver/rest/openapi/__init__.py | 3 +++ mlserver/rest/openapi/dataplane.json | 1 + mlserver/rest/openapi/model_repository.json | 1 + mlserver/rest/{openapi.py => openapi/schema.py} | 4 +--- tests/rest/openapi/__init__.py | 0 tests/rest/{test_openapi.py => openapi/test_schema.py} | 2 +- 8 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 mlserver/rest/openapi/__init__.py create mode 120000 mlserver/rest/openapi/dataplane.json create mode 120000 mlserver/rest/openapi/model_repository.json rename mlserver/rest/{openapi.py => openapi/schema.py} (94%) create mode 100644 tests/rest/openapi/__init__.py rename tests/rest/{test_openapi.py => openapi/test_schema.py} (95%) diff --git a/Dockerfile b/Dockerfile index 11e503434..2737de522 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,9 +3,11 @@ SHELL ["/bin/bash", "-l", "-c"] COPY ./hack/build-wheels.sh ./hack/build-wheels.sh COPY ./mlserver ./mlserver +COPY ./openapi ./openapi COPY ./runtimes ./runtimes COPY \ setup.py \ + MANIFEST.in \ README.md \ . diff --git a/MANIFEST.in b/MANIFEST.in index c8964f1dc..80bcc2ff9 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1 +1 @@ -include openapi/*.json +include mlserver/rest/openapi/*.json diff --git a/mlserver/rest/openapi/__init__.py b/mlserver/rest/openapi/__init__.py new file mode 100644 index 000000000..92cb17843 --- /dev/null +++ b/mlserver/rest/openapi/__init__.py @@ -0,0 +1,3 @@ +from .schema import get_openapi_schema, get_model_schema, get_model_schema_uri + +__all__ = ["get_openapi_schema", "get_model_schema", "get_model_schema_uri"] diff --git a/mlserver/rest/openapi/dataplane.json b/mlserver/rest/openapi/dataplane.json new file mode 120000 index 000000000..812215f4d --- /dev/null +++ b/mlserver/rest/openapi/dataplane.json @@ -0,0 +1 @@ +../../../openapi/dataplane.json \ No newline at end of file diff --git a/mlserver/rest/openapi/model_repository.json b/mlserver/rest/openapi/model_repository.json new file mode 120000 index 000000000..47a818e36 --- /dev/null +++ b/mlserver/rest/openapi/model_repository.json @@ -0,0 +1 @@ +../../../openapi/model_repository.json \ No newline at end of file diff --git a/mlserver/rest/openapi.py b/mlserver/rest/openapi/schema.py similarity index 94% rename from mlserver/rest/openapi.py rename to mlserver/rest/openapi/schema.py index ed85b3dec..ec04abbce 100644 --- a/mlserver/rest/openapi.py +++ b/mlserver/rest/openapi/schema.py @@ -4,15 +4,13 @@ from typing import Optional, Tuple from importlib_resources import files -OPENAPI_SCHEMA_RELATIVE_PATH = "../openapi/dataplane.json" MODEL_NAME_PARAMETER = "model_name" MODEL_VERSION_PARAMETER = "model_version" @lru_cache def get_openapi_schema() -> dict: - mlserver_package = __package__.split(".")[0] - openapi_schema_path = files(mlserver_package).joinpath(OPENAPI_SCHEMA_RELATIVE_PATH) + openapi_schema_path = files(__package__).joinpath("dataplane.json") return orjson.loads(openapi_schema_path.read_bytes()) diff --git a/tests/rest/openapi/__init__.py b/tests/rest/openapi/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/rest/test_openapi.py b/tests/rest/openapi/test_schema.py similarity index 95% rename from tests/rest/test_openapi.py rename to tests/rest/openapi/test_schema.py index 8d2d2c960..02a8dbd1a 100644 --- a/tests/rest/test_openapi.py +++ b/tests/rest/openapi/test_schema.py @@ -2,7 +2,7 @@ from typing import Optional -from mlserver.rest.openapi import ( +from mlserver.rest.openapi.schema import ( get_openapi_schema, get_model_schema, MODEL_VERSION_PARAMETER,