Skip to content

Commit

Permalink
update test and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslagoni committed Mar 4, 2024
1 parent 0765db2 commit 2558388
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
8 changes: 8 additions & 0 deletions docs/presets.md
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,14 @@ This preset is a generator for the meta model `ConstrainedObjectModel` and [can
|---|---|---|
| `field` | A method to extend rendered given field. | `field` object as a [`ConstrainedObjectPropertyModel`](./internal-model.md#the-constrained-meta-model) instance. |

#### **Enum**

This preset is a generator for the meta model `ConstrainedEnumModel` and [can be accessed through the `model` argument](#presets-shape).

| Method | Description | Additional arguments |
|---|---|---|
| `item` | A method to extend rendering the enum items. | `item` object as a [`ConstrainedEnumValueModel`](./internal-model.md#the-constrained-meta-model) instance. `index` as `number`, the current enum item being rendered. |

### C#

#### **Class**
Expand Down
6 changes: 2 additions & 4 deletions examples/generate-go-enums/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ var ValuesToCities = map[any]Cities{
CitiesValues[CitiesLondon]: CitiesLondon,
CitiesValues[CitiesRome]: CitiesRome,
CitiesValues[CitiesBrussels]: CitiesBrussels,
}
",
}",
]
`;

Expand Down Expand Up @@ -65,7 +64,6 @@ var ValuesToOptions = map[any]Options{
OptionsValues[OptionsNumber_213]: OptionsNumber_213,
OptionsValues[OptionsTrue]: OptionsTrue,
OptionsValues[OptionsRun]: OptionsRun,
}
",
}",
]
`;
10 changes: 6 additions & 4 deletions src/generators/go/renderers/EnumRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ export class EnumRenderer extends GoRenderer<ConstrainedEnumModel> {
return `${this.model.name}Values[${value.key}]: ${value.key},`;
});
const additionalContent = await this.runAdditionalContentPreset();
const renderedAdditionalContent = additionalContent
? `
${this.indent(additionalContent)}
`
: '';
const values = this.model.values
.map((value) => {
return value.value;
Expand All @@ -46,10 +51,7 @@ func (op ${this.model.name}) Value() any {
var ${this.model.name}Values = []any{${values}}
var ValuesTo${this.model.name} = map[any]${this.model.name}{
${this.indent(this.renderBlock(valuesToEnumMap))}
}
${this.indent(additionalContent)}
`;
}${renderedAdditionalContent}`;
}

async renderItems(): Promise<string> {
Expand Down
6 changes: 2 additions & 4 deletions test/generators/go/__snapshots__/GoGenerator.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ var ValuesToThings = map[any]Things{
ThingsValues[ThingsReservedNumber_1]: ThingsReservedNumber_1,
ThingsValues[ThingsFalse]: ThingsFalse,
ThingsValues[ThingsCurlyleftQuotationTestQuotationColonQuotationTestQuotationCurlyright]: ThingsCurlyleftQuotationTestQuotationColonQuotationTestQuotationCurlyright,
}
"
}"
`;

exports[`GoGenerator should render \`struct\` type 1`] = `
Expand Down Expand Up @@ -131,8 +130,7 @@ var ValuesToCustomEnum = map[any]CustomEnum{
CustomEnumValues[CustomEnumTexas]: CustomEnumTexas,
CustomEnumValues[CustomEnumAlabama]: CustomEnumAlabama,
CustomEnumValues[CustomEnumCalifornia]: CustomEnumCalifornia,
}
"
}"
`;

exports[`GoGenerator should work custom preset for \`struct\` type 1`] = `
Expand Down

0 comments on commit 2558388

Please sign in to comment.