2017-02-15 8 views
1

go implementation of petstore exampleの仕様ファイルを作成しようとしています。私はdoc.goを持っていたディレクトリにgo generateを試しましたが、何もしませんでした。さらに読書では、私はdoc.goGoswaggerが適切なjson仕様ファイルを作成しない

//go:generate swagger generate spec -o swagger.json

がなければならないことに気づきました。私はそれが仕様ファイルを作成することを追加しましたが、それは仕様全体を含んでいません。これは、specファイルに記載された一切のルート/パラメータ/モデルはありませんgo generate

{ 
    "consumes": [ 
    "application/json" 
    ], 
    "produces": [ 
    "application/json" 
    ], 
    "schemes": [ 
    "http", 
    "https" 
    ], 
    "swagger": "2.0", 
    "info": { 
    "description": "the purpose of this application is to provide an application\nthat is using plain go code to define an API\n\nThis should demonstrate all the possible comment annotations\nthat are available to turn go code into a fully compliant swagger 2.0 spec", 
    "title": "Petstore API.", 
    "termsOfService": "there are no TOS at this moment, use at your own risk we take no responsibility\ngo:generate swagger generate spec -o swagger.json", 
    "contact": { 
     "name": "John Doe", 
     "url": "http://john.doe.com", 
     "email": "[email protected]" 
    }, 
    "license": { 
     "name": "MIT", 
     "url": "http://opensource.org/licenses/MIT" 
    }, 
    "version": "0.0.1" 
    }, 
    "host": "localhost", 
    "basePath": "/v2", 
    "paths": {} 
} 

に作成され.jsonファイルです。これはこれがどうなるのでしょうか?これはgoswagger repoの正式な例なので、コードが間違っているとは思わない。私はそれを動作させるために何を変えるべきですか?

答えて

0

文書化したいコードには、メインパッケージからアクセス可能である必要があります。これは、メインパッケージからその使用を検出可能にする必要があることを意味します。 ある反射の手段で接続されていない稼働中のサーバーがあれば、正しい仕様が生成されます。

関連する問題