这是 swagger ui 的配置 /schema/config.yaml
Invite:
type: object
x-mongo-schema: true
properties:
uid:
type: string
description: The unique identifier of the invite.
sequence:
type: number
description: The sequence number of the cal invite.
Invites:
type: object
x-mongo-schema: true
properties:
participant:
$ref: "#/components/schemas/Invite"
researcher:
$ref: "#/components/schemas/Invite"
用于生成样板代码的 Mustache 配置 /cgen/generator_custom_templates/config.yaml
templateDir: ./cgen/generator_custom_templates/templates
files:
.env.example: {}
authz.mustache:
folder: controllers
destinationFilename: authz.ts
templateType: SupportingFiles
这是我运行来生成样板代码的脚本 脚本:
java -jar ./cgen/openapi-generator-cli.jar generate -g nodejs-express-server -i ./schemas/index.yaml -c ./cgen/generator_custom_templates/config.yaml -o ./generated_code --skip-operation-example
生成的文件:invites.ts
import mongoose from 'mongoose';
import { inviteSchema, IInvite } from '#models/invite'; // Need to fix this Duplicate import
import { inviteSchema, IInvite } from '#models/invite'; // Need to fix this Duplicate import
export interface IInvites {
participant?: IInvite,
researcher?: IInvite,
};
export const invitesSchema = new mongoose.Schema<IInvites>(
{
participant: { type: inviteSchema, },
researcher: { type: inviteSchema, },
},
{ _id: false }
);
我解决了它,虽然它是一个黑客。嘿,目前有一个关于此重复导入问题的公开讨论。我所做的是在生成的代码文件(即invites.ts 文件)中运行 eslint,以使用“eslint --fix”命令删除重复导入