diff --git a/src/google-types.ts b/src/google-types.ts index 25cc9e7..db8b6e8 100644 --- a/src/google-types.ts +++ b/src/google-types.ts @@ -134,6 +134,16 @@ export class GoogleTypes { 'HALF', 'YEAR', ], + 'x-enum-mapping': { + CALENDAR_PERIOD_UNSPECIFIED: 0, + DAY: 1, + WEEK: 2, + FORTNIGHT: 3, + MONTH: 4, + QUARTER: 5, + HALF: 6, + YEAR: 7, + }, description: 'A `CalendarPeriod` represents the abstract concept of a time period that has a canonical start. Grammatically, "the start of the current `CalendarPeriod`." All calendar times begin at midnight UTC.', }, @@ -498,6 +508,21 @@ export class GoogleTypes { 'NOVEMBER', 'DECEMBER', ], + 'x-enum-mapping': { + MONTH_UNSPECIFIED: 0, + JANUARY: 1, + FEBRUARY: 2, + MARCH: 3, + APRIL: 4, + MAY: 5, + JUNE: 6, + JULY: 7, + AUGUST: 8, + SEPTEMBER: 9, + OCTOBER: 10, + NOVEMBER: 11, + DECEMBER: 12, + }, description: 'Represents a month in the Gregorian calendar.', }, 'google.type.PostalAddress': { diff --git a/src/protoj2jsonSchema.ts b/src/protoj2jsonSchema.ts index 6ea7131..81b8da3 100644 --- a/src/protoj2jsonSchema.ts +++ b/src/protoj2jsonSchema.ts @@ -286,10 +286,16 @@ class Proto2JsonSchema { private compileEnum( enumType: InternalEnum ): SpecTypesV2.AsyncAPISchemaDefinition { + const enumMapping: {[key: string]: number} = {}; + for (const enumKey of Object.keys(enumType.values)) { + enumMapping[enumKey] = enumType.values[enumKey].value; + } + return { title: enumType.name, type: 'string', enum: Object.keys(enumType.values), + 'x-enum-mapping': enumMapping }; } diff --git a/test/documents/realworld.train_run.proto.result.json b/test/documents/realworld.train_run.proto.result.json index fb18a26..a73f01a 100644 --- a/test/documents/realworld.train_run.proto.result.json +++ b/test/documents/realworld.train_run.proto.result.json @@ -216,6 +216,13 @@ "AFDZ_MANUELL_ERGAENZT", "AFDZ_OK" ], + "x-enum-mapping": { + "AFDZ_UNSPECIFIED": 0, + "AFDZ_KEINE_TRAKTION": 1, + "AFDZ_ANHAENGELAST_FEHLT": 2, + "AFDZ_MANUELL_ERGAENZT": 3, + "AFDZ_OK": 4 + }, }, "anzahl_loks": { @@ -621,6 +628,13 @@ "FS_NORMAL", "FS_FAHRZEIT_VERTEILEN" ], + "x-enum-mapping": { + "FS_UNSPECIFIED": 0, + "FS_SCHNELL": 1, + "FS_HALTEN": 2, + "FS_NORMAL": 3, + "FS_FAHRZEIT_VERTEILEN": 4 + }, } }, @@ -680,6 +694,13 @@ "TST_D", "TST_N" ], + "x-enum-mapping": { + "TST_UNSPECIFIED": 0, + "TST_R": 1, + "TST_A": 2, + "TST_D": 3, + "TST_N": 4 + }, } }, @@ -714,6 +735,13 @@ "AOSS_OBSERVE_EARLIEST_TIMES", "AOSS_ONLY_WHEN_ROUTE_IS_SET" ], + "x-enum-mapping": { + "AOSS_UNSPECIFIED": 0, + "AOSS_ALLOWED": 1, + "AOSS_PROHIBITED": 2, + "AOSS_OBSERVE_EARLIEST_TIMES": 4, + "AOSS_ONLY_WHEN_ROUTE_IS_SET": 5 + }, } }, @@ -791,6 +819,13 @@ "AFDZ_MANUELL_ERGAENZT", "AFDZ_OK" ], + "x-enum-mapping": { + "AFDZ_UNSPECIFIED": 0, + "AFDZ_KEINE_TRAKTION": 1, + "AFDZ_ANHAENGELAST_FEHLT": 2, + "AFDZ_MANUELL_ERGAENZT": 3, + "AFDZ_OK": 4 + }, }, "anzahl_loks": { @@ -1043,6 +1078,13 @@ "AFDZ_MANUELL_ERGAENZT", "AFDZ_OK" ], + "x-enum-mapping": { + "AFDZ_UNSPECIFIED": 0, + "AFDZ_KEINE_TRAKTION": 1, + "AFDZ_ANHAENGELAST_FEHLT": 2, + "AFDZ_MANUELL_ERGAENZT": 3, + "AFDZ_OK": 4 + }, }, "anzahl_loks": { @@ -1448,6 +1490,13 @@ "FS_NORMAL", "FS_FAHRZEIT_VERTEILEN" ], + "x-enum-mapping": { + "FS_UNSPECIFIED": 0, + "FS_SCHNELL": 1, + "FS_HALTEN": 2, + "FS_NORMAL": 3, + "FS_FAHRZEIT_VERTEILEN": 4 + }, } }, @@ -1507,6 +1556,13 @@ "TST_D", "TST_N" ], + "x-enum-mapping": { + "TST_UNSPECIFIED": 0, + "TST_R": 1, + "TST_A": 2, + "TST_D": 3, + "TST_N": 4 + }, } }, @@ -1541,6 +1597,13 @@ "AOSS_OBSERVE_EARLIEST_TIMES", "AOSS_ONLY_WHEN_ROUTE_IS_SET" ], + "x-enum-mapping": { + "AOSS_UNSPECIFIED": 0, + "AOSS_ALLOWED": 1, + "AOSS_PROHIBITED": 2, + "AOSS_OBSERVE_EARLIEST_TIMES": 4, + "AOSS_ONLY_WHEN_ROUTE_IS_SET": 5 + }, } }, @@ -1618,6 +1681,13 @@ "AFDZ_MANUELL_ERGAENZT", "AFDZ_OK" ], + "x-enum-mapping": { + "AFDZ_UNSPECIFIED": 0, + "AFDZ_KEINE_TRAKTION": 1, + "AFDZ_ANHAENGELAST_FEHLT": 2, + "AFDZ_MANUELL_ERGAENZT": 3, + "AFDZ_OK": 4 + }, }, "anzahl_loks": {