swagger-api / swagger-api/swagger-codegen
[Question] Can Swagger generate custom generic types?
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Assume we have API return model in C#
public class ApiResult<T>
{
public T Result;
public bool Success;
}
and returning ApiResult<string> object instance to client
so we have swagger generated model
ApiResult[String] {
result (string, optional),
success (boolean, optional)
}
which is incorrectly converted to typescript class using https://swagger.io/swagger-codegen/
'use strict';
import * as models from './models';
export interface ApiResultString {
result?: string;
success?: boolean;
}
Is it possible to generate output models with generics same as in input models?
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 by reviewing swagger-codegen's TypeScript model generation and the ApiResultString example described in the issue. Done means generated TypeScript models can preserve the generic ApiResult shape rather than only producing a concrete ApiResultString interface.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, typescript
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100