Skip to content

Commit

Permalink
Fix descriptions of array items in generated models (#534)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarshalX authored Jan 26, 2025
1 parent b89c77e commit c5d8f95
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 11 deletions.
4 changes: 2 additions & 2 deletions packages/atproto_client/models/app/bsky/graph/defs.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ class Relationship(base.ModelBase):

did: string_formats.Did #: Did.
followed_by: t.Optional[string_formats.AtUri] = (
None #: if the actor is followed by this DID, contains the AT-URI of the follow record.
None #: If the actor is followed by this DID, contains the AT-URI of the follow record.
)
following: t.Optional[string_formats.AtUri] = (
None #: if the actor follows this DID, this is the AT-URI of the follow record.
None #: If the actor follows this DID, this is the AT-URI of the follow record.
)

py_type: t.Literal['app.bsky.graph.defs#relationship'] = Field(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,19 @@ class Params(base.ParamsModelBase):
cursor: t.Optional[str] = None #: Cursor.
limit: t.Optional[int] = Field(default=50, ge=1, le=100) #: Limit.
priority: t.Optional[bool] = None #: Priority.
reasons: t.Optional[t.List[str]] = None #: Notification reasons to include in response.
reasons: t.Optional[t.List[str]] = (
None #: Notification reasons to include in response. A reason that matches the reason property of #notification.
)
seen_at: t.Optional[string_formats.DateTime] = None #: Seen at.


class ParamsDict(t.TypedDict):
cursor: te.NotRequired[t.Optional[str]] #: Cursor.
limit: te.NotRequired[t.Optional[int]] #: Limit.
priority: te.NotRequired[t.Optional[bool]] #: Priority.
reasons: te.NotRequired[t.Optional[t.List[str]]] #: Notification reasons to include in response.
reasons: te.NotRequired[
t.Optional[t.List[str]]
] #: Notification reasons to include in response. A reason that matches the reason property of #notification.
seen_at: te.NotRequired[t.Optional[string_formats.DateTime]] #: Seen at.


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ class ParamsDict(t.TypedDict):
class Commit(base.ModelBase):
"""Definition model for :obj:`com.atproto.sync.subscribeRepos`. Represents an update of repository state. Note that empty commits are allowed, which include no repo data changes, but an update to rev and signature."""

blobs: t.List['CIDType'] #: Blobs.
blobs: t.List['CIDType'] #: Blobs. List of new blobs (by CID) referenced by records in this commit.
blocks: t.Union[str, bytes] #: CAR file containing relevant blocks, as a diff since the previous repo state.
commit: 'CIDType' #: Repo commit object CID.
ops: t.List['models.ComAtprotoSyncSubscribeRepos.RepoOp'] = Field(max_length=200) #: Ops.
ops: t.List['models.ComAtprotoSyncSubscribeRepos.RepoOp'] = Field(
max_length=200
) #: Ops. List of repo mutation operations in this commit (eg, records created, updated, or deleted).
rebase: bool #: DEPRECATED -- unused.
repo: string_formats.Did #: The repo this event comes from.
rev: str #: The rev of the emitted commit. Note that this information is also in the commit object included in blocks, unless this is a tooBig event.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ class Params(base.ParamsModelBase):
False #: If true, events on all record types (posts, lists, profile etc.) or records from given 'collections' param, owned by the did are returned.
)
limit: t.Optional[int] = Field(default=50, ge=1, le=100) #: Limit.
policies: t.Optional[t.List[str]] = None #: Policies.
policies: t.Optional[t.List[str]] = (
None #: Policies. If specified, only events where the action policies match any of the given policies are returned.
)
removed_labels: t.Optional[t.List[str]] = (
None #: If specified, only events where all of these labels were removed are returned.
)
Expand Down Expand Up @@ -87,7 +89,9 @@ class ParamsDict(t.TypedDict):
t.Optional[bool]
] #: If true, events on all record types (posts, lists, profile etc.) or records from given 'collections' param, owned by the did are returned.
limit: te.NotRequired[t.Optional[int]] #: Limit.
policies: te.NotRequired[t.Optional[t.List[str]]] #: Policies.
policies: te.NotRequired[
t.Optional[t.List[str]]
] #: Policies. If specified, only events where the action policies match any of the given policies are returned.
removed_labels: te.NotRequired[
t.Optional[t.List[str]]
] #: If specified, only events where all of these labels were removed are returned.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ class Params(base.ParamsModelBase):
subject_type: t.Optional[t.Union[t.Literal['account'], t.Literal['record'], str]] = (
None #: If specified, subjects of the given type (account or record) will be returned. When this is set to 'account' the 'collections' parameter will be ignored. When includeAllUserRecords or subject is set, this will be ignored.
)
tags: t.Optional[t.List[str]] = Field(default=None, max_length=25) #: Tags.
tags: t.Optional[t.List[str]] = Field(
default=None, max_length=25
) #: Tags. Items in this array are applied with OR filters. To apply AND filter, put all tags in the same string and separate using && characters.
takendown: t.Optional[bool] = None #: Get subjects that were taken down.


Expand Down Expand Up @@ -171,7 +173,9 @@ class ParamsDict(t.TypedDict):
subject_type: te.NotRequired[
t.Optional[t.Union[t.Literal['account'], t.Literal['record'], str]]
] #: If specified, subjects of the given type (account or record) will be returned. When this is set to 'account' the 'collections' parameter will be ignored. When includeAllUserRecords or subject is set, this will be ignored.
tags: te.NotRequired[t.Optional[t.List[str]]] #: Tags.
tags: te.NotRequired[
t.Optional[t.List[str]]
] #: Tags. Items in this array are applied with OR filters. To apply AND filter, put all tags in the same string and separate using && characters.
takendown: te.NotRequired[t.Optional[bool]] #: Get subjects that were taken down.


Expand Down
7 changes: 6 additions & 1 deletion packages/atproto_codegen/models/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from atproto_codegen.utils import (
_resolve_nsid_ref,
append_code,
capitalize_first_symbol,
convert_camel_case_to_snake_case,
format_code,
gen_description_by_camel_case_name,
Expand Down Expand Up @@ -371,10 +372,14 @@ def _add_dot_to_end_if_not_exist(description: str) -> str:
def _get_field_docstring(
field_name: str, field_type: t.Union[models.LexPrimitive, models.LexArray, models.LexBlob]
) -> str:
field_desc = field_type.description
field_desc = capitalize_first_symbol(field_type.description)
if field_desc is None:
field_desc = gen_description_by_camel_case_name(field_name)

if isinstance(field_type, models.LexArray) and field_type.items.description:
items_desc = capitalize_first_symbol(field_type.items.description)
field_desc = f'{_add_dot_to_end_if_not_exist(field_desc)} {items_desc}'

return _add_dot_to_end_if_not_exist(field_desc)


Expand Down

0 comments on commit c5d8f95

Please sign in to comment.