Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 27 additions & 8 deletions src/keria/app/aiding.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,15 +488,12 @@ class GroupKeyState:


@dataclass
class HabState:
"""Data class for identifier resource result"""
class HabStateBase:
"""Base data class for identifier state (minimal)"""

name: str
prefix: str
icp_dt: str
state: KeyStateRecord
transferable: Optional[bool] = None
windexes: Optional[List[str]] = None
# One of salty, randy, group, or extern must be present
# Patch to ensure only one of these is set in specing

Expand All @@ -508,6 +505,28 @@ def __post_init__(self):
)


@dataclass
class HabState(HabStateBase):
"""Data class for identifier resource result (full state)"""

state: KeyStateRecord = field(
default_factory=KeyStateRecord,
metadata={
"marshmallow_field": fields.Nested(
class_schema(KeyStateRecord), required=True
)
},
)
transferable: bool = field(
default=False,
metadata={"marshmallow_field": fields.Boolean(required=True)},
)
windexes: list[str] = field(
default_factory=list,
metadata={"marshmallow_field": fields.List(fields.String(), required=True)},
)


class IdentifierCollectionEnd:
"""Resource class for creating and managing identifiers"""

Expand Down Expand Up @@ -545,7 +564,7 @@ def on_get(req, rep):
schema:
type: array
items:
$ref: '#/components/schemas/Identifier'
$ref: '#/components/schemas/HabStateBase'
206:
description: Successfully retrieved identifiers within the specified range.
"""
Expand Down Expand Up @@ -853,7 +872,7 @@ def on_get(req, rep, name):
content:
application/json:
schema:
$ref: '#/components/schemas/Identifier'
$ref: '#/components/schemas/HabState'
400:
description: Bad request. This could be due to a missing or invalid name parameter.
404:
Expand Down Expand Up @@ -915,7 +934,7 @@ def on_put(self, req, rep, name):
content:
application/json:
schema:
$ref: '#/components/schemas/Identifier'
$ref: '#/components/schemas/HabState'
400:
description: Bad request. This could be due to a missing or invalid name parameter.
404:
Expand Down
24 changes: 17 additions & 7 deletions src/keria/app/specing.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,10 @@ def __init__(self, app, title, version="1.0.1", openapi_version="3.1.0"):
]
}

# Identifiers
# Register HabState
self.spec.components.schema(
"HabState", schema=marshmallow_dataclass.class_schema(aiding.HabState)()
)
self.spec.components.schema(
"SaltyState", schema=marshmallow_dataclass.class_schema(aiding.SaltyState)()
)
Expand All @@ -235,11 +238,8 @@ def __init__(self, app, title, version="1.0.1", openapi_version="3.1.0"):
"ExternState",
schema=marshmallow_dataclass.class_schema(aiding.ExternState)(),
)
self.spec.components.schema(
"Identifier", schema=marshmallow_dataclass.class_schema(aiding.HabState)()
)
identifierSchema = self.spec.components.schemas["Identifier"]
identifierSchema["oneOf"] = [

statesList = [
{
"required": ["salty"],
"properties": {"salty": {"$ref": "#/components/schemas/SaltyState"}},
Expand All @@ -257,8 +257,18 @@ def __init__(self, app, title, version="1.0.1", openapi_version="3.1.0"):
"properties": {"extern": {"$ref": "#/components/schemas/ExternState"}},
},
]

self.spec.components.schema(
"HabStateBase",
schema=marshmallow_dataclass.class_schema(aiding.HabStateBase)(),
)
habStateSchemaBase = self.spec.components.schemas["HabStateBase"]
habStateSchemaBase["oneOf"] = statesList
habStateSchema = self.spec.components.schemas["HabState"]
habStateSchema["oneOf"] = statesList

self.spec.components.schemas["GroupKeyState"]["properties"]["mhab"] = {
"$ref": "#/components/schemas/Identifier"
"$ref": "#/components/schemas/HabState"
}
self.spec.components.schemas["Tier"] = enumSchemaFromNamedtuple(
coring.Tiers, description="Tier of key material"
Expand Down
2 changes: 1 addition & 1 deletion tests/app/test_specing.py

Large diffs are not rendered by default.