盛湘堂海参蔡 發表於 2026-2-13 16:34:00

【EASY-YAPI】IDEA插件easyyapi如何解决公共前缀问题

<h1 id="问题">问题</h1>
<p>在某些Yapi上的项目,有些设置了项目级别前缀,有些没有设置,有些接口文档是手写的,有些是自动生成的。</p>
<p>因此会出现URL前缀重叠、缺失等问题,需要<strong>截断</strong>,或者<strong>追加</strong></p>
<h1 id="解决">解决</h1>
<h2 id="如何移除前缀">如何移除前缀</h2>
<pre><code>if(it.containingClass().name().contains("com.slankka.coder.OpenapiController")){
api.setPath(tool.removePrefix(api.path(),"/api/vmi"))
}
</code></pre>
<h2 id="如何添加前缀">如何添加前缀</h2>
<pre><code>if(it.containingClass().name().contains("com.slankka.coder.browser.PageController")){
api.setPath("/prefix" + api.path())
}
</code></pre>
<h2 id="如何配置">如何配置</h2>
<p>新建一份.yapi.config 文件到项目根目录</p>
<pre><code>export.after=groovy:```
//上述代码
```
</code></pre>
<h2 id="it-内嵌变量">it 内嵌变量</h2>
<p>对于class(类)、method(方法/API)、field(字段/属性)、param(参数)都支持如下方法</p>
<table>
<thead>
<tr>
<th>方法</th>
<th>返回值</th>
<th>描述</th>
<th>示例</th>
</tr>
</thead>
<tbody>
<tr>
<td>name()</td>
<td>string</td>
<td>名称</td>
<td>it.name()</td>
</tr>
</tbody>
</table>
<p>method(方法/API)</p>
<table>
<thead>
<tr>
<th>方法</th>
<th>返回值</th>
<th>描述</th>
<th>示例</th>
</tr>
</thead>
<tbody>
<tr>
<td>containingClass()</td>
<td>class</td>
<td>方法所属类</td>
<td>it.containingClass()</td>
</tr>
</tbody>
</table>
<h1 id="参考链接">参考链接</h1>
<p>文章内容同步发表到:</p>
<ul>
<li>【Tutorial】教程-项目前缀和后缀微调以及一对多项目</li>
</ul>
<p>参考链接</p>
<ul>
<li>easyyapi | it内嵌对象-文档</li>
<li>tool | 内嵌对象-文档</li>
</ul>
<p>本文使用了Markdown转义才得以呈现上述代码块</p>
<ul>
<li>如何在Markdown中转义backtick符号</li>
</ul><br><br>
来源:https://www.cnblogs.com/slankka/p/19612672
頁: [1]
查看完整版本: 【EASY-YAPI】IDEA插件easyyapi如何解决公共前缀问题