有沒有什麼方法可以根據元數據/ Swagger自動生成ServiceStack javascript(無腳本)客戶端?將它與webpack整合起來會很好。從ServiceStack api元數據/ swagger生成javascript客戶端
我不確定是否可以用swagger-js-codegen做到這一點(這個包從swagger規範文件中生成nodejs或angularjs類)。
實際上,swagger插件不共享服務來訪問swagger.json以獲取完整的模式(模式被分離)。是否有任何解決方法使用JavaScript的swagger codegen?
通過訪問http://localhost:12116/resources你可以得到
{"swaggerVersion":"1.2","apis":[{"path":"/resource/assignroles"},{"path":"/resource/auth"},{"path":"/resource/authenticate"},{"path":"/resource/criteria"},{"path":"/resource/import"},{"path":"/resource/tenders"},{"path":"/resource/unassignroles"}],"apiVersion":"1.0","basePath":"http://localhost:12116","info":{"title":"App"}}
,並使用http://localhost:12116/resource/import
{"swaggerVersion":"1.2","apiVersion":"1.0","basePath":"http://localhost:12116","resourcePath":"/import","apis":[{"path":"/import/stats","operations":[{"method":"GET","nickname":"BrowseImportStats","parameters":[],"errorResponses":[]}]},{"path":"/import/tenders/changes/apply","operations":[{"method":"GET","nickname":"ApplyChanges","parameters":[],"errorResponses":[]},{"method":"POST","nickname":"ApplyChanges","parameters":[{"paramType":"body","name":"body","required":false,"allowMultiple":false,"type":"ApplyChanges"}],"errorResponses":[]},{"method":"PUT","nickname":"ApplyChanges","parameters":[{"paramType":"body","name":"body","required":false,"allowMultiple":false,"type":"ApplyChanges"}],"errorResponses":[]},{"method":"DELETE","nickname":"ApplyChanges","parameters":[],"errorResponses":[]}]},{"path":"/import/tenders/sync","description":"summary","operations":[{"method":"GET","summary":"summary","nickname":"ImportTenders","parameters":[],"errorResponses":[]}]}],"models":{"ImportTenders":{"id":"ImportTenders","properties":{}},"ApplyChanges":{"id":"ApplyChanges","properties":{}},"BrowseImportStats":{"id":"BrowseImportStats","description":"BrowseImportStats","properties":{}}}}
更新2016年11月26日 我能夠生成文檔
C:\git\testapp>java -jar swagger-codegen-cli-2.2.1.jar generate -i http
://localhost:12116/resources -l javascript -o ./node_modules/testapp_api --additi
onal-properties emitJSDoc=false,usePromises=true
你可以檢查我的更新有關用於Servicestack插件?它生成分裂的模式,我不確定這是由Swagger Codegen支持的。 – marcinn
是的,Swagger Codegen的最新版本對分離模式有更好的支持(FYI。Swagger Codegen利用Swagger分析器來解析Swagger文件) –
thnx獲取信息。我現在在webpack中使用該API存在問題。我在導入模塊錯誤時遇到錯誤./~/testapp_api/src/index.js 模塊未找到:錯誤:無法解析'C:\ git \ testapp \ n中的'ApiClient' ode_modules \ testapp_api \ src' @ ./~/testapp_api/src/index.js 28:4-705 – marcinn