Skip to content

Commit

Permalink
support json_name defined in a proto file
Browse files Browse the repository at this point in the history
  • Loading branch information
Yo-mah-Ya committed Oct 9, 2023
1 parent 1283602 commit eba3fde
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ function generateInterfaceDeclaration(
const info = sourceInfo.lookup(Fields.message.field, index);
maybeAddComment(info, chunks, fieldDesc.options?.deprecated);

const name = maybeSnakeToCamel(fieldDesc.name, options);
const name = maybeSnakeToCamel(options.useJsonName ? fieldDesc.jsonName : fieldDesc.name, options);
const isOptional = isOptionalProperty(fieldDesc, messageDesc.options, options);
const type = toTypeName(ctx, messageDesc, fieldDesc, isOptional);
chunks.push(code`${maybeReadonly(options)}${name}${isOptional ? "?" : ""}: ${type}, `);
Expand Down
2 changes: 2 additions & 0 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export type Options = {
useAsyncIterable: boolean;
unknownFields: boolean;
usePrototypeForDefaults: boolean;
useJsonName: boolean;
useJsonWireFormat: boolean;
useNumericEnumForJson: boolean;
initializeFieldsAsUndefined: boolean;
Expand Down Expand Up @@ -128,6 +129,7 @@ export function defaultOptions(): Options {
useAsyncIterable: false,
unknownFields: false,
usePrototypeForDefaults: false,
useJsonName: false,
useJsonWireFormat: false,
useNumericEnumForJson: false,
initializeFieldsAsUndefined: true,
Expand Down
1 change: 1 addition & 0 deletions tests/options-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ describe("options", () => {
"useAsyncIterable": false,
"useDate": "timestamp",
"useExactTypes": true,
"useJsonName": false,
"useJsonWireFormat": false,
"useMapType": false,
"useMongoObjectId": false,
Expand Down

0 comments on commit eba3fde

Please sign in to comment.