OpenAPITools / OpenAPITools/openapi-generator
[Typescript-axios generator]: How to generate only TypeScript types without API controllers/resources?
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
I'm trying to generate only TypeScript types from my Swagger json specification using @openapitools/openapi-generator-cli, but it keeps generating API controllers and resources even though I've disabled API generation in the configuration.
Here's my current openapitools.json configuration:
{
"$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json",
"spaces": 2,
"generator-cli": {
"version": "6.2.1",
"generators": {
"typescript-types": {
"generatorName": "typescript-axios",
"output": "src/generated",
"glob": "swagger.json",
"skipValidateSpec": true,
"additionalProperties": {
"modelPropertyNaming": "original",
"typescriptThreePlus": true,
"enumNameSuffix": "",
"enumPropertyNaming": "UPPERCASE",
"withInterfaces": true,
"generateModels": true,
"supportsES6": true,
"modelPackage": "models",
"stringEnums": true,
"withoutRuntimeChecks": true,
"generateApis": false,
"generateApiDocumentation": false,
"generateApiTests": false,
"generateModelDocumentation": false,
"generateModelTests": false
}
}
}
}
}
Despite setting generateApis: false and other API-related flags to false, I'm still getting generated code like:
/**
* ProductResourcesAPIsApi - axios parameter creator
* @export
*/
export const ProductResourcesAPIsApiAxiosParamCreator = function (configuration?: Configuration) {
return {
/**
* @summary Get Product Details by ID
* @param {string} xRequestID Request Tracking ID
* @param {string} id
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof ProductResourcesAPIsApi
*/
public productControllerGetDetails(xRequestID
I only want the TypeScript types/interfaces to be generated, without any API-related code. How can I achieve this?
Things I've already tried:
- Setting all API-related generation flags to false
- Using withSeparateModelsAndApi: true
- Setting apiPackage: ""
Is there a way to generate only types using openapi-generator, or should I switch to a different tool? If so, what alternatives would you recommend?
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 openapitools.json and the typescript-axios generator configuration, focusing on how generateApis and the other API-related flags are handled. Use swagger.json as the input and compare the generated output with the requested types/interfaces-only result. Done means API controllers/resources and related API code are absent while TypeScript models and interfaces remain.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100