christianhelle / refitter

Refit Client API Generator for OpenAPI
https://refitter.github.io
MIT License
157 stars 36 forks source link

Support generating immutable records #407

Closed ebarnard closed 2 days ago

ebarnard commented 3 days ago

Is your feature request related to a problem? Please describe. I'd like to be able to generate immutable records.

NJsonSchema supports this by setting GenerateNativeRecords = true and ClassStyle = CSharpClassStyle.Record in CSharpGeneratorSettings.

Describe the solution you'd like Add support for setting ClassStyle in codeGeneratorSettings in the .refitter file.

Describe alternatives you've considered N/A

Additional context N/A

christianhelle commented 3 days ago

@ebarnard Thanks for taking the time to suggest this. If NJsonSchema already supports it then it should be trivial to implement. You're more than welcome to try to give it a go and I'll make sure your pull request gets merged in, or I could do it myself.

I'm a bit occupied with work and family these days so it might take a few days for me to build this

christianhelle commented 3 days ago

@all-contributors please add @ebarnard for ideas

allcontributors[bot] commented 3 days ago

@christianhelle

I've put up a pull request to add @ebarnard! :tada:

christianhelle commented 3 days ago

@ebarnard I got a bit curious so I looked into this in detail and apparently, Refitter already supports GenerateNativeRecords but cannot generate immutable records. The immutable records are only generated when ClassStyle is set to Record, as you mentioned

This feature will only take a couple of minutes to implement so I'll just do it myself

christianhelle commented 3 days ago

@ebarnard In the pull request #409, I set the ClassStyle to either POCO or Record depending on whether GenerateNativeRecords is set. I'll expose the ClassStyle in the .refitter settings file later as that involves a bit more work

ebarnard commented 3 days ago

That looks perfect, thank you for looking at this so quickly.

christianhelle commented 3 days ago

That looks perfect, thank you for looking at this so quickly.

@ebarnard you're welcome

christianhelle commented 2 days ago

@ebarnard this feature is now released as v1.1.1