swagger-api / swagger-api/swagger-codegen
[CSharp] Custom generator with typed type
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
Hi, I've got a question about the command which generate the csharp code.
I have an object which my API return :
PagnatedResult <myObjectToReturn>
So the swagger generator create an object called "PaginatedResultMyObjectToReturn".
But I need to have after the generation my typed object "PagnatedResult"
I was using AutoRest before and that was the config I used
directive:
from: code-model-v1
where: $..[?(@.name.raw.startsWith('PaginatedResult_'))]
transform: >-
$.name.raw = $.name.raw.replace('PaginatedResult_', 'PaginatedResult<').replace('_', '>'); /* C#-ify generic name /
$.name.fixed = true; / prevent sanitizing that name /
$.extensions = { "x-ms-external": true }; / don't generate the class definitions */
I've tryed something like that :
java -jar swagger-codegen2.jar generate --type-mappings PaginatedResult*= PaginatedResult<*> -i http://myUrl.com/swagger.json -l csharp -o ./client/
Swagger-codegen version
Swagger codegen version 2.4.9
Command line used for generation
java -jar swagger-codegen2.jar generate --type-mappings PaginatedResult=PaginatedResult<> -i http://myUrl.com/swagger.json -l csharp -o ./client/
java -jar swagger-codegen2.jar generate --type-mappings PaginatedResult*= PaginatedResult<*> -i http://myUrl.com/swagger.json -l csharp -o ./client/
Suggest a fix/enhancement
I'm pretty sure it's doable but it's just that it's not very documented and I don't figure out how to accomplish this.
EDIT
I found a solution with this command which work
java -jar swagger-codegen2.jar generate --type-mappings PaginatedResultNotificationResult=PaginatedResult^<NotificationResult^> -i http://myURL.com/swagger.json -l csharp -o ./client/
But I still need to have a way to generalize because I don't want to specify all objects in my command line...
Thanks
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the generate command's --type-mappings handling for the C# generator in swagger-codegen 2.4.9, comparing the explicit PaginatedResultNotificationResult mapping with the requested wildcard behavior. Done means a generalized mapping produces typed PaginatedResult objects without listing every generated result type; the issue names no files or tests to run.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100