Comments (7)
Its also not understood, why simplified Union serialization (as a string value in case of void tag) is not really used (even in deserializers) in generated SDK code.
And also, its quite confusing of how to use such simplified serialization, in case of a Union inside Union.
from stone.
The .tag
properties become nested under the appropriate field names. For example, given the following spec:
union U
var1 V
union V
varA
Serializing U
outputs:
{
".tag": "var1",
"var1: {
".tag": "varA"
}
}
The compact union serialization format isn't understood by our client SDKs in any language besides Python because Dropbox server always sends down the more general form. That's done because we see the compact form as beneficial for writing requests by hand in a terminal, rather than for programmatic ease.
Why do we support it in Python? Because Dropbox's API servers are written in Python and the deserializers needs to support the compact form for incoming client requests: https://github.com/dropbox/stone/blob/master/stone/backends/python_rsrc/stone_serializers.py#L642
Ideally, all of our deserializers would support the compact form, but I suspect that will only happen once we/someone requires the use of a target language other than Python on their server-side.
from stone.
Are you sure? It seems to me that .Net SDK serializes your example as:
{
".tag": "var1",
".tag": "varA"
}
I didn't run the code, but I reviewed it. I'll check it more...
However, anyway, do unions has to inline struct fields or this is also only a compact format; for example, whether this:
union U
var1 V
struct V
x integer
y integer
have to be serialized to this:
{
".tag": "var1",
"x": 7,
"y": 9
}
or general form is also valid:
{
".tag": "var1",
"var1: {
"x": 7,
"y": 9
}
}
from stone.
I'm certain that's our intended behavior. @qimingyuan can verify the .NET SDK.
Unions have to inline struct fields, there's no compact/general form distinction.
from stone.
Ok, but what about structs with subtypes? To inline their fields inside a union still two ".tag" properties are required...
from stone.
Structs with subtypes cannot be inlined. Instead, the serialization looks just like the first nested union example I provided. Let me know if you want an example.
from stone.
By the way, thanks for the feedback. I've updated our documentation to be more explicit: https://github.com/dropbox/stone/blob/master/docs/json_serializer.rst#union
Feel free to re-open if you have further questions.
from stone.
Related Issues (20)
- Stone CLI and importing custom helpers HOT 4
- Generic types
- `python_type_stubs` generator incorrectly puts imports at bottom of file, not top
- Dependent routes/data structures?
- Generated .pyi files reference 'long', which is not Python 3 compatible
- Properties are not always optional HOT 2
- Pypi HOT 5
- Does Boolean data type interpret integer values? HOT 1
- mypy errors as of 2e04e96 HOT 1
- Which OSs are supported? HOT 18
- Do tests require pytest <5 or <7? HOT 2
- Examples should be runnable and actually run by CI HOT 2
- 3.2.1: test suite warnings HOT 2
- Missing requirements.txt HOT 8
- Python 3.11 support HOT 6
- Please use int and float instead of numbers.Integral/Real HOT 9
- Stone should generate `#type` declarations for generated Python code HOT 2
- python_type_stubs generator should output _validator and route objects.
- lowerCamelCase field names for python_types?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from stone.