swagger-codegen icon indicating copy to clipboard operation
swagger-codegen copied to clipboard

[C#] Use fully-qualified name for models

Open wing328 opened this issue 8 years ago • 5 comments

Similar to Task (System.Threading.Tasks.Task) a year ago and then Stream (System.IO.Stream), we want to use fully-qualified name for models.

Related discussion: #2589

If anyone wants to work on this, please reply to let us know.

wing328 avatar Apr 17 '16 14:04 wing328

@wing328 I seem to recall you had started work on this? Am I remembering incorrectly? If you had any work in progress, would you mind sharing it?

I think this issue could easily be fixed by an option that appends the full model namespace to client generated models. This way users who don't like fully qualified names throughout code and have no issue with collisions can continue generating as normal.

jimschubert avatar Jul 24 '16 15:07 jimschubert

@jimschubert yes it's on my plate. I was able to update model with fully-qualified names but one remaining issue I found was that the documentation looks very ugly using fully-qualified name. I'll probably go with your suggestion to use a CLI option (similar to fullJavaUtil)

wing328 avatar Jul 25 '16 13:07 wing328

I recently started using fully qualified definitions in my spec file because of some DTOs that shared class names (in different namespaces). So the definitions section of my spec file has property named ClientPortal.Api.Model.PunchReport.Contract.SchedulePunchesRow (was simply SchedulePunchesRow before).

This has resulted in a class once called SchedulePunchesRow to be named ClientPortalApiModelPunchReportContractSchedulePunchesRow. I tried using --import-mappings to effectively "bring my own model", and while the Model class no longer gets generated, the Api classes where it's used, still reference it a whole word (without the periods).

Is this task meant to resolve that or something similar? Is there another way around the problem I'm having? TIA!

langdonx avatar Nov 01 '16 14:11 langdonx

@langdonx you could try the --model-name-prefix: https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen-cli/src/main/java/io/swagger/codegen/cmd/Generate.java#L69

I don't recall exactly, but I think this doesn't do sanitization on the provided prefix.

jimschubert avatar Nov 19 '16 02:11 jimschubert

I'm having this issue with C# code generayed from Amazon SP API models. Can this be addressed? --import-mappings did not help.

smargoli2 avatar Aug 28 '22 11:08 smargoli2