我正在运行以下命令,以从openapi生成器(v6.0.1 -稳定)生成一个自动生成的api。
openapi-generator-cli generate -i app.json -g typescript -o src/main/apijson文件是有效的。我运行openapi-generator-cli validate -i app.json以确保它的安全。
该命令成功执行,但当我试图根据自动生成的文档使用其中一个api端点时,我看到我应该使用的API的导入语句/初始配置缺少关键信息:
import { } from '';
import * as fs from 'fs';
const configuration = .createConfiguration();
const apiInstance = new .AuthApi(configuration);查看Datadog的node.js api客户端,我认为它应该如下所示
import { client, v1 } from '@datadog/datadog-api-client';
const configuration = client.createConfiguration();
const apiInstance = new v1.MonitorsApi(configuration);我缺少什么让生成器也不给我的api正确的导入?
编辑:示例json文件:
{
"openapi": "3.0.2",
"info": {
"title": "NinjaAPI",
"version": "1.0.0",
"description": ""
},
"paths": {
"/api/auth/cli/pickup/{pickup_key}/": {
"get": {
"operationId": "users_api_cli_pickup",
"summary": "Cli Pickup",
"parameters": [
{
"in": "path",
"name": "pickup_key",
"schema": {
"title": "Pickup Key",
"type": "string",
"format": "uuid"
},
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/PickupResponse"
}
}
}
}
},
"tags": [
"auth"
]
}
}
},
"components": {
"schemas": {
"PickupResponse": {
"title": "PickupResponse",
"type": "object",
"properties": {
"success": {
"title": "Success",
"type": "boolean"
},
"jwt": {
"title": "Jwt",
"type": "string"
}
},
"required": [
"success"
]
}
},
"securitySchemes": {
"UserJWTBearerAuth": {
"type": "http",
"scheme": "bearer"
}
}
}
}发布于 2022-09-22 14:09:11
看起来openapi生成器需要为文档文件设置moduleName和projectName,以便包含正确的代码。
它们可以通过配置文件(例如config.json)进行设置:
{
"moduleName": "NinjaAPI",
"projectName": "@ninja/api-client"
}并传递给openapi生成器:
openapi-generator-cli generate -i app.json -g typescript -o src/main/api -c config.json
https://stackoverflow.com/questions/73213069
复制相似问题