From c4f2a30a1baea45074a9d3b7cc6316e95c2287e8 Mon Sep 17 00:00:00 2001 From: ericwenn Date: Fri, 23 Apr 2021 23:07:29 +0200 Subject: [PATCH] fix: ignore path covered fields in query parameters This was the intention in the first place, but was forgotten about. --- .../einride/example/freight/v1/index.ts | 30 ------------------- .../einride/example/syntax/v1/index.ts | 6 ---- internal/plugin/servicegen.go | 6 ++++ 3 files changed, 6 insertions(+), 36 deletions(-) diff --git a/examples/proto/gen/typescript/einride/example/freight/v1/index.ts b/examples/proto/gen/typescript/einride/example/freight/v1/index.ts index 568a228..0c8e254 100644 --- a/examples/proto/gen/typescript/einride/example/freight/v1/index.ts +++ b/examples/proto/gen/typescript/einride/example/freight/v1/index.ts @@ -373,9 +373,6 @@ export function createFreightServiceClient( const path = `v1/${request.name}`; // eslint-disable-line quotes const body = null; const queryParams: string[] = []; - if (request.name) { - queryParams.push("name=" + encodeURIComponent(request.name.toString())); - } let uri = path; if (queryParams.length > 0) { uri += "?" + queryParams.join("&"); @@ -447,9 +444,6 @@ export function createFreightServiceClient( const path = `v1/${request.name}`; // eslint-disable-line quotes const body = null; const queryParams: string[] = []; - if (request.name) { - queryParams.push("name=" + encodeURIComponent(request.name.toString())); - } let uri = path; if (queryParams.length > 0) { uri += "?" + queryParams.join("&"); @@ -467,9 +461,6 @@ export function createFreightServiceClient( const path = `v1/${request.name}`; // eslint-disable-line quotes const body = null; const queryParams: string[] = []; - if (request.name) { - queryParams.push("name=" + encodeURIComponent(request.name.toString())); - } let uri = path; if (queryParams.length > 0) { uri += "?" + queryParams.join("&"); @@ -487,9 +478,6 @@ export function createFreightServiceClient( const path = `v1/${request.parent}/sites`; // eslint-disable-line quotes const body = null; const queryParams: string[] = []; - if (request.parent) { - queryParams.push("parent=" + encodeURIComponent(request.parent.toString())); - } if (request.pageSize) { queryParams.push("pageSize=" + encodeURIComponent(request.pageSize.toString())); } @@ -513,9 +501,6 @@ export function createFreightServiceClient( const path = `v1/${request.parent}/sites`; // eslint-disable-line quotes const body = JSON.stringify(request?.site ?? {}); const queryParams: string[] = []; - if (request.parent) { - queryParams.push("parent=" + encodeURIComponent(request.parent.toString())); - } let uri = path; if (queryParams.length > 0) { uri += "?" + queryParams.join("&"); @@ -553,9 +538,6 @@ export function createFreightServiceClient( const path = `v1/${request.name}`; // eslint-disable-line quotes const body = null; const queryParams: string[] = []; - if (request.name) { - queryParams.push("name=" + encodeURIComponent(request.name.toString())); - } let uri = path; if (queryParams.length > 0) { uri += "?" + queryParams.join("&"); @@ -573,9 +555,6 @@ export function createFreightServiceClient( const path = `v1/${request.name}`; // eslint-disable-line quotes const body = null; const queryParams: string[] = []; - if (request.name) { - queryParams.push("name=" + encodeURIComponent(request.name.toString())); - } let uri = path; if (queryParams.length > 0) { uri += "?" + queryParams.join("&"); @@ -593,9 +572,6 @@ export function createFreightServiceClient( const path = `v1/${request.parent}/shipments`; // eslint-disable-line quotes const body = null; const queryParams: string[] = []; - if (request.parent) { - queryParams.push("parent=" + encodeURIComponent(request.parent.toString())); - } if (request.pageSize) { queryParams.push("pageSize=" + encodeURIComponent(request.pageSize.toString())); } @@ -619,9 +595,6 @@ export function createFreightServiceClient( const path = `v1/${request.parent}/shipments`; // eslint-disable-line quotes const body = JSON.stringify(request?.shipment ?? {}); const queryParams: string[] = []; - if (request.parent) { - queryParams.push("parent=" + encodeURIComponent(request.parent.toString())); - } let uri = path; if (queryParams.length > 0) { uri += "?" + queryParams.join("&"); @@ -659,9 +632,6 @@ export function createFreightServiceClient( const path = `v1/${request.name}`; // eslint-disable-line quotes const body = null; const queryParams: string[] = []; - if (request.name) { - queryParams.push("name=" + encodeURIComponent(request.name.toString())); - } let uri = path; if (queryParams.length > 0) { uri += "?" + queryParams.join("&"); diff --git a/examples/proto/gen/typescript/einride/example/syntax/v1/index.ts b/examples/proto/gen/typescript/einride/example/syntax/v1/index.ts index a01818c..0cc7f77 100644 --- a/examples/proto/gen/typescript/einride/example/syntax/v1/index.ts +++ b/examples/proto/gen/typescript/einride/example/syntax/v1/index.ts @@ -358,9 +358,6 @@ export function createSyntaxServiceClient( const path = `v1/${request.string}:path`; // eslint-disable-line quotes const body = null; const queryParams: string[] = []; - if (request.string) { - queryParams.push("string=" + encodeURIComponent(request.string.toString())); - } if (request.repeatedString) { for (const x of request.repeatedString) { queryParams.push("repeatedString=" + encodeURIComponent(x.toString())); @@ -386,9 +383,6 @@ export function createSyntaxServiceClient( const path = `v1/${request.string}:pathBody`; // eslint-disable-line quotes const body = JSON.stringify(request?.nested ?? {}); const queryParams: string[] = []; - if (request.string) { - queryParams.push("string=" + encodeURIComponent(request.string.toString())); - } if (request.repeatedString) { for (const x of request.repeatedString) { queryParams.push("repeatedString=" + encodeURIComponent(x.toString())); diff --git a/internal/plugin/servicegen.go b/internal/plugin/servicegen.go index f7ad00e..7936cb1 100644 --- a/internal/plugin/servicegen.go +++ b/internal/plugin/servicegen.go @@ -183,6 +183,12 @@ func (s serviceGenerator) generateMethodQuery( } // fields covered by path pathCovered := make(map[string]struct{}) + for _, segment := range rule.Template.Segments { + if segment.Kind != httprule.SegmentKindVariable { + continue + } + pathCovered[segment.Variable.FieldPath.String()] = struct{}{} + } walkJSONLeafFields(input, func(path httprule.FieldPath, field protoreflect.FieldDescriptor) { if _, ok := pathCovered[path.String()]; ok { return