<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>ja-Swagger on Junpei Kawamoto</title>
    <link>https://www.jkawamoto.info/tags/ja-swagger/</link>
    <description>Recent content in ja-Swagger on Junpei Kawamoto</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <managingEditor>junpei.kawamoto@acm.org (Junpei Kawamoto)</managingEditor>
    <webMaster>junpei.kawamoto@acm.org (Junpei Kawamoto)</webMaster>
    <copyright>&amp;copy; 2016-2017 Junpei Kawamoto</copyright>
    <lastBuildDate>Thu, 11 May 2017 00:00:00 +0000</lastBuildDate>
    
	<atom:link href="https://www.jkawamoto.info/tags/ja-swagger/index.xml" rel="self" type="application/rss+xml" />
    
    
    <item>
      <title>配列が null だと Azure サーバがエラーを返す問題</title>
      <link>https://www.jkawamoto.info/blog-ja/azure-server-returns-error-when-array-is-null/</link>
      <pubDate>Thu, 11 May 2017 00:00:00 +0000</pubDate>
      <author>junpei.kawamoto@acm.org (Junpei Kawamoto)</author>
      <guid>https://www.jkawamoto.info/blog-ja/azure-server-returns-error-when-array-is-null/</guid>
      <description>本稿は Qiita 投稿記事 のバックアップです．
 概要 Go から Microsoft Azure を利用するの方法でソースコードを生成すると， スライス型の構造体メンバに omitempty が付かず API 呼び出しがエラーになる場合があった． その原因ととりあえずの対策をまとめる．
go-swagger が生成する構造体 例えば，
$ swagger generate client \ -f https://raw.githubusercontent.com/Azure/azure-rest-api-specs/master/batch/2016-07-01.3.1/swagger/BatchService.json \ -t batch  上記のコマンドで Batch API のバインディングを作った場合， ジョブプールの追加に必要なパラメータを表す構造体として，下記のような PoolAddParameter が生成される．
type PoolAddParameter struct { // The list of application packages to be installed on each compute node in the pool. // // This property is currently not supported on pools created using // the virtualMachineConfiguration (IaaS) property.</description>
    </item>
    
    <item>
      <title>OAuthアクセストークンを使ってMicrosoft Azureにアクセスする</title>
      <link>https://www.jkawamoto.info/blog-ja/access-azure-using-oauth-tokens/</link>
      <pubDate>Wed, 10 May 2017 00:00:00 +0000</pubDate>
      <author>junpei.kawamoto@acm.org (Junpei Kawamoto)</author>
      <guid>https://www.jkawamoto.info/blog-ja/access-azure-using-oauth-tokens/</guid>
      <description>本稿は Qiita 投稿記事 のバックアップです．
 概要 
Microsoft Azureを利用するデスクトップアプリのデバイス認証にて取得したアクセストークンを， Go から Microsoft Azure を利用するにて紹介した Swagger で生成したクライアントから利用する方法． API によって微妙に関数の形が変わるため，生成されたソースコードを見ながらどこでトークンを渡せるのか調べる必要があるが，おおよそ次の二種類に分かれると思われる．
メソッドが認証情報を受け取る場合 最も簡単なのは，認証情報を受け取るタイプのメソッドが生成された場合である． 例えば，次のようにして生成できる 2016-09-01 版の Resource API
$ swagger generate client \ -f https://raw.githubusercontent.com/Azure/azure-rest-api-specs/master/arm-resources/resources/2016-09-01/swagger/resources.json \ -t resource  では，リソースグループの作成または更新を行う関数が次のように定義されている．
func (a *Client) ResourceGroupsCreateOrUpdate( params *ResourceGroupsCreateOrUpdateParams, authInfo runtime.ClientAuthInfoWriter ) (*ResourceGroupsCreateOrUpdateOK, *ResourceGroupsCreateOrUpdateCreated, error)  この runtime.ClientAuthInfoWriter型 は，go-openapi/runtime ライブラリにて
import &amp;quot;github.com/go-openapi/strfmt&amp;quot; type ClientAuthInfoWriter interface { AuthenticateRequest(ClientRequest, strfmt.Registry) error }  と定義されているのだが，go-openapi/runtime/client に OAuth アクセストークン (BearerToken) から ClientAuthInfoWriter を生成する BearerToken 関数が用意されている．</description>
    </item>
    
    <item>
      <title>Go から Microsoft Azure を利用する</title>
      <link>https://www.jkawamoto.info/blog-ja/access-azure-from-go/</link>
      <pubDate>Mon, 08 May 2017 00:00:00 +0000</pubDate>
      <author>junpei.kawamoto@acm.org (Junpei Kawamoto)</author>
      <guid>https://www.jkawamoto.info/blog-ja/access-azure-from-go/</guid>
      <description>本稿は Qiita 投稿記事 のバックアップです．
 概要 
Microsoft Azure をプログラムから利用する場合 .Net が一般的な選択肢だと思われるが， あえて Go から利用する方法について調べた．
Microsoft Azure SDK for Go &amp;ldquo;go azure&amp;rdquo; で検索すると見つかる公式の SDK が Microsoft Azure SDK for Go と Azure Storage SDK for Go である．後者は前者のうち storage に関する API だけを切り離したもので，今後は別リポジトリとして開発されるそうだ．
公式 SDK のため，基本的にはこれらを使えれば良いのだが，まだ preview 版であり未実装の API が多い．個人的には，Azure Storage SDK for Go は必要な機能は揃っていたが，それ以外は別の方法を探した方が良いと感じた．
余談だが，Microsoft Azure SDK for Go は一つの操作 Foo に対して Foo, FooPreparer, FooResponder, FooSender と４つの関数がセットで定義されているのだが，後ろの３つはパブリックにする必要はあるのだろうか？補完やドキュメント検索がごちゃごちゃするのだが・・・．
Azure REST API Specifications Azure REST API Specifications は REST API 定義書を管理している公式のリポジトリである． こちらの方は，ほぼ全ての API を網羅していると思われる． REST API 定義書さえあれば，Swagger を使って Go 用のパッケージを自動生成できる．</description>
    </item>
    
  </channel>
</rss>