Comments (4)
I'd love to find a better way of encoding unions in a way that works across various encoders that is compatible with clients generated from the OpenAPI specification!
As mentioned in the linked issue the current implementation adds a Type
field as the union discriminator and the value itself is serialized as a JSON string in the Value
field. The client code that a oneof
OpenAPI spec would generate would not be compatible with what the current implementation does. So it's not just a matter of updating the generated spec but it's mostly about how Goa handles union types in HTTP. We'd need to come up with a scheme that makes it possible for server and client Go methods to understand the underlying type so responses and/or requests can be unmarshaled correctly.
from goa.
So it's not just a matter of updating the generated spec but it's mostly about how Goa handles union types in HTTP.
Isn't this actually exactly what's required? It seems that all that's missing is the enumeration of the acceptable types for the serialised value - the response is JSON anyway, what is stopping the generated spec from including the type references?
anyOf:
- $ref: '#/components/schemas/Dog'
- $ref: '#/components/schemas/Cat'
from goa.
Not quite, the spec above would describe a response like:
{ "pet1": { "bark": true }, "pet2": { "claws": 20 } }
where Goa generates:
{ "pet1": { "Type": "dog", "Value": "{\"bark\":true}" }, "pet2": { "Type": "cat", "Value": "{\"claws\":20}" } }
Also to make the problem clearer the spec above would also work for:
<data><pet1><bark>true</bark></pet1><pet2><claws>20</claws></pet2></data>
where Goa generates:
<data><pet1><Type>dog</Type><Value>{"bark":true}</Value></pet1><pet2><Type>cat</Type><Value>{"claws":20}</Value></pet2></data>
from goa.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
from goa.
Related Issues (20)
- Using Param() to map path parameters to attributes results in a runtime error HOT 5
- Panic in main HOT 2
- Goa panics when query params have unclosed square brackets HOT 2
- Goa panics when a user provides an explicit `null` where a `Map` is expected, if it's a nested structure HOT 2
- Middleware in design? HOT 6
- Goa generating uncompilable code while using views on types that contain OneOf union type
- Goa generating invalid code when OneOf types is a user defined type
- Example generation failed in the latest version HOT 3
- Generated server code parses query parameters repeatedly HOT 1
- Getting the Raw Query? HOT 1
- Allow implementing `io.WriterTo` for `SkipResponseBodyEncodeDecode` responses. HOT 3
- generated cli: expected type, found newline HOT 4
- `CollectionOf()` + `View()` leading to unknown attribute errors. HOT 4
- `Return(ResultType)` + `Meta("struct:pkg:path", "path")` leads to some broken return types in gen/**/service.go. HOT 1
- go.mod shouldn't specify Go patch version HOT 1
- OpenAPI schema for `Any` DSL type assumes nested serialization into a string HOT 7
- Unexpected OpenAPI specification when using CollectionOf() + View() in Attribute HOT 1
- Incorrect code generation for GoaErrorName() function for custom error types HOT 6
- goa gen example issue HOT 1
- SIGSEGV when generating design HOT 2
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 goa.