Code Monkey home page Code Monkey logo

Comments (4)

raphael avatar raphael commented on September 26, 2024

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.

seapike avatar seapike commented on September 26, 2024

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.

raphael avatar raphael commented on September 26, 2024

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.

github-actions avatar github-actions commented on September 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.