Comments (4)
Can you provide a complete design that reproduces this problem? thank you!
from goa.
Surely.
Here's a full design.go
// This file contains descriptions of services and their methods.
// The methods should be implemented in, e.g. /example/api/service.go.
// Goa will roll up these descriptions and generate the corresponding endpoints.
package design
import (
. "goa.design/goa/v3/dsl"
cors "goa.design/plugins/v3/cors/dsl"
)
var _ = API("my-service", func() {
Title("my-service")
Description("Services related ")
Server("my-service", func() {
Host("localhost", func() {
URI("http://localhost:8000")
})
})
})
var DeduplicateSpecification = Type("DeduplicateSpecification", func() {
Attribute("matching_names", Boolean, func() {
Description("de-duplicate when names match")
Default(true)
})
})
// Service describes a service
var _ = Service("my-service", func() {
cors.Origin("*", func() {
cors.Headers("*")
cors.Methods("GET", "POST", "PUT", "DELETE", "PATCH")
cors.Credentials()
})
Error("not_found")
Method("create-dispatch", func() {
Payload(func() {
Attribute("name", String, "submission name")
Attribute("deduplicate_by", DeduplicateSpecification, "how to deduplicate the submission")
})
Result(func() {
Attribute("id", Int, "the submission id")
Required("id")
})
HTTP(func() {
POST("/submit")
Response(StatusOK)
})
})
})
And here's the resulting generated gen/client/encode_decode.go
with the problematic function:
func marshalMyserviceDeduplicateSpecificationToDeduplicateSpecificationRequestBody(v *myservice.DeduplicateSpecification) *DeduplicateSpecificationRequestBody {
if v == nil {
return nil
}
res := &DeduplicateSpecificationRequestBody{
MatchingNames: v.MatchingNames,
}
{
var zero bool
if res.MatchingNames == zero {
res.MatchingNames = true // this clobbers user-set false values
}
}
return res
}
from goa.
Taking another look at this issue. I wonder what the behavior should be. The idea is that attributes that have a default value should generate fields that are not pointers, so in this case a field that is a bool
and not a *bool
. This would be difficult to change because it would break a lot of existing code. So I see two options:
- Make it an error to specify a default value for boolean fields. The
goa gen
tool would fail in this case with an error message indicating that boolean attributes can't have default values. The obvious drawback is that this behavior would preclude the generation of the transport level code that initializes the field to the default value if missing from the marshaled data. - Change the code generation so that the marshaling side (client for payloads, server for results) does not check or set the default value - only the unmarshaling side would if the field is missing from the marshaled data.
Option 2 is probably preferable?
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)
- Incomplete definition of OpenAPI response with SkipResponseBodyEncodeDecode
- Pull #3250 changed the openapi returned types for views, breaking anything code-gen'ing types for each schema.
- Slack join link doesn't work. HOT 4
- HTTP cache - RFC compliant with many other features HOT 7
- Something strange happens when using ArrayOf(Int32) with MultipartRequest() in a Method()! HOT 2
- `Maximum()`; `validation_error` points to variable name instead of attribute in response
- generated service code is incorrect when using `Meta` for shared types HOT 2
- Request - additional command line parameters for generation HOT 4
- OpenAPI response may be declared even though Result is empty HOT 1
- Duplicate function definitions to implement the OneOf in generated code when using Meta("struct:pkg:path", "types")
- Is there a nice way to integrate AsyncAPI into goa? HOT 1
- Make endpointsData public HOT 1
- goa gen only generating structs for types contained in service definitions HOT 1
- Upstream indirect dependency change HOT 6
- Meta openapi:example still generates example if put at API level HOT 1
- Goa not enforcing required attribute HOT 6
- grpc stream.Recv doesn't decode errors HOT 1
- can't use SkipRequestBodyEncodeDecode and authentification at the same time HOT 7
- Shouldn't body be closed by decoder ? HOT 12
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.