<p>I'm a big fan of code generation for tedious, boilerplate stuff. I stumbled across go-swagger the other day and it looks pretty nice. The code it generates is as clean as generated code can be, and there are enough hooks to let you inject functionality where you need (e.g. go middleware).</p>
<p>I'm looking at using <a href="https://github.com/swagger-api/swagger-codegen" rel="nofollow">swagger-codegen</a> for generating a client side API with TypeScript, getting me to a full cycle of:</p>
<ul>
<li>develop API model in swagger</li>
<li>generate go models + plumbing</li>
<li>generate TypeScript models + plumbing</li>
<li>type check everything!</li>
</ul>
<hr/>**评论:**<br/><br/>Jamo008: <pre><p>Link to <a href="https://github.com/go-swagger/go-swagger" rel="nofollow">go-swagger</a></p></pre>vburenin: <pre><p>Link to the go-swagger picture <a href="https://twitter.com/asteroix/status/723728506648059904" rel="nofollow">https://twitter.com/asteroix/status/723728506648059904</a> and the other <a href="https://twitter.com/asteroix/status/726160120766320641" rel="nofollow">https://twitter.com/asteroix/status/726160120766320641</a></p></pre>kpurdon: <pre><blockquote>
<p>as clean as generated code can be</p>
</blockquote>
<p>Ya ... never clean enough for me to go with generated code. I always find myself doing 10x more work to get generated code to work the way I want (and to test it properly).</p>
<p>I tried go-swagger for awhile (though was going the other way comments>spec) and ended up bailing on it in favor of writing my own code and specs. However we (work) are using swagger-codegen to generate typescript for the FE that we additionally use to validate that the spec/BE are in sync. Pretty neat to have a FE-SPEC-BE validation tree that we can use. Keeps us all in sync!</p>
<p>You may be interested in <a href="https://github.com/swagger-api/swagger-codegen/pull/2763" rel="nofollow">https://github.com/swagger-api/swagger-codegen/pull/2763</a> which a co-worker recently got merged into codegen.</p></pre>3264128256: <pre><p>You might also want to give <a href="http://goa.design" rel="nofollow">goa</a> a try.</p></pre>chub79: <pre><p>I haven't looked at goa nor go-swagger but, how do they generate meaningful tests from a swagger spec?</p></pre>casualjim: <pre><p>go-swagger doesn't at this point, but nothing is stopping you from adding it. The reason it doesn't is that I wanted to make the model generation support all of the swagger first before I got into doing more features. I felt that stability was more important than features.
That being said it has pretty much stabilized now, so it could be added by a motivated party.</p></pre>chub79: <pre><p>Okay. I was curious because I'm facing that very question :)</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传