Skip to content

Commit

Permalink
Merge branch 'v3' into dependabot/go_modules/golang.org/x/tools-0.22.0
Browse files Browse the repository at this point in the history
  • Loading branch information
raphael committed Jun 15, 2024
2 parents 36653c8 + c87dff9 commit 836ad0b
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/report-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
ref: ${{ github.event.workflow_run.head_sha }}

- name: Download test coverage
uses: dawidd6/action-download-artifact@v3
uses: dawidd6/action-download-artifact@v5
with:
workflow: test.yml
name: coverage
Expand Down
2 changes: 1 addition & 1 deletion codegen/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func BuildSubcommandData(svcName string, m *service.MethodData, buildFunction *B
description = fmt.Sprintf("Make request to the %q endpoint", m.Name)
}

if buildFunction == nil && len(flags) > 0 {
if m.Payload != "" && buildFunction == nil && len(flags) > 0 {
// No build function, just convert the arg to the body type
var convPre, convSuff string
target := "data"
Expand Down
2 changes: 0 additions & 2 deletions grpc/codegen/client_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,6 @@ func ParseEndpoint(cc *grpc.ClientConn, opts ...grpc.CallOption) (goa.Endpoint,
data, err = {{ $pkgName}}.{{ .BuildFunction.Name }}({{ range .BuildFunction.ActualParams }}*{{ . }}Flag, {{ end }})
{{- else if .Conversion }}
{{ .Conversion }}
{{- else }}
data = nil
{{- end }}
{{- end }}
}
Expand Down
1 change: 1 addition & 0 deletions http/codegen/client_cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func TestClientCLIFiles(t *testing.T) {
{"simple-parse", testdata.MultiSimpleDSL, testdata.MultiSimpleParseCode, 0, 3},
{"multi-parse", testdata.MultiDSL, testdata.MultiParseCode, 0, 3},
{"multi-required-payload", testdata.MultiRequiredPayloadDSL, testdata.MultiRequiredPayloadParseCode, 0, 3},
{"skip-request-body-encode-decode", testdata.SkipRequestBodyEncodeDecodeDSL, testdata.SkipRequestBodyEncodeDecodeParseCode, 0, 3},
{"streaming-parse", testdata.StreamingMultipleServicesDSL, testdata.StreamingParseCode, 0, 3},
{"simple-build", testdata.MultiSimpleDSL, testdata.MultiSimpleBuildCode, 1, 1},
{"multi-build", testdata.MultiDSL, testdata.MultiBuildCode, 1, 1},
Expand Down
2 changes: 0 additions & 2 deletions http/codegen/templates/parse_endpoint.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ func ParseEndpoint(
data, err = {{ $pkgName}}.{{ .BuildFunction.Name }}({{ range .BuildFunction.ActualParams }}*{{ . }}Flag, {{ end }})
{{- else if .Conversion }}
{{ .Conversion }}
{{- else }}
data = nil
{{- end }}
{{- if .StreamFlag }}
{{- if .BuildFunction }}
Expand Down
104 changes: 94 additions & 10 deletions http/codegen/testdata/parse_endpoint_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,20 +109,16 @@ func ParseEndpoint(
switch epn {
case "method-service-no-payload11":
endpoint = c.MethodServiceNoPayload11()
data = nil
case "method-service-no-payload12":
endpoint = c.MethodServiceNoPayload12()
data = nil
}
case "service-multi-no-payload2":
c := servicemultinopayload2c.NewClient(scheme, host, doer, enc, dec, restore)
switch epn {
case "method-service-no-payload21":
endpoint = c.MethodServiceNoPayload21()
data = nil
case "method-service-no-payload22":
endpoint = c.MethodServiceNoPayload22()
data = nil
}
}
}
Expand Down Expand Up @@ -245,7 +241,6 @@ func ParseEndpoint(
switch epn {
case "method-multi-simple-no-payload":
endpoint = c.MethodMultiSimpleNoPayload()
data = nil
case "method-multi-simple-payload":
endpoint = c.MethodMultiSimplePayload()
data, err = servicemultisimple1c.BuildMethodMultiSimplePayloadPayload(*serviceMultiSimple1MethodMultiSimplePayloadBodyFlag)
Expand All @@ -255,7 +250,6 @@ func ParseEndpoint(
switch epn {
case "method-multi-simple-no-payload":
endpoint = c.MethodMultiSimpleNoPayload()
data = nil
case "method-multi-simple-payload":
endpoint = c.MethodMultiSimplePayload()
data, err = servicemultisimple2c.BuildMethodMultiSimplePayloadPayload(*serviceMultiSimple2MethodMultiSimplePayloadBodyFlag)
Expand Down Expand Up @@ -382,7 +376,6 @@ func ParseEndpoint(
switch epn {
case "method-multi-required-no-payload":
endpoint = c.MethodMultiRequiredNoPayload()
data = nil
case "method-multi-required-payload":
endpoint = c.MethodMultiRequiredPayload()
data, err = servicemultirequired2c.BuildMethodMultiRequiredPayloadPayload(*serviceMultiRequired2MethodMultiRequiredPayloadAFlag)
Expand All @@ -397,6 +390,100 @@ func ParseEndpoint(
}
`

var SkipRequestBodyEncodeDecodeParseCode = `// ParseEndpoint returns the endpoint and payload as specified on the command
// line.
func ParseEndpoint(
scheme, host string,
doer goahttp.Doer,
enc func(*http.Request) goahttp.Encoder,
dec func(*http.Response) goahttp.Decoder,
restore bool,
) (goa.Endpoint, any, error) {
var (
skipRequestBodyEncodeDecodeFlags = flag.NewFlagSet("skip-request-body-encode-decode", flag.ContinueOnError)
skipRequestBodyEncodeDecodeSkipRequestBodyEncodeDecodeMethodFlags = flag.NewFlagSet("skip-request-body-encode-decode-method", flag.ExitOnError)
skipRequestBodyEncodeDecodeSkipRequestBodyEncodeDecodeMethodStreamFlag = skipRequestBodyEncodeDecodeSkipRequestBodyEncodeDecodeMethodFlags.String("stream", "REQUIRED", "path to file containing the streamed request body")
)
skipRequestBodyEncodeDecodeFlags.Usage = skipRequestBodyEncodeDecodeUsage
skipRequestBodyEncodeDecodeSkipRequestBodyEncodeDecodeMethodFlags.Usage = skipRequestBodyEncodeDecodeSkipRequestBodyEncodeDecodeMethodUsage
if err := flag.CommandLine.Parse(os.Args[1:]); err != nil {
return nil, nil, err
}
if flag.NArg() < 2 { // two non flag args are required: SERVICE and ENDPOINT (aka COMMAND)
return nil, nil, fmt.Errorf("not enough arguments")
}
var (
svcn string
svcf *flag.FlagSet
)
{
svcn = flag.Arg(0)
switch svcn {
case "skip-request-body-encode-decode":
svcf = skipRequestBodyEncodeDecodeFlags
default:
return nil, nil, fmt.Errorf("unknown service %q", svcn)
}
}
if err := svcf.Parse(flag.Args()[1:]); err != nil {
return nil, nil, err
}
var (
epn string
epf *flag.FlagSet
)
{
epn = svcf.Arg(0)
switch svcn {
case "skip-request-body-encode-decode":
switch epn {
case "skip-request-body-encode-decode-method":
epf = skipRequestBodyEncodeDecodeSkipRequestBodyEncodeDecodeMethodFlags
}
}
}
if epf == nil {
return nil, nil, fmt.Errorf("unknown %q endpoint %q", svcn, epn)
}
// Parse endpoint flags if any
if svcf.NArg() > 1 {
if err := epf.Parse(svcf.Args()[1:]); err != nil {
return nil, nil, err
}
}
var (
data any
endpoint goa.Endpoint
err error
)
{
switch svcn {
case "skip-request-body-encode-decode":
c := skiprequestbodyencodedecodec.NewClient(scheme, host, doer, enc, dec, restore)
switch epn {
case "skip-request-body-encode-decode-method":
endpoint = c.SkipRequestBodyEncodeDecodeMethod()
data, err = skiprequestbodyencodedecodec.BuildSkipRequestBodyEncodeDecodeMethodStreamPayload(*skipRequestBodyEncodeDecodeSkipRequestBodyEncodeDecodeMethodStreamFlag)
}
}
}
if err != nil {
return nil, nil, err
}
return endpoint, data, nil
}
`

var MultiParseCode = `// ParseEndpoint returns the endpoint and payload as specified on the command
// line.
func ParseEndpoint(
Expand Down Expand Up @@ -487,7 +574,6 @@ func ParseEndpoint(
switch epn {
case "method-multi-no-payload":
endpoint = c.MethodMultiNoPayload()
data = nil
case "method-multi-payload":
endpoint = c.MethodMultiPayload()
data, err = servicemultic.BuildMethodMultiPayloadPayload(*serviceMultiMethodMultiPayloadBodyFlag, *serviceMultiMethodMultiPayloadBFlag, *serviceMultiMethodMultiPayloadAFlag)
Expand Down Expand Up @@ -602,14 +688,12 @@ func ParseEndpoint(
switch epn {
case "method":
endpoint = c.Method()
data = nil
}
case "streaming-service-b":
c := streamingservicebc.NewClient(scheme, host, doer, enc, dec, restore, dialer, streamingServiceBConfigurer)
switch epn {
case "method":
endpoint = c.Method()
data = nil
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions http/codegen/testdata/streaming_dsls.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ var MixedEndpointsDSL = func() {
})
}

var SkipRequestBodyEncodeDecodeDSL = func() {
Service("SkipRequestBodyEncodeDecode", func() {
Method("SkipRequestBodyEncodeDecodeMethod", func() {
HTTP(func() {
POST("/")
SkipRequestBodyEncodeDecode()
Response(StatusOK)
})
})
})
}

var StreamingMultipleServicesDSL = func() {
Service("StreamingServiceA", func() {
Method("Method", func() {
Expand Down

0 comments on commit 836ad0b

Please sign in to comment.