Coder Social home page Coder Social logo

Comments (6)

raphael avatar raphael commented on June 5, 2024 1

This seems to be a bug in the OpenAPI generation, the newInstance operation should use the type Instance and not InstanceWithCookies.

from goa.

zig avatar zig commented on June 5, 2024 1

Thanks for the fix and explanations :)

from goa.

zig avatar zig commented on June 5, 2024

I also notice that returned (set) cookies are not documented in the openapi.

Maybe what we would need in this case, instead of defining (extend) a new type with cookies, which is a bit weird (and define a new type name), would be to be able to define Result as the combination of several things, in this case it would be 'Instance' + the cookie. It would kind of merge all these in an anonymous type.

But right now if I try to do this :

	Method("newInstance2", func() {
		Result(Instance, func() {
			Attribute("cookie", String)
		})
		HTTP(func() {
			POST("/instance2")
			Response(StatusOK, func() {
				Cookie("cookie")
				CookieMaxAge(3600 * 24 * 365)
				CookieSecure()
				CookieHTTPOnly()
				CookiePath("/")
			})
		})
	})

I get this error : [design/test.go:45] can't define child attribute "cookie" on attribute of type Instance *expr.UserTypeExpr in attribute

from goa.

raphael avatar raphael commented on June 5, 2024

Yeah the above isn't valid DSL. Extend should work and would be the proper way to do what you want. For now though you could use your own function that defines the same attributes in two different types and add an additional cookie attribute to the InstanceWithCookies type.

from goa.

zig avatar zig commented on June 5, 2024

The example I provided also has in comment the method you suggest where I use a function instead of Extend, but this leads to the same bug, where only InstanceWithCookies is defined in the openapi.

from goa.

raphael avatar raphael commented on June 5, 2024

Thanks for the repro, this is fixed in #3379, a few things to note though:

  1. The fact that only one type is being generated is correct and by design. That is because the shape of the response bodies for both API endpoints are actually the exact same and Goa ensures that it won't create arbitrary schemas for types that are structurally identical. Meta("openapi:typename") can be used to override the name generated in the OpenAPI specification (Goa will use the name of the first type from which the body is derived by default).
  2. The OpenAPI specification does not define a discrete attribute for cookies in responses (it does for cookies in requests). Instead official examples add the "Set-Coookie" header so this is what the PR linked above does.

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.