Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LexiconUnknownUnion fails to account for fully unknown/arbitrary values #39

Open
luciascarlet opened this issue Mar 7, 2024 · 0 comments

Comments

@luciascarlet
Copy link

luciascarlet commented Mar 7, 2024

The ATProto documentation states that an unknown type in a lexicon has no type-specific fields and can be anything:

unknown#

Indicates than any data could appear at this location, with no specific validation. Note that the data must still be valid under the data model: it can't contain unsupported things like floats.

No type-specific fields.

This library uses a LexiconUnknownUnion union distinguishing between a set of known structs and relying on a $type field as a coding key. This does not, however, work if there is no $type field present in the response at all, as with didDoc in the output of createSession for example. Attempting to decode such a response causes a DecodingError.

It appears that this is incorrect behaviour, as no type validation is stated to be needed for an unknown type at all. These should be decoded differently in a manner that can represent any arbitrary JSON objects, for example using JSONSerialization to output an array. Unfortunately that produces a dynamic Any type, so I really am not sure how you might go about integrating this into a system built around Codable, which is very strict about types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant