Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect order of nested messages generator #18

Open
qwetexac opened this issue Aug 2, 2024 · 0 comments
Open

Incorrect order of nested messages generator #18

qwetexac opened this issue Aug 2, 2024 · 0 comments

Comments

@qwetexac
Copy link

qwetexac commented Aug 2, 2024

Description

Hey, while generating types from nested fields, the generator first looks for already defined top-level fields instead of looking for fields inside the parent. See example below:

message Metrics {
  uint64 foo = 1;
}

message Parent {
  message Metrics {
    uint64 bar = 1;
  }

  repeated Metrics items = 1;
}

Expected result

export function Metrics() {
    return [
        [1, "foo", "uint64", 1],
    ];
}

export function Parent_Metrics() {
    return [
        [1, "bar", "uint64", 1],
    ];
}

export function Parent() {
    return [
        [1, "items", ["repeated", Parent_Metrics], 1],
    ];
}

Actual result

export function Metrics() {
    return [
        [1, "foo", "uint64", 1],
    ];
}

export function Parent_Metrics() { // totally unused
    return [
        [1, "bar", "uint64", 1],
    ];
}

export function Parent() {
    return [
        [1, "items", ["repeated", Metrics], 1],
    ];
}

Soluiton

export const pathField = (field: string, base: string, out: MakeOuts, parent?: string) => {
  // ...rest code

+ const fieldPath = joinPath(field);
+ const fullPath = joinPath(base, field);

- if (out.names.has(field)) {
-   return joinPath(field);
- }

- return joinPath(base, field);

+ if (out.names.has(fullPath)) {
+   return fullPath;
+ }

+ if (out.names.has(fieldPath)) {
+   return fieldPath;
+ }

+ return fullPath;
};

This will tell the generator to search in nested messages before getting messages at the level above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant