<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Code_generation on omegaatt</title>
    <link>https://www.omegaatt.com/tags/code_generation/</link>
    <description>Recent content in Code_generation on omegaatt</description>
    <generator>Hugo -- 0.164.0</generator>
    <language>zh-TW</language>
    <managingEditor>raiven.kao@gmail.com (Raiven Kao)</managingEditor>
    <webMaster>raiven.kao@gmail.com (Raiven Kao)</webMaster>
    <copyright>Raiven Kao 2020 - 2026</copyright>
    <lastBuildDate>Tue, 11 Aug 2026 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://www.omegaatt.com/tags/code_generation/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Spec-First API：用 codegen 約束 LLM 與人類的 drift</title>
      <link>https://www.omegaatt.com/blogs/develop/2026/spec_first_api_against_drift/</link>
      <pubDate>Tue, 11 Aug 2026 00:00:00 +0000</pubDate><author>raiven.kao@gmail.com (Raiven Kao)</author>
      <guid>https://www.omegaatt.com/blogs/develop/2026/spec_first_api_against_drift/</guid>
      <description>&lt;h2 id=&#34;前言&#34;&gt;前言&lt;/h2&gt;
&lt;p&gt;事情是這樣開始的。&lt;/p&gt;
&lt;p&gt;我請 agent 幫忙加一個 endpoint，它三分鐘寫完，handler 乾淨、error handling 完整、unit test 也跟著補齊，&lt;code&gt;go test ./...&lt;/code&gt; 全綠。此時我想到的是，agent 真的有做完嗎？route 真的有被註冊嗎？&lt;/p&gt;
&lt;p&gt;換成三年前的我，也會漏，那要怎麼樣讓 Agent 不會漏？這個系統從一開始就沒有任何機制能發現有人漏改。以前它靠的是 reviewer 的眼力與同一批人的肌肉記憶撐著；現在把產出速度乘上十倍，這條防線就直接被沖垮了。這不是 agent 的問題，是架構債被提早引爆。&lt;/p&gt;
&lt;p&gt;這篇想記錄的，就是後來把這個服務從 code-first 遷移到 spec-first 的過程：用 OpenAPI 當單一真值來源(SSOT)，用 oapi-codegen 產生 typed interface，讓 compiler 與 CI 去做原本靠人記憶的事情。&lt;/p&gt;
&lt;h2 id=&#34;問題不是有三份檔案&#34;&gt;問題不是「有三份檔案」&lt;/h2&gt;
&lt;p&gt;遷移前，同一條 API 的定義散落在三個地方：&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-text&#34; data-lang=&#34;text&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;infra route definition     ← path / method / authorizer
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;cmd/*/main.go              ← mux.HandleFunc 手寫註冊
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Go swag comments           ← @Router / @Param / @Success
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;三份檔案本身不是問題，同一個概念散在多個檔案是常態。&lt;/p&gt;
&lt;p&gt;真正的問題是，它們彼此不知道對方存在。&lt;/p&gt;
&lt;p&gt;改 path，可能只改到 Go route，忘了 infra；改 response shape，可能只改 handler struct，忘了註解；授權設定只活在 infra 層，Go 跟 OpenAPI 都不知道有這回事。而 swaggo 的註解在 repo 裡形同空轉，它是「程式碼的產物」，而我們沒有任何機制拿它回頭驗證程式碼。&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
