Skip to content

Commit

Permalink
Move OpenAPI schemas into Python package (#1095)
Browse files Browse the repository at this point in the history
Co-authored-by: adriangonz <adriangonz@users.noreply.github.com>
  • Loading branch information
Adrian Gonzalez-Martin and adriangonz committed Apr 14, 2023
1 parent 9297862 commit 0576b7d
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
.

Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include openapi/*.json
include mlserver/rest/openapi/*.json
3 changes: 3 additions & 0 deletions mlserver/rest/openapi/__init__.py
Original file line number Diff line number Diff line change
@@ -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"]
1 change: 1 addition & 0 deletions mlserver/rest/openapi/dataplane.json
1 change: 1 addition & 0 deletions mlserver/rest/openapi/model_repository.json
4 changes: 1 addition & 3 deletions mlserver/rest/openapi.py → mlserver/rest/openapi/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())


Expand Down
Empty file added tests/rest/openapi/__init__.py
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 0576b7d

Please sign in to comment.