Skip to content

Commit

Permalink
fix: ignore path covered fields in query parameters
Browse files Browse the repository at this point in the history
This was the intention in the first place, but was forgotten about.
  • Loading branch information
ericwenn committed Apr 24, 2021
1 parent b5384b4 commit c4f2a30
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 36 deletions.
30 changes: 0 additions & 30 deletions examples/proto/gen/typescript/einride/example/freight/v1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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("&");
Expand Down Expand Up @@ -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("&");
Expand All @@ -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("&");
Expand All @@ -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()));
}
Expand All @@ -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("&");
Expand Down Expand Up @@ -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("&");
Expand All @@ -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("&");
Expand All @@ -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()));
}
Expand All @@ -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("&");
Expand Down Expand Up @@ -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("&");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand All @@ -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()));
Expand Down
6 changes: 6 additions & 0 deletions internal/plugin/servicegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c4f2a30

Please sign in to comment.