Skip to content

Commit

Permalink
[resotocore][fix] Type of exported model (#1833)
Browse files Browse the repository at this point in the history
  • Loading branch information
aquamatthias authored Nov 21, 2023
1 parent bdbad56 commit 38d43d6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
2 changes: 2 additions & 0 deletions resotocore/resotocore/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1600,6 +1600,8 @@ def from_prop_path(kinds: Iterable[ComplexKind]) -> Tuple[int, Dict[str, str]]:
props[p.name + "[*]"] = pk.inner.fqn
elif isinstance(pk, TransformKind):
props[p.name] = (pk.source_kind or any_kind).fqn
elif isinstance(pk, SimpleKind):
props[p.name] = pk.runtime_kind
else:
props[p.name] = pk.fqn
return len(props), {k: props[k] for k in sorted(props)[skip : skip + limit]}
Expand Down
26 changes: 19 additions & 7 deletions resotocore/resotocore/web/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
from attrs import evolve
from dateutil import parser as date_parser
from networkx.readwrite import cytoscape_data
from resotoui import ui_path

from resotocore.analytics import AnalyticsEvent
from resotocore.cli.command import alias_names
from resotocore.cli.model import (
Expand Down Expand Up @@ -99,7 +101,18 @@
from resotocore.task.model import Subscription
from resotocore.types import Json, JsonElement
from resotocore.user.model import Permission, AuthorizedUser
from resotocore.util import uuid_str, force_gen, rnd_str, if_set, duration, utc_str, parse_utc, async_noop, utc
from resotocore.util import (
async_noop,
duration,
force_gen,
if_set,
parse_utc,
rnd_str,
utc,
utc_str,
uuid_str,
value_in_path_get,
)
from resotocore.web.auth import raw_jwt_from_auth_message, LoginWithCode, AuthHandler
from resotocore.web.content_renderer import result_binary_gen, single_result
from resotocore.web.directives import (
Expand All @@ -120,7 +133,6 @@
from resotolib.asynchronous.web.ws_handler import accept_websocket, clean_ws_handler
from resotolib.jwt import encode_jwt
from resotolib.x509 import cert_to_bytes
from resotoui import ui_path

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -1050,12 +1062,12 @@ async def explain(self, request: Request, deps: TenantDependencies) -> StreamRes
async def property_path_complete(self, request: Request, deps: TenantDependencies) -> StreamResponse:
_, model = await self.graph_model_from_request(request, deps)
body = await request.json()
path = variable_to_absolute(section_of(request), body.get("path", PathRoot)).rstrip(".\n\t")
prop = body.get("prop", "")
path = variable_to_absolute(section_of(request), value_in_path_get(body, "path", PathRoot)).rstrip(".\n\t")
prop = value_in_path_get(body, "prop", "")
filter_kinds = body.get("kinds")
fuzzy = body.get("fuzzy", False)
limit = body.get("limit", 20)
skip = body.get("skip", 0)
fuzzy = value_in_path_get(body, "fuzzy", False)
limit = value_in_path_get(body, "limit", 20)
skip = value_in_path_get(body, "skip", 0)
assert skip >= 0, "Skip must be positive"
assert limit > 0, "Limit must be positive"
count, result = model.complete_path(path, prop, filter_kinds=filter_kinds, fuzzy=fuzzy, skip=skip, limit=limit)
Expand Down
4 changes: 2 additions & 2 deletions resotocore/tests/resotocore/model/model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ def test_complete_path(person_model: Model) -> None:
assert all_props == {"city": "string", "ctime": "datetime", "expires": "datetime", "exported_age": "duration"}
# ask for a nested kind
count, all_props = person_model.complete_path("address", "", fuzzy=False, skip=4, limit=4)
assert all_props == {"mtime": "datetime", "tags": "dictionary[string, string]", "zip": "zip"}
assert all_props == {"mtime": "datetime", "tags": "dictionary[string, string]", "zip": "string"}
# ask for a nested kind filtered
count, all_props = person_model.complete_path("address", "ta", fuzzy=False, skip=0, limit=4)
assert all_props == {"tags": "dictionary[string, string]"}
Expand All @@ -615,7 +615,7 @@ def test_complete_path(person_model: Model) -> None:
assert all_props == {"city": "string", "id": "string", "kind": "string", "list[*]": "string"}
# filter by kinds
count, all_props = person_model.complete_path("", "", filter_kinds=["Address"], skip=5)
assert all_props == {"tags": "dictionary[string, string]", "zip": "zip"}
assert all_props == {"tags": "dictionary[string, string]", "zip": "string"}


@given(json_object_gen)
Expand Down

0 comments on commit 38d43d6

Please sign in to comment.