Skip to content

Commit

Permalink
Merge master into bot/bump-@asyncapi/raml-dt-schema-parser-4.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
asyncapi-bot-eve authored Aug 7, 2023
2 parents 01875fd + ea309cd commit 4b2a682
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/generators/php/renderers/EnumRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import { PhpOptions } from '../PhpGenerator';
*/
export class EnumRenderer extends PhpRenderer<ConstrainedEnumModel> {
async defaultSelf(): Promise<string> {
const content = [await this.renderItems()];
const content = [
await this.renderItems(),
await this.runAdditionalContentPreset()
];
return `enum ${this.model.name}
{
${this.indent(this.renderBlock(content, 2))}
Expand Down
26 changes: 26 additions & 0 deletions test/generators/php/PhpGenerator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,32 @@ describe('PhpGenerator', () => {
expect(models).toHaveLength(1);
expect(models[0].result).toMatchSnapshot();
});

test('should render `enum` with presets applied', async () => {
const doc = {
$id: 'Things',
enum: ['A', 'B', 'C']
};

generator = new PhpGenerator({
presets: [
{
enum: {
self({ content }) {
return `${content}// self content`;
},
additionalContent({ content }) {
return `${content}// additional content`;
}
}
}
]
});

const models = await generator.generate(doc);
expect(models).toHaveLength(1);
expect(models[0].result).toMatchSnapshot();
});
});
describe('Class', () => {
test('should not render reserved keyword', async () => {
Expand Down
12 changes: 12 additions & 0 deletions test/generators/php/__snapshots__/PhpGenerator.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,18 @@ exports[`PhpGenerator Enum should render \`enum\` with mixed types (union type)
"
`;
exports[`PhpGenerator Enum should render \`enum\` with presets applied 1`] = `
"enum Things
{
case A;
case B;
case C;
// additional content
}
// self content"
`;
exports[`PhpGenerator Enum should render enums with translated special characters 1`] = `
"enum States
{
Expand Down

0 comments on commit 4b2a682

Please sign in to comment.