question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Option "useProtoFieldName" to generate interfaces in snake_case

See original GitHub issue

I use protobuf-ts in my project like this Example proto

syntax = "proto3";

message MyMessage {
  int32 foo_bar = 1;
}

Output interface after compilation

export interface MyMessage {
    fooBar: number;
    /* I want to have
      foo_bar: number;
   */
}

Usage

const message = MyMessage.fromBinary(buffer, { readUnknownField: false });
const result =  MyMessage.toJson(message, {
    emitDefaultValues: false,
    useProtoFieldName: true,
});

result looks like { foo_bar: 1 }. But I can’t cast it const result: MyMessage because MyMessage has fields in camelCase.

Are you agree to add such option to ts_opt? If yes I can help you and create PR for that 😃 Thanks!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jcreadycommented, Mar 25, 2022

This has been addressed in https://github.com/timostamm/protobuf-ts/pull/250 which was released in v2.3.0.

0reactions
doochikcommented, Aug 3, 2021

Thanks, I’ll take a look to use ts-proto to generate interfaces

Read more comments on GitHub >

github_iconTop Results From Across the Web

protoc-gen-go: support using proto field names as JSON names
An implementation may provide an option to use proto field name as the JSON name instead. Proto3 JSON parsers are required to accept...
Read more >
Language Guide (proto3) | Protocol Buffers - Google Developers
This guide describes how to use the protocol buffer language to structure your protocol buffer data, including .proto file syntax and how to...
Read more >
Is it possible to use mapped types in Typescript to change a ...
I am trying to figure out a way to use mapped types to change a types keys from camel to snake case. For...
Read more >
StyleGuide - TypeScript Deep Dive - Gitbook
Interface. Use PascalCase for name. Reason: Similar to class. Use camelCase for members. Reason: Similar to class. Don't prefix with I.
Read more >
Snake case to Camel case: bring peace between Rails and ...
Developing software by conventions produce easy-to-read code and ... models/active.interface';; import { camelCase, snakeCase } from ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found