Skip to content

[BUG] Passing {constraints: { additionalProperties: false }} to the CSharpGenerator's generate method still generates an AdditionalProperties property in the model file #2212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
2 tasks done
mgmccarthy opened this issue Mar 19, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@mgmccarthy
Copy link

Describe the bug.

Currently, when I generate C# models from AsyncAPI input and specific I do not want the additional AdditionalProperties property included in the generated model, it does now work:

const generator = new CSharpGenerator({ autoImplementedProperties: true });

... 

const models = await generator.generate(mappedSchema,
{
    modelName: messageName,
    constraints: { additionalProperties: false }
});

the output still contains an AdditionalProperties method (which is not in the yaml file)
public Dictionary<string, dynamic>? AdditionalProperties { get; set; }

Expected behavior

that setting additionalProperties: false does not render:
public Dictionary<string, dynamic>? AdditionalProperties { get; set; }

in the generated model file

Screenshots

Image

Image

How to Reproduce

  1. I wrote a javascript file (generate-csharp-models.js) to import my AsyncAPI file and generate C# models
  2. I ran node generate-csharp-models.js
  3. The generated model still contains the AdditionalProperties property

🖥️ Device Information [optional]

  • Operating System (OS):
  • Browser:
  • Browser Version:

👀 Have you checked for similar open issues?

  • I checked and didn't find similar issue

🏢 Have you read the Contributing Guidelines?

Are you willing to work on this issue ?

None

@mgmccarthy mgmccarthy added the bug Something isn't working label Mar 19, 2025
Copy link
Contributor

Welcome to AsyncAPI. Thanks a lot for reporting your first issue. Please check out our contributors guide and the instructions about a basic recommended setup useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

@mgmccarthy
Copy link
Author

mgmccarthy commented Mar 19, 2025

I found a workaround that seems to suppress the generation of the AdditionalProperties property in the generated model.

Right before calling generator.generate, I added this line:

mappedSchema.additionalProperties = false; and that prevented the AdditionalProperties property from being rendered to the model

so, the code that works is:

const generator = new CSharpGenerator({ autoImplementedProperties: true });

...

mappedSchema.additionalProperties = false;

const models = await generator.generate(mappedSchema,
{
    modelName: messageName,
    constraints: { additionalProperties: false }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant