├── .gitignore ├── LICENSE ├── README.md ├── action └── action.go ├── example ├── clients │ ├── go │ │ ├── .gitignore │ │ ├── .swagger-codegen-ignore │ │ ├── .travis.yml │ │ ├── README.md │ │ ├── api │ │ │ └── swagger.yaml │ │ ├── api_greet.go │ │ ├── api_user_api.go │ │ ├── client.go │ │ ├── configuration.go │ │ ├── docs │ │ │ ├── GreetApi.md │ │ │ ├── LoginReq.md │ │ │ ├── RegisterReq.md │ │ │ ├── UserApiApi.md │ │ │ ├── UserInfoReply.md │ │ │ ├── UserInfoReq.md │ │ │ ├── UserSearchReply.md │ │ │ └── UserSearchReq.md │ │ ├── git_push.sh │ │ ├── model_login_req.go │ │ ├── model_register_req.go │ │ ├── model_user_info_reply.go │ │ ├── model_user_info_req.go │ │ ├── model_user_search_reply.go │ │ ├── model_user_search_req.go │ │ └── response.go │ ├── javascript │ │ ├── .swagger-codegen-ignore │ │ ├── .travis.yml │ │ ├── README.md │ │ ├── docs │ │ │ ├── GreetApi.md │ │ │ ├── LoginReq.md │ │ │ ├── RegisterReq.md │ │ │ ├── UserApiApi.md │ │ │ ├── UserInfoReply.md │ │ │ ├── UserInfoReq.md │ │ │ ├── UserSearchReply.md │ │ │ └── UserSearchReq.md │ │ ├── git_push.sh │ │ ├── mocha.opts │ │ ├── package.json │ │ ├── src │ │ │ ├── ApiClient.js │ │ │ ├── api │ │ │ │ ├── GreetApi.js │ │ │ │ └── UserApiApi.js │ │ │ ├── index.js │ │ │ └── model │ │ │ │ ├── LoginReq.js │ │ │ │ ├── RegisterReq.js │ │ │ │ ├── UserInfoReply.js │ │ │ │ ├── UserInfoReq.js │ │ │ │ ├── UserSearchReply.js │ │ │ │ └── UserSearchReq.js │ │ └── test │ │ │ ├── api │ │ │ ├── GreetApi.spec.js │ │ │ └── UserApiApi.spec.js │ │ │ ├── assert-equals.js │ │ │ └── model │ │ │ ├── LoginReq.spec.js │ │ │ ├── RegisterReq.spec.js │ │ │ ├── UserInfoReply.spec.js │ │ │ ├── UserInfoReq.spec.js │ │ │ ├── UserSearchReply.spec.js │ │ │ └── UserSearchReq.spec.js │ └── php │ │ ├── .swagger-codegen-ignore │ │ └── SwaggerClient-php │ │ ├── .php_cs │ │ ├── .travis.yml │ │ ├── README.md │ │ ├── composer.json │ │ ├── docs │ │ ├── Api │ │ │ ├── GreetApi.md │ │ │ └── UserApiApi.md │ │ └── Model │ │ │ ├── LoginReq.md │ │ │ ├── RegisterReq.md │ │ │ ├── UserInfoReply.md │ │ │ ├── UserInfoReq.md │ │ │ ├── UserSearchReply.md │ │ │ └── UserSearchReq.md │ │ ├── git_push.sh │ │ ├── lib │ │ ├── Api │ │ │ ├── GreetApi.php │ │ │ └── UserApiApi.php │ │ ├── ApiException.php │ │ ├── Configuration.php │ │ ├── HeaderSelector.php │ │ ├── Model │ │ │ ├── LoginReq.php │ │ │ ├── ModelInterface.php │ │ │ ├── RegisterReq.php │ │ │ ├── UserInfoReply.php │ │ │ ├── UserInfoReq.php │ │ │ ├── UserSearchReply.php │ │ │ └── UserSearchReq.php │ │ └── ObjectSerializer.php │ │ ├── phpunit.xml.dist │ │ └── test │ │ ├── Api │ │ ├── GreetApiTest.php │ │ └── UserApiApiTest.php │ │ └── Model │ │ ├── LoginReqTest.php │ │ ├── RegisterReqTest.php │ │ ├── UserInfoReplyTest.php │ │ ├── UserInfoReqTest.php │ │ ├── UserSearchReplyTest.php │ │ └── UserSearchReqTest.php ├── generate-client.sh ├── generate.go ├── gozero │ ├── main.go │ ├── swagger.go │ └── swagger.json ├── rest.swagger.json ├── swagger.json ├── sys │ └── user.api ├── test.api ├── user.api └── user.json ├── generate ├── entities.go ├── generate.go └── parser.go ├── go.mod ├── go.sum └── main.go /.gitignore: -------------------------------------------------------------------------------- 1 | # temp ignore 2 | *.log 3 | *.cache 4 | *.diff 5 | *.patch 6 | *.tmp 7 | 8 | # system ignore 9 | .DS_Store 10 | Thumbs.db 11 | *.orig 12 | 13 | # idea ignore 14 | .idea/ 15 | *.ipr 16 | 17 | # 18 | .swagger-codegen 19 | swagtest 20 | *.exe -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 zeromicro 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # goctl-swagger[已废弃] 2 | 3 | ## 废弃使用说明 4 | 5 | 由于长期无人维护,此插件将不推荐使用,考虑到大家需求,goctl 内置实现了一套比较完善的 swagger 生成功能,可以使用 goctl api swagger 替换,详情参考 https://go-zero.dev/docs/tutorials/cli/swagger 6 | 7 | 8 | ### 1. 编译goctl-swagger插件 9 | 10 | ``` 11 | GOPROXY=https://goproxy.cn/,direct go install github.com/zeromicro/goctl-swagger@latest 12 | ``` 13 | 14 | ### 2. 配置环境 15 | 16 | 将$GOPATH/bin中的goctl-swagger添加到环境变量 17 | 18 | ### 3. 使用姿势 19 | 20 | * 创建api文件 21 | 22 | ```go 23 | info( 24 | title: "type title here" 25 | desc: "type desc here" 26 | author: "type author here" 27 | email: "type email here" 28 | version: "type version here" 29 | ) 30 | 31 | 32 | type ( 33 | RegisterReq { 34 | Username string `json:"username"` 35 | Password string `json:"password"` 36 | Mobile string `json:"mobile"` 37 | } 38 | 39 | LoginReq { 40 | Username string `json:"username"` 41 | Password string `json:"password"` 42 | } 43 | 44 | UserInfoReq { 45 | Id string `path:"id"` 46 | } 47 | 48 | UserInfoReply { 49 | Name string `json:"name"` 50 | Age int `json:"age"` 51 | Birthday string `json:"birthday"` 52 | Description string `json:"description"` 53 | Tag []string `json:"tag"` 54 | } 55 | 56 | UserSearchReq { 57 | KeyWord string `form:"keyWord"` 58 | } 59 | ) 60 | 61 | service user-api { 62 | @doc( 63 | summary: "注册" 64 | ) 65 | @handler register 66 | post /api/user/register (RegisterReq) 67 | 68 | @doc( 69 | summary: "登录" 70 | ) 71 | @handler login 72 | post /api/user/login (LoginReq) 73 | 74 | @doc( 75 | summary: "获取用户信息" 76 | ) 77 | @handler getUserInfo 78 | get /api/user/:id (UserInfoReq) returns (UserInfoReply) 79 | 80 | @doc( 81 | summary: "用户搜索" 82 | ) 83 | @handler searchUser 84 | get /api/user/search (UserSearchReq) returns (UserInfoReply) 85 | } 86 | ``` 87 | 88 | * 生成swagger.json 文件 89 | 90 | ```shell script 91 | goctl api plugin -plugin goctl-swagger="swagger -filename user.json" -api user.api -dir . 92 | ``` 93 | 94 | * 指定Host,basePath,schemes [api-host-and-base-path](https://swagger.io/docs/specification/2-0/api-host-and-base-path/) 95 | 96 | ```shell script 97 | goctl api plugin -plugin goctl-swagger="swagger -filename user.json -host 127.0.0.2 -basepath /api -schemes https,wss" -api user.api -dir . 98 | ``` 99 | 100 | * swagger ui 查看生成的文档 101 | 102 | ```shell script 103 | docker run --rm -p 8083:8080 -e SWAGGER_JSON=/foo/user.json -v $PWD:/foo swaggerapi/swagger-ui 104 | ``` 105 | 106 | * Swagger Codegen 生成客户端调用代码(go,javascript,php) 107 | 108 | ```shell script 109 | for l in go javascript php; do 110 | docker run --rm -v "$(pwd):/go-work" swaggerapi/swagger-codegen-cli generate \ 111 | -i "/go-work/rest.swagger.json" \ 112 | -l "$l" \ 113 | -o "/go-work/clients/$l" 114 | done 115 | ``` 116 | -------------------------------------------------------------------------------- /action/action.go: -------------------------------------------------------------------------------- 1 | package action 2 | 3 | import ( 4 | "github.com/urfave/cli/v2" 5 | "github.com/zeromicro/go-zero/tools/goctl/plugin" 6 | "github.com/zeromicro/goctl-swagger/generate" 7 | ) 8 | 9 | func Generator(ctx *cli.Context) error { 10 | fileName := ctx.String("filename") 11 | 12 | if len(fileName) == 0 { 13 | fileName = "rest.swagger.json" 14 | } 15 | 16 | p, err := plugin.NewPlugin() 17 | if err != nil { 18 | return err 19 | } 20 | basepath := ctx.String("basepath") 21 | host := ctx.String("host") 22 | schemes := ctx.String("schemes") 23 | return generate.Do(fileName, host, basepath, schemes, p) 24 | } 25 | -------------------------------------------------------------------------------- /example/clients/go/.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | *.test 24 | *.prof 25 | -------------------------------------------------------------------------------- /example/clients/go/.swagger-codegen-ignore: -------------------------------------------------------------------------------- 1 | # Swagger Codegen Ignore 2 | # Generated by swagger-codegen https://github.com/swagger-api/swagger-codegen 3 | 4 | # Use this file to prevent files from being overwritten by the generator. 5 | # The patterns follow closely to .gitignore or .dockerignore. 6 | 7 | # As an example, the C# client generator defines ApiClient.cs. 8 | # You can make changes and tell Swagger Codgen to ignore just this file by uncommenting the following line: 9 | #ApiClient.cs 10 | 11 | # You can match any string of characters against a directory, file or extension with a single asterisk (*): 12 | #foo/*/qux 13 | # The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux 14 | 15 | # You can recursively match patterns against a directory, file or extension with a double asterisk (**): 16 | #foo/**/qux 17 | # This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux 18 | 19 | # You can also negate patterns with an exclamation (!). 20 | # For example, you can ignore all files in a docs folder with the file extension .md: 21 | #docs/*.md 22 | # Then explicitly reverse the ignore rule for a single file: 23 | #!docs/README.md 24 | -------------------------------------------------------------------------------- /example/clients/go/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | install: 4 | - go get -d -v . 5 | 6 | script: 7 | - go build -v ./ 8 | 9 | -------------------------------------------------------------------------------- /example/clients/go/README.md: -------------------------------------------------------------------------------- 1 | # Go API client for swagger 2 | 3 | No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) 4 | 5 | ## Overview 6 | This API client was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. By using the [swagger-spec](https://github.com/swagger-api/swagger-spec) from a remote server, you can easily generate an API client. 7 | 8 | - API version: 9 | - Package version: 1.0.0 10 | - Build package: io.swagger.codegen.languages.GoClientCodegen 11 | 12 | ## Installation 13 | Put the package under your project folder and add the following in import: 14 | ```golang 15 | import "./swagger" 16 | ``` 17 | 18 | ## Documentation for API Endpoints 19 | 20 | All URIs are relative to *http://localhost* 21 | 22 | Class | Method | HTTP request | Description 23 | ------------ | ------------- | ------------- | ------------- 24 | *GreetApi* | [**Ping**](docs/GreetApi.md#ping) | **Get** /user/ping | 25 | *UserApiApi* | [**GetUserInfo**](docs/UserApiApi.md#getuserinfo) | **Get** /api/user/{id} | 获取用户信息 26 | *UserApiApi* | [**Login**](docs/UserApiApi.md#login) | **Post** /api/user/login | 登录 27 | *UserApiApi* | [**Register**](docs/UserApiApi.md#register) | **Post** /api/user/register | 注册 28 | *UserApiApi* | [**SearchUser**](docs/UserApiApi.md#searchuser) | **Get** /api/user/search | 用户搜索 29 | 30 | 31 | ## Documentation For Models 32 | 33 | - [LoginReq](docs/LoginReq.md) 34 | - [RegisterReq](docs/RegisterReq.md) 35 | - [UserInfoReply](docs/UserInfoReply.md) 36 | - [UserInfoReq](docs/UserInfoReq.md) 37 | - [UserSearchReply](docs/UserSearchReply.md) 38 | - [UserSearchReq](docs/UserSearchReq.md) 39 | 40 | 41 | ## Documentation For Authorization 42 | 43 | ## apiKey 44 | - **Type**: API key 45 | 46 | Example 47 | ```golang 48 | auth := context.WithValue(context.Background(), sw.ContextAPIKey, sw.APIKey{ 49 | Key: "APIKEY", 50 | Prefix: "Bearer", // Omit if not necessary. 51 | }) 52 | r, err := client.Service.Operation(auth, args) 53 | ``` 54 | 55 | ## Author 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /example/clients/go/api/swagger.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | swagger: "2.0" 3 | info: 4 | version: "" 5 | title: "" 6 | schemes: 7 | - "http" 8 | - "https" 9 | consumes: 10 | - "application/json" 11 | produces: 12 | - "application/json" 13 | paths: 14 | /api/user/login: 15 | post: 16 | tags: 17 | - "user-api" 18 | summary: "登录" 19 | operationId: "login" 20 | parameters: 21 | - in: "body" 22 | name: "body" 23 | required: true 24 | schema: 25 | $ref: "#/definitions/LoginReq" 26 | x-exportParamName: "Body" 27 | responses: 28 | "200": 29 | description: "A successful response." 30 | schema: {} 31 | /api/user/register: 32 | post: 33 | tags: 34 | - "user-api" 35 | summary: "注册" 36 | description: "注册一个用户" 37 | operationId: "register" 38 | parameters: 39 | - in: "body" 40 | name: "body" 41 | required: true 42 | schema: 43 | $ref: "#/definitions/RegisterReq" 44 | x-exportParamName: "Body" 45 | responses: 46 | "200": 47 | description: "A successful response." 48 | schema: {} 49 | /api/user/search: 50 | get: 51 | tags: 52 | - "user-api" 53 | summary: "用户搜索" 54 | operationId: "searchUser" 55 | parameters: 56 | - in: "body" 57 | name: "body" 58 | required: true 59 | schema: 60 | $ref: "#/definitions/UserSearchReq" 61 | x-exportParamName: "Body" 62 | responses: 63 | "200": 64 | description: "A successful response." 65 | schema: 66 | $ref: "#/definitions/UserSearchReply" 67 | /api/user/{id}: 68 | get: 69 | tags: 70 | - "user-api" 71 | summary: "获取用户信息" 72 | operationId: "getUserInfo" 73 | parameters: 74 | - name: "id" 75 | in: "path" 76 | required: true 77 | type: "string" 78 | x-exportParamName: "Id" 79 | - in: "body" 80 | name: "body" 81 | required: true 82 | schema: 83 | $ref: "#/definitions/UserInfoReq" 84 | x-exportParamName: "Body" 85 | responses: 86 | "200": 87 | description: "A successful response." 88 | schema: 89 | $ref: "#/definitions/UserInfoReply" 90 | /user/ping: 91 | get: 92 | tags: 93 | - "greet" 94 | operationId: "ping" 95 | parameters: [] 96 | responses: 97 | "200": 98 | description: "A successful response." 99 | schema: {} 100 | securityDefinitions: 101 | apiKey: 102 | description: "Enter JWT Bearer token **_only_**" 103 | type: "apiKey" 104 | name: "Authorization" 105 | in: "header" 106 | definitions: 107 | LoginReq: 108 | type: "object" 109 | properties: 110 | username: 111 | type: "string" 112 | password: 113 | type: "string" 114 | title: "LoginReq" 115 | example: 116 | password: "password" 117 | username: "username" 118 | RegisterReq: 119 | type: "object" 120 | properties: 121 | username: 122 | type: "string" 123 | password: 124 | type: "string" 125 | mobile: 126 | type: "string" 127 | title: "RegisterReq" 128 | example: 129 | password: "password" 130 | mobile: "mobile" 131 | username: "username" 132 | UserInfoReply: 133 | type: "object" 134 | properties: 135 | name: 136 | type: "string" 137 | age: 138 | type: "integer" 139 | format: "int32" 140 | birthday: 141 | type: "string" 142 | description: 143 | type: "string" 144 | tag: 145 | type: "array" 146 | items: 147 | type: "string" 148 | title: "UserInfoReply" 149 | example: 150 | birthday: "birthday" 151 | name: "name" 152 | description: "description" 153 | tag: 154 | - "tag" 155 | - "tag" 156 | age: 0 157 | UserInfoReq: 158 | type: "object" 159 | properties: 160 | id: 161 | type: "string" 162 | title: "UserInfoReq" 163 | example: 164 | id: "id" 165 | UserSearchReply: 166 | type: "object" 167 | properties: 168 | KeyWord: 169 | type: "array" 170 | items: 171 | $ref: "#/definitions/UserInfoReply" 172 | title: "UserSearchReply" 173 | example: 174 | KeyWord: 175 | - birthday: "birthday" 176 | name: "name" 177 | description: "description" 178 | tag: 179 | - "tag" 180 | - "tag" 181 | age: 0 182 | - birthday: "birthday" 183 | name: "name" 184 | description: "description" 185 | tag: 186 | - "tag" 187 | - "tag" 188 | age: 0 189 | UserSearchReq: 190 | type: "object" 191 | properties: 192 | keyWord: 193 | type: "string" 194 | title: "UserSearchReq" 195 | example: 196 | keyWord: "keyWord" 197 | -------------------------------------------------------------------------------- /example/clients/go/api_greet.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * 4 | * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) 5 | * 6 | * API version: 7 | * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) 8 | */ 9 | 10 | package swagger 11 | 12 | import ( 13 | "context" 14 | "io/ioutil" 15 | "net/http" 16 | "net/url" 17 | "strings" 18 | ) 19 | 20 | // Linger please 21 | var ( 22 | _ context.Context 23 | ) 24 | 25 | type GreetApiService service 26 | 27 | /* 28 | GreetApiService 29 | * @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). 30 | 31 | @return interface{} 32 | */ 33 | func (a *GreetApiService) Ping(ctx context.Context) (interface{}, *http.Response, error) { 34 | var ( 35 | localVarHttpMethod = strings.ToUpper("Get") 36 | localVarPostBody interface{} 37 | localVarFileName string 38 | localVarFileBytes []byte 39 | localVarReturnValue interface{} 40 | ) 41 | 42 | // create path and map variables 43 | localVarPath := a.client.cfg.BasePath + "/user/ping" 44 | 45 | localVarHeaderParams := make(map[string]string) 46 | localVarQueryParams := url.Values{} 47 | localVarFormParams := url.Values{} 48 | 49 | // to determine the Content-Type header 50 | localVarHttpContentTypes := []string{"application/json"} 51 | 52 | // set Content-Type header 53 | localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes) 54 | if localVarHttpContentType != "" { 55 | localVarHeaderParams["Content-Type"] = localVarHttpContentType 56 | } 57 | 58 | // to determine the Accept header 59 | localVarHttpHeaderAccepts := []string{"application/json"} 60 | 61 | // set Accept header 62 | localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts) 63 | if localVarHttpHeaderAccept != "" { 64 | localVarHeaderParams["Accept"] = localVarHttpHeaderAccept 65 | } 66 | r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes) 67 | if err != nil { 68 | return localVarReturnValue, nil, err 69 | } 70 | 71 | localVarHttpResponse, err := a.client.callAPI(r) 72 | if err != nil || localVarHttpResponse == nil { 73 | return localVarReturnValue, localVarHttpResponse, err 74 | } 75 | 76 | localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body) 77 | localVarHttpResponse.Body.Close() 78 | if err != nil { 79 | return localVarReturnValue, localVarHttpResponse, err 80 | } 81 | 82 | if localVarHttpResponse.StatusCode < 300 { 83 | // If we succeed, return the data, otherwise pass on to decode error. 84 | err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) 85 | return localVarReturnValue, localVarHttpResponse, err 86 | } 87 | 88 | if localVarHttpResponse.StatusCode >= 300 { 89 | newErr := GenericSwaggerError{ 90 | body: localVarBody, 91 | error: localVarHttpResponse.Status, 92 | } 93 | 94 | if localVarHttpResponse.StatusCode == 200 { 95 | var v interface{} 96 | err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type")) 97 | if err != nil { 98 | newErr.error = err.Error() 99 | return localVarReturnValue, localVarHttpResponse, newErr 100 | } 101 | newErr.model = v 102 | return localVarReturnValue, localVarHttpResponse, newErr 103 | } 104 | 105 | return localVarReturnValue, localVarHttpResponse, newErr 106 | } 107 | 108 | return localVarReturnValue, localVarHttpResponse, nil 109 | } 110 | -------------------------------------------------------------------------------- /example/clients/go/configuration.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * 4 | * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) 5 | * 6 | * API version: 7 | * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) 8 | */ 9 | 10 | package swagger 11 | 12 | import ( 13 | "net/http" 14 | ) 15 | 16 | // contextKeys are used to identify the type of value in the context. 17 | // Since these are string, it is possible to get a short description of the 18 | // context key for logging and debugging using key.String(). 19 | 20 | type contextKey string 21 | 22 | func (c contextKey) String() string { 23 | return "auth " + string(c) 24 | } 25 | 26 | var ( 27 | // ContextOAuth2 takes a oauth2.TokenSource as authentication for the request. 28 | ContextOAuth2 = contextKey("token") 29 | 30 | // ContextBasicAuth takes BasicAuth as authentication for the request. 31 | ContextBasicAuth = contextKey("basic") 32 | 33 | // ContextAccessToken takes a string oauth2 access token as authentication for the request. 34 | ContextAccessToken = contextKey("accesstoken") 35 | 36 | // ContextAPIKey takes an APIKey as authentication for the request 37 | ContextAPIKey = contextKey("apikey") 38 | ) 39 | 40 | // BasicAuth provides basic http authentication to a request passed via context using ContextBasicAuth 41 | type BasicAuth struct { 42 | UserName string `json:"userName,omitempty"` 43 | Password string `json:"password,omitempty"` 44 | } 45 | 46 | // APIKey provides API key based authentication to a request passed via context using ContextAPIKey 47 | type APIKey struct { 48 | Key string 49 | Prefix string 50 | } 51 | 52 | type Configuration struct { 53 | BasePath string `json:"basePath,omitempty"` 54 | Host string `json:"host,omitempty"` 55 | Scheme string `json:"scheme,omitempty"` 56 | DefaultHeader map[string]string `json:"defaultHeader,omitempty"` 57 | UserAgent string `json:"userAgent,omitempty"` 58 | HTTPClient *http.Client 59 | } 60 | 61 | func NewConfiguration() *Configuration { 62 | cfg := &Configuration{ 63 | BasePath: "http://localhost", 64 | DefaultHeader: make(map[string]string), 65 | UserAgent: "Swagger-Codegen/1.0.0/go", 66 | } 67 | return cfg 68 | } 69 | 70 | func (c *Configuration) AddDefaultHeader(key string, value string) { 71 | c.DefaultHeader[key] = value 72 | } 73 | -------------------------------------------------------------------------------- /example/clients/go/docs/GreetApi.md: -------------------------------------------------------------------------------- 1 | # \GreetApi 2 | 3 | All URIs are relative to *http://localhost* 4 | 5 | Method | HTTP request | Description 6 | ------------- | ------------- | ------------- 7 | [**Ping**](GreetApi.md#Ping) | **Get** /user/ping | 8 | 9 | 10 | # **Ping** 11 | > interface{} Ping(ctx, ) 12 | 13 | 14 | ### Required Parameters 15 | This endpoint does not need any parameter. 16 | 17 | ### Return type 18 | 19 | [**interface{}**](interface{}.md) 20 | 21 | ### Authorization 22 | 23 | No authorization required 24 | 25 | ### HTTP request headers 26 | 27 | - **Content-Type**: application/json 28 | - **Accept**: application/json 29 | 30 | [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) 31 | 32 | -------------------------------------------------------------------------------- /example/clients/go/docs/LoginReq.md: -------------------------------------------------------------------------------- 1 | # LoginReq 2 | 3 | ## Properties 4 | Name | Type | Description | Notes 5 | ------------ | ------------- | ------------- | ------------- 6 | **Username** | **string** | | [optional] [default to null] 7 | **Password** | **string** | | [optional] [default to null] 8 | 9 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 10 | 11 | 12 | -------------------------------------------------------------------------------- /example/clients/go/docs/RegisterReq.md: -------------------------------------------------------------------------------- 1 | # RegisterReq 2 | 3 | ## Properties 4 | Name | Type | Description | Notes 5 | ------------ | ------------- | ------------- | ------------- 6 | **Username** | **string** | | [optional] [default to null] 7 | **Password** | **string** | | [optional] [default to null] 8 | **Mobile** | **string** | | [optional] [default to null] 9 | 10 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 11 | 12 | 13 | -------------------------------------------------------------------------------- /example/clients/go/docs/UserApiApi.md: -------------------------------------------------------------------------------- 1 | # \UserApiApi 2 | 3 | All URIs are relative to *http://localhost* 4 | 5 | Method | HTTP request | Description 6 | ------------- | ------------- | ------------- 7 | [**GetUserInfo**](UserApiApi.md#GetUserInfo) | **Get** /api/user/{id} | 获取用户信息 8 | [**Login**](UserApiApi.md#Login) | **Post** /api/user/login | 登录 9 | [**Register**](UserApiApi.md#Register) | **Post** /api/user/register | 注册 10 | [**SearchUser**](UserApiApi.md#SearchUser) | **Get** /api/user/search | 用户搜索 11 | 12 | 13 | # **GetUserInfo** 14 | > UserInfoReply GetUserInfo(ctx, id, body) 15 | 获取用户信息 16 | 17 | ### Required Parameters 18 | 19 | Name | Type | Description | Notes 20 | ------------- | ------------- | ------------- | ------------- 21 | **ctx** | **context.Context** | context for authentication, logging, cancellation, deadlines, tracing, etc. 22 | **id** | **string**| | 23 | **body** | [**UserInfoReq**](UserInfoReq.md)| | 24 | 25 | ### Return type 26 | 27 | [**UserInfoReply**](UserInfoReply.md) 28 | 29 | ### Authorization 30 | 31 | No authorization required 32 | 33 | ### HTTP request headers 34 | 35 | - **Content-Type**: application/json 36 | - **Accept**: application/json 37 | 38 | [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) 39 | 40 | # **Login** 41 | > interface{} Login(ctx, body) 42 | 登录 43 | 44 | ### Required Parameters 45 | 46 | Name | Type | Description | Notes 47 | ------------- | ------------- | ------------- | ------------- 48 | **ctx** | **context.Context** | context for authentication, logging, cancellation, deadlines, tracing, etc. 49 | **body** | [**LoginReq**](LoginReq.md)| | 50 | 51 | ### Return type 52 | 53 | [**interface{}**](interface{}.md) 54 | 55 | ### Authorization 56 | 57 | No authorization required 58 | 59 | ### HTTP request headers 60 | 61 | - **Content-Type**: application/json 62 | - **Accept**: application/json 63 | 64 | [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) 65 | 66 | # **Register** 67 | > interface{} Register(ctx, body) 68 | 注册 69 | 70 | 注册一个用户 71 | 72 | ### Required Parameters 73 | 74 | Name | Type | Description | Notes 75 | ------------- | ------------- | ------------- | ------------- 76 | **ctx** | **context.Context** | context for authentication, logging, cancellation, deadlines, tracing, etc. 77 | **body** | [**RegisterReq**](RegisterReq.md)| | 78 | 79 | ### Return type 80 | 81 | [**interface{}**](interface{}.md) 82 | 83 | ### Authorization 84 | 85 | No authorization required 86 | 87 | ### HTTP request headers 88 | 89 | - **Content-Type**: application/json 90 | - **Accept**: application/json 91 | 92 | [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) 93 | 94 | # **SearchUser** 95 | > UserSearchReply SearchUser(ctx, body) 96 | 用户搜索 97 | 98 | ### Required Parameters 99 | 100 | Name | Type | Description | Notes 101 | ------------- | ------------- | ------------- | ------------- 102 | **ctx** | **context.Context** | context for authentication, logging, cancellation, deadlines, tracing, etc. 103 | **body** | [**UserSearchReq**](UserSearchReq.md)| | 104 | 105 | ### Return type 106 | 107 | [**UserSearchReply**](UserSearchReply.md) 108 | 109 | ### Authorization 110 | 111 | No authorization required 112 | 113 | ### HTTP request headers 114 | 115 | - **Content-Type**: application/json 116 | - **Accept**: application/json 117 | 118 | [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) 119 | 120 | -------------------------------------------------------------------------------- /example/clients/go/docs/UserInfoReply.md: -------------------------------------------------------------------------------- 1 | # UserInfoReply 2 | 3 | ## Properties 4 | Name | Type | Description | Notes 5 | ------------ | ------------- | ------------- | ------------- 6 | **Name** | **string** | | [optional] [default to null] 7 | **Age** | **int32** | | [optional] [default to null] 8 | **Birthday** | **string** | | [optional] [default to null] 9 | **Description** | **string** | | [optional] [default to null] 10 | **Tag** | **[]string** | | [optional] [default to null] 11 | 12 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 13 | 14 | 15 | -------------------------------------------------------------------------------- /example/clients/go/docs/UserInfoReq.md: -------------------------------------------------------------------------------- 1 | # UserInfoReq 2 | 3 | ## Properties 4 | Name | Type | Description | Notes 5 | ------------ | ------------- | ------------- | ------------- 6 | **Id** | **string** | | [optional] [default to null] 7 | 8 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 9 | 10 | 11 | -------------------------------------------------------------------------------- /example/clients/go/docs/UserSearchReply.md: -------------------------------------------------------------------------------- 1 | # UserSearchReply 2 | 3 | ## Properties 4 | Name | Type | Description | Notes 5 | ------------ | ------------- | ------------- | ------------- 6 | **KeyWord** | [**[]UserInfoReply**](UserInfoReply.md) | | [optional] [default to null] 7 | 8 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 9 | 10 | 11 | -------------------------------------------------------------------------------- /example/clients/go/docs/UserSearchReq.md: -------------------------------------------------------------------------------- 1 | # UserSearchReq 2 | 3 | ## Properties 4 | Name | Type | Description | Notes 5 | ------------ | ------------- | ------------- | ------------- 6 | **KeyWord** | **string** | | [optional] [default to null] 7 | 8 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 9 | 10 | 11 | -------------------------------------------------------------------------------- /example/clients/go/git_push.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ 3 | # 4 | # Usage example: /bin/sh ./git_push.sh wing328 swagger-petstore-perl "minor update" 5 | 6 | git_user_id=$1 7 | git_repo_id=$2 8 | release_note=$3 9 | 10 | if [ "$git_user_id" = "" ]; then 11 | git_user_id="GIT_USER_ID" 12 | echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id" 13 | fi 14 | 15 | if [ "$git_repo_id" = "" ]; then 16 | git_repo_id="GIT_REPO_ID" 17 | echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id" 18 | fi 19 | 20 | if [ "$release_note" = "" ]; then 21 | release_note="Minor update" 22 | echo "[INFO] No command line input provided. Set \$release_note to $release_note" 23 | fi 24 | 25 | # Initialize the local directory as a Git repository 26 | git init 27 | 28 | # Adds the files in the local repository and stages them for commit. 29 | git add . 30 | 31 | # Commits the tracked changes and prepares them to be pushed to a remote repository. 32 | git commit -m "$release_note" 33 | 34 | # Sets the new remote 35 | git_remote=`git remote` 36 | if [ "$git_remote" = "" ]; then # git remote not defined 37 | 38 | if [ "$GIT_TOKEN" = "" ]; then 39 | echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment." 40 | git remote add origin https://github.com/${git_user_id}/${git_repo_id}.git 41 | else 42 | git remote add origin https://${git_user_id}:${GIT_TOKEN}@github.com/${git_user_id}/${git_repo_id}.git 43 | fi 44 | 45 | fi 46 | 47 | git pull origin master 48 | 49 | # Pushes (Forces) the changes in the local repository up to the remote repository 50 | echo "Git pushing to https://github.com/${git_user_id}/${git_repo_id}.git" 51 | git push origin master 2>&1 | grep -v 'To https' 52 | 53 | -------------------------------------------------------------------------------- /example/clients/go/model_login_req.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * 4 | * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) 5 | * 6 | * API version: 7 | * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) 8 | */ 9 | 10 | package swagger 11 | 12 | type LoginReq struct { 13 | Username string `json:"username,omitempty"` 14 | Password string `json:"password,omitempty"` 15 | } 16 | -------------------------------------------------------------------------------- /example/clients/go/model_register_req.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * 4 | * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) 5 | * 6 | * API version: 7 | * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) 8 | */ 9 | 10 | package swagger 11 | 12 | type RegisterReq struct { 13 | Username string `json:"username,omitempty"` 14 | Password string `json:"password,omitempty"` 15 | Mobile string `json:"mobile,omitempty"` 16 | } 17 | -------------------------------------------------------------------------------- /example/clients/go/model_user_info_reply.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * 4 | * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) 5 | * 6 | * API version: 7 | * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) 8 | */ 9 | 10 | package swagger 11 | 12 | type UserInfoReply struct { 13 | Name string `json:"name,omitempty"` 14 | Age int32 `json:"age,omitempty"` 15 | Birthday string `json:"birthday,omitempty"` 16 | Description string `json:"description,omitempty"` 17 | Tag []string `json:"tag,omitempty"` 18 | } 19 | -------------------------------------------------------------------------------- /example/clients/go/model_user_info_req.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * 4 | * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) 5 | * 6 | * API version: 7 | * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) 8 | */ 9 | 10 | package swagger 11 | 12 | type UserInfoReq struct { 13 | Id string `json:"id,omitempty"` 14 | } 15 | -------------------------------------------------------------------------------- /example/clients/go/model_user_search_reply.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * 4 | * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) 5 | * 6 | * API version: 7 | * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) 8 | */ 9 | 10 | package swagger 11 | 12 | type UserSearchReply struct { 13 | KeyWord []UserInfoReply `json:"KeyWord,omitempty"` 14 | } 15 | -------------------------------------------------------------------------------- /example/clients/go/model_user_search_req.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * 4 | * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) 5 | * 6 | * API version: 7 | * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) 8 | */ 9 | 10 | package swagger 11 | 12 | type UserSearchReq struct { 13 | KeyWord string `json:"keyWord,omitempty"` 14 | } 15 | -------------------------------------------------------------------------------- /example/clients/go/response.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * 4 | * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) 5 | * 6 | * API version: 7 | * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) 8 | */ 9 | 10 | package swagger 11 | 12 | import ( 13 | "net/http" 14 | ) 15 | 16 | type APIResponse struct { 17 | *http.Response `json:"-"` 18 | Message string `json:"message,omitempty"` 19 | // Operation is the name of the swagger operation. 20 | Operation string `json:"operation,omitempty"` 21 | // RequestURL is the request URL. This value is always available, even if the 22 | // embedded *http.Response is nil. 23 | RequestURL string `json:"url,omitempty"` 24 | // Method is the HTTP method used for the request. This value is always 25 | // available, even if the embedded *http.Response is nil. 26 | Method string `json:"method,omitempty"` 27 | // Payload holds the contents of the response body (which may be nil or empty). 28 | // This is provided here as the raw response.Body() reader will have already 29 | // been drained. 30 | Payload []byte `json:"-"` 31 | } 32 | 33 | func NewAPIResponse(r *http.Response) *APIResponse { 34 | 35 | response := &APIResponse{Response: r} 36 | return response 37 | } 38 | 39 | func NewAPIResponseWithError(errorMessage string) *APIResponse { 40 | 41 | response := &APIResponse{Message: errorMessage} 42 | return response 43 | } 44 | -------------------------------------------------------------------------------- /example/clients/javascript/.swagger-codegen-ignore: -------------------------------------------------------------------------------- 1 | # Swagger Codegen Ignore 2 | # Generated by swagger-codegen https://github.com/swagger-api/swagger-codegen 3 | 4 | # Use this file to prevent files from being overwritten by the generator. 5 | # The patterns follow closely to .gitignore or .dockerignore. 6 | 7 | # As an example, the C# client generator defines ApiClient.cs. 8 | # You can make changes and tell Swagger Codgen to ignore just this file by uncommenting the following line: 9 | #ApiClient.cs 10 | 11 | # You can match any string of characters against a directory, file or extension with a single asterisk (*): 12 | #foo/*/qux 13 | # The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux 14 | 15 | # You can recursively match patterns against a directory, file or extension with a double asterisk (**): 16 | #foo/**/qux 17 | # This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux 18 | 19 | # You can also negate patterns with an exclamation (!). 20 | # For example, you can ignore all files in a docs folder with the file extension .md: 21 | #docs/*.md 22 | # Then explicitly reverse the ignore rule for a single file: 23 | #!docs/README.md 24 | -------------------------------------------------------------------------------- /example/clients/javascript/.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "6" 4 | - "6.1" 5 | - "5" 6 | - "5.11" 7 | 8 | -------------------------------------------------------------------------------- /example/clients/javascript/README.md: -------------------------------------------------------------------------------- 1 | # swagger-js-client 2 | 3 | SwaggerJsClient - JavaScript client for swagger-js-client 4 | No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) 5 | This SDK is automatically generated by the [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) project: 6 | 7 | - API version: 8 | - Package version: 1.0.0 9 | - Build package: io.swagger.codegen.languages.JavascriptClientCodegen 10 | 11 | ## Installation 12 | 13 | ### For [Node.js](https://nodejs.org/) 14 | 15 | #### npm 16 | 17 | To publish the library as a [npm](https://www.npmjs.com/), 18 | please follow the procedure in ["Publishing npm packages"](https://docs.npmjs.com/getting-started/publishing-npm-packages). 19 | 20 | Then install it via: 21 | 22 | ```shell 23 | npm install swagger-js-client --save 24 | ``` 25 | 26 | ##### Local development 27 | 28 | To use the library locally without publishing to a remote npm registry, first install the dependencies by changing 29 | into the directory containing `package.json` (and this README). Let's call this `JAVASCRIPT_CLIENT_DIR`. Then run: 30 | 31 | ```shell 32 | npm install 33 | ``` 34 | 35 | Next, [link](https://docs.npmjs.com/cli/link) it globally in npm with the following, also from `JAVASCRIPT_CLIENT_DIR`: 36 | 37 | ```shell 38 | npm link 39 | ``` 40 | 41 | Finally, switch to the directory you want to use your swagger-js-client from, and run: 42 | 43 | ```shell 44 | npm link /path/to/ 45 | ``` 46 | 47 | You should now be able to `require('swagger-js-client')` in javascript files from the directory you ran the last 48 | command above from. 49 | 50 | #### git 51 | # 52 | If the library is hosted at a git repository, e.g. 53 | https://github.com/GIT_USER_ID/GIT_REPO_ID 54 | then install it via: 55 | 56 | ```shell 57 | npm install GIT_USER_ID/GIT_REPO_ID --save 58 | ``` 59 | 60 | ### For browser 61 | 62 | The library also works in the browser environment via npm and [browserify](http://browserify.org/). After following 63 | the above steps with Node.js and installing browserify with `npm install -g browserify`, 64 | perform the following (assuming *main.js* is your entry file, that's to say your javascript file where you actually 65 | use this library): 66 | 67 | ```shell 68 | browserify main.js > bundle.js 69 | ``` 70 | 71 | Then include *bundle.js* in the HTML pages. 72 | 73 | ### Webpack Configuration 74 | 75 | Using Webpack you may encounter the following error: "Module not found: Error: 76 | Cannot resolve module", most certainly you should disable AMD loader. Add/merge 77 | the following section to your webpack config: 78 | 79 | ```javascript 80 | module: { 81 | rules: [ 82 | { 83 | parser: { 84 | amd: false 85 | } 86 | } 87 | ] 88 | } 89 | ``` 90 | 91 | ## Getting Started 92 | 93 | Please follow the [installation](#installation) instruction and execute the following JS code: 94 | 95 | ```javascript 96 | var SwaggerJsClient = require('swagger-js-client'); 97 | 98 | var api = new SwaggerJsClient.GreetApi() 99 | 100 | var callback = function(error, data, response) { 101 | if (error) { 102 | console.error(error); 103 | } else { 104 | console.log('API called successfully. Returned data: ' + data); 105 | } 106 | }; 107 | api.ping(callback); 108 | 109 | ``` 110 | 111 | ## Documentation for API Endpoints 112 | 113 | All URIs are relative to *http://localhost* 114 | 115 | Class | Method | HTTP request | Description 116 | ------------ | ------------- | ------------- | ------------- 117 | *SwaggerJsClient.GreetApi* | [**ping**](docs/GreetApi.md#ping) | **GET** /user/ping | 118 | *SwaggerJsClient.UserApiApi* | [**getUserInfo**](docs/UserApiApi.md#getUserInfo) | **GET** /api/user/{id} | 获取用户信息 119 | *SwaggerJsClient.UserApiApi* | [**login**](docs/UserApiApi.md#login) | **POST** /api/user/login | 登录 120 | *SwaggerJsClient.UserApiApi* | [**register**](docs/UserApiApi.md#register) | **POST** /api/user/register | 注册 121 | *SwaggerJsClient.UserApiApi* | [**searchUser**](docs/UserApiApi.md#searchUser) | **GET** /api/user/search | 用户搜索 122 | 123 | 124 | ## Documentation for Models 125 | 126 | - [SwaggerJsClient.LoginReq](docs/LoginReq.md) 127 | - [SwaggerJsClient.RegisterReq](docs/RegisterReq.md) 128 | - [SwaggerJsClient.UserInfoReply](docs/UserInfoReply.md) 129 | - [SwaggerJsClient.UserInfoReq](docs/UserInfoReq.md) 130 | - [SwaggerJsClient.UserSearchReply](docs/UserSearchReply.md) 131 | - [SwaggerJsClient.UserSearchReq](docs/UserSearchReq.md) 132 | 133 | 134 | ## Documentation for Authorization 135 | 136 | 137 | ### apiKey 138 | 139 | - **Type**: API key 140 | - **API key parameter name**: Authorization 141 | - **Location**: HTTP header 142 | 143 | -------------------------------------------------------------------------------- /example/clients/javascript/docs/GreetApi.md: -------------------------------------------------------------------------------- 1 | # SwaggerJsClient.GreetApi 2 | 3 | All URIs are relative to *http://localhost* 4 | 5 | Method | HTTP request | Description 6 | ------------- | ------------- | ------------- 7 | [**ping**](GreetApi.md#ping) | **GET** /user/ping | 8 | 9 | 10 | 11 | # **ping** 12 | > Object ping() 13 | 14 | 15 | 16 | ### Example 17 | ```javascript 18 | var SwaggerJsClient = require('swagger-js-client'); 19 | 20 | var apiInstance = new SwaggerJsClient.GreetApi(); 21 | 22 | var callback = function(error, data, response) { 23 | if (error) { 24 | console.error(error); 25 | } else { 26 | console.log('API called successfully. Returned data: ' + data); 27 | } 28 | }; 29 | apiInstance.ping(callback); 30 | ``` 31 | 32 | ### Parameters 33 | This endpoint does not need any parameter. 34 | 35 | ### Return type 36 | 37 | **Object** 38 | 39 | ### Authorization 40 | 41 | No authorization required 42 | 43 | ### HTTP request headers 44 | 45 | - **Content-Type**: application/json 46 | - **Accept**: application/json 47 | 48 | -------------------------------------------------------------------------------- /example/clients/javascript/docs/LoginReq.md: -------------------------------------------------------------------------------- 1 | # SwaggerJsClient.LoginReq 2 | 3 | ## Properties 4 | Name | Type | Description | Notes 5 | ------------ | ------------- | ------------- | ------------- 6 | **username** | **String** | | [optional] 7 | **password** | **String** | | [optional] 8 | 9 | 10 | -------------------------------------------------------------------------------- /example/clients/javascript/docs/RegisterReq.md: -------------------------------------------------------------------------------- 1 | # SwaggerJsClient.RegisterReq 2 | 3 | ## Properties 4 | Name | Type | Description | Notes 5 | ------------ | ------------- | ------------- | ------------- 6 | **username** | **String** | | [optional] 7 | **password** | **String** | | [optional] 8 | **mobile** | **String** | | [optional] 9 | 10 | 11 | -------------------------------------------------------------------------------- /example/clients/javascript/docs/UserApiApi.md: -------------------------------------------------------------------------------- 1 | # SwaggerJsClient.UserApiApi 2 | 3 | All URIs are relative to *http://localhost* 4 | 5 | Method | HTTP request | Description 6 | ------------- | ------------- | ------------- 7 | [**getUserInfo**](UserApiApi.md#getUserInfo) | **GET** /api/user/{id} | 获取用户信息 8 | [**login**](UserApiApi.md#login) | **POST** /api/user/login | 登录 9 | [**register**](UserApiApi.md#register) | **POST** /api/user/register | 注册 10 | [**searchUser**](UserApiApi.md#searchUser) | **GET** /api/user/search | 用户搜索 11 | 12 | 13 | 14 | # **getUserInfo** 15 | > UserInfoReply getUserInfo(id, body) 16 | 17 | 获取用户信息 18 | 19 | ### Example 20 | ```javascript 21 | var SwaggerJsClient = require('swagger-js-client'); 22 | 23 | var apiInstance = new SwaggerJsClient.UserApiApi(); 24 | 25 | var id = "id_example"; // String | 26 | 27 | var body = new SwaggerJsClient.UserInfoReq(); // UserInfoReq | 28 | 29 | 30 | var callback = function(error, data, response) { 31 | if (error) { 32 | console.error(error); 33 | } else { 34 | console.log('API called successfully. Returned data: ' + data); 35 | } 36 | }; 37 | apiInstance.getUserInfo(id, body, callback); 38 | ``` 39 | 40 | ### Parameters 41 | 42 | Name | Type | Description | Notes 43 | ------------- | ------------- | ------------- | ------------- 44 | **id** | **String**| | 45 | **body** | [**UserInfoReq**](UserInfoReq.md)| | 46 | 47 | ### Return type 48 | 49 | [**UserInfoReply**](UserInfoReply.md) 50 | 51 | ### Authorization 52 | 53 | No authorization required 54 | 55 | ### HTTP request headers 56 | 57 | - **Content-Type**: application/json 58 | - **Accept**: application/json 59 | 60 | 61 | # **login** 62 | > Object login(body) 63 | 64 | 登录 65 | 66 | ### Example 67 | ```javascript 68 | var SwaggerJsClient = require('swagger-js-client'); 69 | 70 | var apiInstance = new SwaggerJsClient.UserApiApi(); 71 | 72 | var body = new SwaggerJsClient.LoginReq(); // LoginReq | 73 | 74 | 75 | var callback = function(error, data, response) { 76 | if (error) { 77 | console.error(error); 78 | } else { 79 | console.log('API called successfully. Returned data: ' + data); 80 | } 81 | }; 82 | apiInstance.login(body, callback); 83 | ``` 84 | 85 | ### Parameters 86 | 87 | Name | Type | Description | Notes 88 | ------------- | ------------- | ------------- | ------------- 89 | **body** | [**LoginReq**](LoginReq.md)| | 90 | 91 | ### Return type 92 | 93 | **Object** 94 | 95 | ### Authorization 96 | 97 | No authorization required 98 | 99 | ### HTTP request headers 100 | 101 | - **Content-Type**: application/json 102 | - **Accept**: application/json 103 | 104 | 105 | # **register** 106 | > Object register(body) 107 | 108 | 注册 109 | 110 | 注册一个用户 111 | 112 | ### Example 113 | ```javascript 114 | var SwaggerJsClient = require('swagger-js-client'); 115 | 116 | var apiInstance = new SwaggerJsClient.UserApiApi(); 117 | 118 | var body = new SwaggerJsClient.RegisterReq(); // RegisterReq | 119 | 120 | 121 | var callback = function(error, data, response) { 122 | if (error) { 123 | console.error(error); 124 | } else { 125 | console.log('API called successfully. Returned data: ' + data); 126 | } 127 | }; 128 | apiInstance.register(body, callback); 129 | ``` 130 | 131 | ### Parameters 132 | 133 | Name | Type | Description | Notes 134 | ------------- | ------------- | ------------- | ------------- 135 | **body** | [**RegisterReq**](RegisterReq.md)| | 136 | 137 | ### Return type 138 | 139 | **Object** 140 | 141 | ### Authorization 142 | 143 | No authorization required 144 | 145 | ### HTTP request headers 146 | 147 | - **Content-Type**: application/json 148 | - **Accept**: application/json 149 | 150 | 151 | # **searchUser** 152 | > UserSearchReply searchUser(body) 153 | 154 | 用户搜索 155 | 156 | ### Example 157 | ```javascript 158 | var SwaggerJsClient = require('swagger-js-client'); 159 | 160 | var apiInstance = new SwaggerJsClient.UserApiApi(); 161 | 162 | var body = new SwaggerJsClient.UserSearchReq(); // UserSearchReq | 163 | 164 | 165 | var callback = function(error, data, response) { 166 | if (error) { 167 | console.error(error); 168 | } else { 169 | console.log('API called successfully. Returned data: ' + data); 170 | } 171 | }; 172 | apiInstance.searchUser(body, callback); 173 | ``` 174 | 175 | ### Parameters 176 | 177 | Name | Type | Description | Notes 178 | ------------- | ------------- | ------------- | ------------- 179 | **body** | [**UserSearchReq**](UserSearchReq.md)| | 180 | 181 | ### Return type 182 | 183 | [**UserSearchReply**](UserSearchReply.md) 184 | 185 | ### Authorization 186 | 187 | No authorization required 188 | 189 | ### HTTP request headers 190 | 191 | - **Content-Type**: application/json 192 | - **Accept**: application/json 193 | 194 | -------------------------------------------------------------------------------- /example/clients/javascript/docs/UserInfoReply.md: -------------------------------------------------------------------------------- 1 | # SwaggerJsClient.UserInfoReply 2 | 3 | ## Properties 4 | Name | Type | Description | Notes 5 | ------------ | ------------- | ------------- | ------------- 6 | **name** | **String** | | [optional] 7 | **age** | **Number** | | [optional] 8 | **birthday** | **String** | | [optional] 9 | **description** | **String** | | [optional] 10 | **tag** | **[String]** | | [optional] 11 | 12 | 13 | -------------------------------------------------------------------------------- /example/clients/javascript/docs/UserInfoReq.md: -------------------------------------------------------------------------------- 1 | # SwaggerJsClient.UserInfoReq 2 | 3 | ## Properties 4 | Name | Type | Description | Notes 5 | ------------ | ------------- | ------------- | ------------- 6 | **id** | **String** | | [optional] 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/clients/javascript/docs/UserSearchReply.md: -------------------------------------------------------------------------------- 1 | # SwaggerJsClient.UserSearchReply 2 | 3 | ## Properties 4 | Name | Type | Description | Notes 5 | ------------ | ------------- | ------------- | ------------- 6 | **keyWord** | [**[UserInfoReply]**](UserInfoReply.md) | | [optional] 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/clients/javascript/docs/UserSearchReq.md: -------------------------------------------------------------------------------- 1 | # SwaggerJsClient.UserSearchReq 2 | 3 | ## Properties 4 | Name | Type | Description | Notes 5 | ------------ | ------------- | ------------- | ------------- 6 | **keyWord** | **String** | | [optional] 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/clients/javascript/git_push.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ 3 | # 4 | # Usage example: /bin/sh ./git_push.sh wing328 swagger-petstore-perl "minor update" 5 | 6 | git_user_id=$1 7 | git_repo_id=$2 8 | release_note=$3 9 | 10 | if [ "$git_user_id" = "" ]; then 11 | git_user_id="GIT_USER_ID" 12 | echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id" 13 | fi 14 | 15 | if [ "$git_repo_id" = "" ]; then 16 | git_repo_id="GIT_REPO_ID" 17 | echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id" 18 | fi 19 | 20 | if [ "$release_note" = "" ]; then 21 | release_note="Minor update" 22 | echo "[INFO] No command line input provided. Set \$release_note to $release_note" 23 | fi 24 | 25 | # Initialize the local directory as a Git repository 26 | git init 27 | 28 | # Adds the files in the local repository and stages them for commit. 29 | git add . 30 | 31 | # Commits the tracked changes and prepares them to be pushed to a remote repository. 32 | git commit -m "$release_note" 33 | 34 | # Sets the new remote 35 | git_remote=`git remote` 36 | if [ "$git_remote" = "" ]; then # git remote not defined 37 | 38 | if [ "$GIT_TOKEN" = "" ]; then 39 | echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the Git credential in your environment." 40 | git remote add origin https://github.com/${git_user_id}/${git_repo_id}.git 41 | else 42 | git remote add origin https://${git_user_id}:${GIT_TOKEN}@github.com/${git_user_id}/${git_repo_id}.git 43 | fi 44 | 45 | fi 46 | 47 | git pull origin master 48 | 49 | # Pushes (Forces) the changes in the local repository up to the remote repository 50 | echo "Git pushing to https://github.com/${git_user_id}/${git_repo_id}.git" 51 | git push origin master 2>&1 | grep -v 'To https' 52 | 53 | -------------------------------------------------------------------------------- /example/clients/javascript/mocha.opts: -------------------------------------------------------------------------------- 1 | --timeout 10000 2 | -------------------------------------------------------------------------------- /example/clients/javascript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "swagger-js-client", 3 | "version": "1.0.0", 4 | "description": "ERROR_UNKNOWN", 5 | "license": "Unlicense", 6 | "main": "src/index.js", 7 | "scripts": { 8 | "test": "mocha --recursive" 9 | }, 10 | "browser": { 11 | "fs": false 12 | }, 13 | "dependencies": { 14 | "superagent": "3.7.0", 15 | "querystring": "0.2.0" 16 | }, 17 | "devDependencies": { 18 | "mocha": "~2.3.4", 19 | "sinon": "1.17.3", 20 | "expect.js": "~0.3.1" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /example/clients/javascript/src/api/GreetApi.js: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) 4 | * 5 | * OpenAPI spec version: 6 | * 7 | * NOTE: This class is auto generated by the swagger code generator program. 8 | * https://github.com/swagger-api/swagger-codegen.git 9 | * 10 | * Swagger Codegen version: 2.4.18 11 | * 12 | * Do not edit the class manually. 13 | * 14 | */ 15 | 16 | (function(root, factory) { 17 | if (typeof define === 'function' && define.amd) { 18 | // AMD. Register as an anonymous module. 19 | define(['ApiClient'], factory); 20 | } else if (typeof module === 'object' && module.exports) { 21 | // CommonJS-like environments that support module.exports, like Node. 22 | module.exports = factory(require('../ApiClient')); 23 | } else { 24 | // Browser globals (root is window) 25 | if (!root.SwaggerJsClient) { 26 | root.SwaggerJsClient = {}; 27 | } 28 | root.SwaggerJsClient.GreetApi = factory(root.SwaggerJsClient.ApiClient); 29 | } 30 | }(this, function(ApiClient) { 31 | 'use strict'; 32 | 33 | /** 34 | * Greet service. 35 | * @module api/GreetApi 36 | * @version 1.0.0 37 | */ 38 | 39 | /** 40 | * Constructs a new GreetApi. 41 | * @alias module:api/GreetApi 42 | * @class 43 | * @param {module:ApiClient} [apiClient] Optional API client implementation to use, 44 | * default to {@link module:ApiClient#instance} if unspecified. 45 | */ 46 | var exports = function(apiClient) { 47 | this.apiClient = apiClient || ApiClient.instance; 48 | 49 | 50 | /** 51 | * Callback function to receive the result of the ping operation. 52 | * @callback module:api/GreetApi~pingCallback 53 | * @param {String} error Error message, if any. 54 | * @param {Object} data The data returned by the service call. 55 | * @param {String} response The complete HTTP response. 56 | */ 57 | 58 | /** 59 | * @param {module:api/GreetApi~pingCallback} callback The callback function, accepting three arguments: error, data, response 60 | * data is of type: {@link Object} 61 | */ 62 | this.ping = function(callback) { 63 | var postBody = null; 64 | 65 | 66 | var pathParams = { 67 | }; 68 | var queryParams = { 69 | }; 70 | var collectionQueryParams = { 71 | }; 72 | var headerParams = { 73 | }; 74 | var formParams = { 75 | }; 76 | 77 | var authNames = []; 78 | var contentTypes = ['application/json']; 79 | var accepts = ['application/json']; 80 | var returnType = Object; 81 | 82 | return this.apiClient.callApi( 83 | '/user/ping', 'GET', 84 | pathParams, queryParams, collectionQueryParams, headerParams, formParams, postBody, 85 | authNames, contentTypes, accepts, returnType, callback 86 | ); 87 | } 88 | }; 89 | 90 | return exports; 91 | })); 92 | -------------------------------------------------------------------------------- /example/clients/javascript/src/api/UserApiApi.js: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) 4 | * 5 | * OpenAPI spec version: 6 | * 7 | * NOTE: This class is auto generated by the swagger code generator program. 8 | * https://github.com/swagger-api/swagger-codegen.git 9 | * 10 | * Swagger Codegen version: 2.4.18 11 | * 12 | * Do not edit the class manually. 13 | * 14 | */ 15 | 16 | (function(root, factory) { 17 | if (typeof define === 'function' && define.amd) { 18 | // AMD. Register as an anonymous module. 19 | define(['ApiClient', 'model/LoginReq', 'model/RegisterReq', 'model/UserInfoReply', 'model/UserInfoReq', 'model/UserSearchReply', 'model/UserSearchReq'], factory); 20 | } else if (typeof module === 'object' && module.exports) { 21 | // CommonJS-like environments that support module.exports, like Node. 22 | module.exports = factory(require('../ApiClient'), require('../model/LoginReq'), require('../model/RegisterReq'), require('../model/UserInfoReply'), require('../model/UserInfoReq'), require('../model/UserSearchReply'), require('../model/UserSearchReq')); 23 | } else { 24 | // Browser globals (root is window) 25 | if (!root.SwaggerJsClient) { 26 | root.SwaggerJsClient = {}; 27 | } 28 | root.SwaggerJsClient.UserApiApi = factory(root.SwaggerJsClient.ApiClient, root.SwaggerJsClient.LoginReq, root.SwaggerJsClient.RegisterReq, root.SwaggerJsClient.UserInfoReply, root.SwaggerJsClient.UserInfoReq, root.SwaggerJsClient.UserSearchReply, root.SwaggerJsClient.UserSearchReq); 29 | } 30 | }(this, function(ApiClient, LoginReq, RegisterReq, UserInfoReply, UserInfoReq, UserSearchReply, UserSearchReq) { 31 | 'use strict'; 32 | 33 | /** 34 | * UserApi service. 35 | * @module api/UserApiApi 36 | * @version 1.0.0 37 | */ 38 | 39 | /** 40 | * Constructs a new UserApiApi. 41 | * @alias module:api/UserApiApi 42 | * @class 43 | * @param {module:ApiClient} [apiClient] Optional API client implementation to use, 44 | * default to {@link module:ApiClient#instance} if unspecified. 45 | */ 46 | var exports = function(apiClient) { 47 | this.apiClient = apiClient || ApiClient.instance; 48 | 49 | 50 | /** 51 | * Callback function to receive the result of the getUserInfo operation. 52 | * @callback module:api/UserApiApi~getUserInfoCallback 53 | * @param {String} error Error message, if any. 54 | * @param {module:model/UserInfoReply} data The data returned by the service call. 55 | * @param {String} response The complete HTTP response. 56 | */ 57 | 58 | /** 59 | * 获取用户信息 60 | * @param {String} id 61 | * @param {module:model/UserInfoReq} body 62 | * @param {module:api/UserApiApi~getUserInfoCallback} callback The callback function, accepting three arguments: error, data, response 63 | * data is of type: {@link module:model/UserInfoReply} 64 | */ 65 | this.getUserInfo = function(id, body, callback) { 66 | var postBody = body; 67 | 68 | // verify the required parameter 'id' is set 69 | if (id === undefined || id === null) { 70 | throw new Error("Missing the required parameter 'id' when calling getUserInfo"); 71 | } 72 | 73 | // verify the required parameter 'body' is set 74 | if (body === undefined || body === null) { 75 | throw new Error("Missing the required parameter 'body' when calling getUserInfo"); 76 | } 77 | 78 | 79 | var pathParams = { 80 | 'id': id 81 | }; 82 | var queryParams = { 83 | }; 84 | var collectionQueryParams = { 85 | }; 86 | var headerParams = { 87 | }; 88 | var formParams = { 89 | }; 90 | 91 | var authNames = []; 92 | var contentTypes = ['application/json']; 93 | var accepts = ['application/json']; 94 | var returnType = UserInfoReply; 95 | 96 | return this.apiClient.callApi( 97 | '/api/user/{id}', 'GET', 98 | pathParams, queryParams, collectionQueryParams, headerParams, formParams, postBody, 99 | authNames, contentTypes, accepts, returnType, callback 100 | ); 101 | } 102 | 103 | /** 104 | * Callback function to receive the result of the login operation. 105 | * @callback module:api/UserApiApi~loginCallback 106 | * @param {String} error Error message, if any. 107 | * @param {Object} data The data returned by the service call. 108 | * @param {String} response The complete HTTP response. 109 | */ 110 | 111 | /** 112 | * 登录 113 | * @param {module:model/LoginReq} body 114 | * @param {module:api/UserApiApi~loginCallback} callback The callback function, accepting three arguments: error, data, response 115 | * data is of type: {@link Object} 116 | */ 117 | this.login = function(body, callback) { 118 | var postBody = body; 119 | 120 | // verify the required parameter 'body' is set 121 | if (body === undefined || body === null) { 122 | throw new Error("Missing the required parameter 'body' when calling login"); 123 | } 124 | 125 | 126 | var pathParams = { 127 | }; 128 | var queryParams = { 129 | }; 130 | var collectionQueryParams = { 131 | }; 132 | var headerParams = { 133 | }; 134 | var formParams = { 135 | }; 136 | 137 | var authNames = []; 138 | var contentTypes = ['application/json']; 139 | var accepts = ['application/json']; 140 | var returnType = Object; 141 | 142 | return this.apiClient.callApi( 143 | '/api/user/login', 'POST', 144 | pathParams, queryParams, collectionQueryParams, headerParams, formParams, postBody, 145 | authNames, contentTypes, accepts, returnType, callback 146 | ); 147 | } 148 | 149 | /** 150 | * Callback function to receive the result of the register operation. 151 | * @callback module:api/UserApiApi~registerCallback 152 | * @param {String} error Error message, if any. 153 | * @param {Object} data The data returned by the service call. 154 | * @param {String} response The complete HTTP response. 155 | */ 156 | 157 | /** 158 | * 注册 159 | * 注册一个用户 160 | * @param {module:model/RegisterReq} body 161 | * @param {module:api/UserApiApi~registerCallback} callback The callback function, accepting three arguments: error, data, response 162 | * data is of type: {@link Object} 163 | */ 164 | this.register = function(body, callback) { 165 | var postBody = body; 166 | 167 | // verify the required parameter 'body' is set 168 | if (body === undefined || body === null) { 169 | throw new Error("Missing the required parameter 'body' when calling register"); 170 | } 171 | 172 | 173 | var pathParams = { 174 | }; 175 | var queryParams = { 176 | }; 177 | var collectionQueryParams = { 178 | }; 179 | var headerParams = { 180 | }; 181 | var formParams = { 182 | }; 183 | 184 | var authNames = []; 185 | var contentTypes = ['application/json']; 186 | var accepts = ['application/json']; 187 | var returnType = Object; 188 | 189 | return this.apiClient.callApi( 190 | '/api/user/register', 'POST', 191 | pathParams, queryParams, collectionQueryParams, headerParams, formParams, postBody, 192 | authNames, contentTypes, accepts, returnType, callback 193 | ); 194 | } 195 | 196 | /** 197 | * Callback function to receive the result of the searchUser operation. 198 | * @callback module:api/UserApiApi~searchUserCallback 199 | * @param {String} error Error message, if any. 200 | * @param {module:model/UserSearchReply} data The data returned by the service call. 201 | * @param {String} response The complete HTTP response. 202 | */ 203 | 204 | /** 205 | * 用户搜索 206 | * @param {module:model/UserSearchReq} body 207 | * @param {module:api/UserApiApi~searchUserCallback} callback The callback function, accepting three arguments: error, data, response 208 | * data is of type: {@link module:model/UserSearchReply} 209 | */ 210 | this.searchUser = function(body, callback) { 211 | var postBody = body; 212 | 213 | // verify the required parameter 'body' is set 214 | if (body === undefined || body === null) { 215 | throw new Error("Missing the required parameter 'body' when calling searchUser"); 216 | } 217 | 218 | 219 | var pathParams = { 220 | }; 221 | var queryParams = { 222 | }; 223 | var collectionQueryParams = { 224 | }; 225 | var headerParams = { 226 | }; 227 | var formParams = { 228 | }; 229 | 230 | var authNames = []; 231 | var contentTypes = ['application/json']; 232 | var accepts = ['application/json']; 233 | var returnType = UserSearchReply; 234 | 235 | return this.apiClient.callApi( 236 | '/api/user/search', 'GET', 237 | pathParams, queryParams, collectionQueryParams, headerParams, formParams, postBody, 238 | authNames, contentTypes, accepts, returnType, callback 239 | ); 240 | } 241 | }; 242 | 243 | return exports; 244 | })); 245 | -------------------------------------------------------------------------------- /example/clients/javascript/src/index.js: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) 4 | * 5 | * OpenAPI spec version: 6 | * 7 | * NOTE: This class is auto generated by the swagger code generator program. 8 | * https://github.com/swagger-api/swagger-codegen.git 9 | * 10 | * Swagger Codegen version: 2.4.18 11 | * 12 | * Do not edit the class manually. 13 | * 14 | */ 15 | 16 | (function(factory) { 17 | if (typeof define === 'function' && define.amd) { 18 | // AMD. Register as an anonymous module. 19 | define(['ApiClient', 'model/LoginReq', 'model/RegisterReq', 'model/UserInfoReply', 'model/UserInfoReq', 'model/UserSearchReply', 'model/UserSearchReq', 'api/GreetApi', 'api/UserApiApi'], factory); 20 | } else if (typeof module === 'object' && module.exports) { 21 | // CommonJS-like environments that support module.exports, like Node. 22 | module.exports = factory(require('./ApiClient'), require('./model/LoginReq'), require('./model/RegisterReq'), require('./model/UserInfoReply'), require('./model/UserInfoReq'), require('./model/UserSearchReply'), require('./model/UserSearchReq'), require('./api/GreetApi'), require('./api/UserApiApi')); 23 | } 24 | }(function(ApiClient, LoginReq, RegisterReq, UserInfoReply, UserInfoReq, UserSearchReply, UserSearchReq, GreetApi, UserApiApi) { 25 | 'use strict'; 26 | 27 | /** 28 | * ERROR_UNKNOWN.
29 | * The index module provides access to constructors for all the classes which comprise the public API. 30 | *

31 | * An AMD (recommended!) or CommonJS application will generally do something equivalent to the following: 32 | *

 33 |    * var SwaggerJsClient = require('index'); // See note below*.
 34 |    * var xxxSvc = new SwaggerJsClient.XxxApi(); // Allocate the API class we're going to use.
 35 |    * var yyyModel = new SwaggerJsClient.Yyy(); // Construct a model instance.
 36 |    * yyyModel.someProperty = 'someValue';
 37 |    * ...
 38 |    * var zzz = xxxSvc.doSomething(yyyModel); // Invoke the service.
 39 |    * ...
 40 |    * 
41 | * *NOTE: For a top-level AMD script, use require(['index'], function(){...}) 42 | * and put the application logic within the callback function. 43 | *

44 | *

45 | * A non-AMD browser application (discouraged) might do something like this: 46 | *

 47 |    * var xxxSvc = new SwaggerJsClient.XxxApi(); // Allocate the API class we're going to use.
 48 |    * var yyy = new SwaggerJsClient.Yyy(); // Construct a model instance.
 49 |    * yyyModel.someProperty = 'someValue';
 50 |    * ...
 51 |    * var zzz = xxxSvc.doSomething(yyyModel); // Invoke the service.
 52 |    * ...
 53 |    * 
54 | *

55 | * @module index 56 | * @version 1.0.0 57 | */ 58 | var exports = { 59 | /** 60 | * The ApiClient constructor. 61 | * @property {module:ApiClient} 62 | */ 63 | ApiClient: ApiClient, 64 | /** 65 | * The LoginReq model constructor. 66 | * @property {module:model/LoginReq} 67 | */ 68 | LoginReq: LoginReq, 69 | /** 70 | * The RegisterReq model constructor. 71 | * @property {module:model/RegisterReq} 72 | */ 73 | RegisterReq: RegisterReq, 74 | /** 75 | * The UserInfoReply model constructor. 76 | * @property {module:model/UserInfoReply} 77 | */ 78 | UserInfoReply: UserInfoReply, 79 | /** 80 | * The UserInfoReq model constructor. 81 | * @property {module:model/UserInfoReq} 82 | */ 83 | UserInfoReq: UserInfoReq, 84 | /** 85 | * The UserSearchReply model constructor. 86 | * @property {module:model/UserSearchReply} 87 | */ 88 | UserSearchReply: UserSearchReply, 89 | /** 90 | * The UserSearchReq model constructor. 91 | * @property {module:model/UserSearchReq} 92 | */ 93 | UserSearchReq: UserSearchReq, 94 | /** 95 | * The GreetApi service constructor. 96 | * @property {module:api/GreetApi} 97 | */ 98 | GreetApi: GreetApi, 99 | /** 100 | * The UserApiApi service constructor. 101 | * @property {module:api/UserApiApi} 102 | */ 103 | UserApiApi: UserApiApi 104 | }; 105 | 106 | return exports; 107 | })); 108 | -------------------------------------------------------------------------------- /example/clients/javascript/src/model/LoginReq.js: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) 4 | * 5 | * OpenAPI spec version: 6 | * 7 | * NOTE: This class is auto generated by the swagger code generator program. 8 | * https://github.com/swagger-api/swagger-codegen.git 9 | * 10 | * Swagger Codegen version: 2.4.18 11 | * 12 | * Do not edit the class manually. 13 | * 14 | */ 15 | 16 | (function(root, factory) { 17 | if (typeof define === 'function' && define.amd) { 18 | // AMD. Register as an anonymous module. 19 | define(['ApiClient'], factory); 20 | } else if (typeof module === 'object' && module.exports) { 21 | // CommonJS-like environments that support module.exports, like Node. 22 | module.exports = factory(require('../ApiClient')); 23 | } else { 24 | // Browser globals (root is window) 25 | if (!root.SwaggerJsClient) { 26 | root.SwaggerJsClient = {}; 27 | } 28 | root.SwaggerJsClient.LoginReq = factory(root.SwaggerJsClient.ApiClient); 29 | } 30 | }(this, function(ApiClient) { 31 | 'use strict'; 32 | 33 | /** 34 | * The LoginReq model module. 35 | * @module model/LoginReq 36 | * @version 1.0.0 37 | */ 38 | 39 | /** 40 | * Constructs a new LoginReq. 41 | * @alias module:model/LoginReq 42 | * @class 43 | */ 44 | var exports = function() { 45 | }; 46 | 47 | /** 48 | * Constructs a LoginReq from a plain JavaScript object, optionally creating a new instance. 49 | * Copies all relevant properties from data to obj if supplied or a new instance if not. 50 | * @param {Object} data The plain JavaScript object bearing properties of interest. 51 | * @param {module:model/LoginReq} obj Optional instance to populate. 52 | * @return {module:model/LoginReq} The populated LoginReq instance. 53 | */ 54 | exports.constructFromObject = function(data, obj) { 55 | if (data) { 56 | obj = obj || new exports(); 57 | if (data.hasOwnProperty('username')) 58 | obj.username = ApiClient.convertToType(data['username'], 'String'); 59 | if (data.hasOwnProperty('password')) 60 | obj.password = ApiClient.convertToType(data['password'], 'String'); 61 | } 62 | return obj; 63 | } 64 | 65 | /** 66 | * @member {String} username 67 | */ 68 | exports.prototype.username = undefined; 69 | 70 | /** 71 | * @member {String} password 72 | */ 73 | exports.prototype.password = undefined; 74 | 75 | 76 | return exports; 77 | 78 | })); 79 | -------------------------------------------------------------------------------- /example/clients/javascript/src/model/RegisterReq.js: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) 4 | * 5 | * OpenAPI spec version: 6 | * 7 | * NOTE: This class is auto generated by the swagger code generator program. 8 | * https://github.com/swagger-api/swagger-codegen.git 9 | * 10 | * Swagger Codegen version: 2.4.18 11 | * 12 | * Do not edit the class manually. 13 | * 14 | */ 15 | 16 | (function(root, factory) { 17 | if (typeof define === 'function' && define.amd) { 18 | // AMD. Register as an anonymous module. 19 | define(['ApiClient'], factory); 20 | } else if (typeof module === 'object' && module.exports) { 21 | // CommonJS-like environments that support module.exports, like Node. 22 | module.exports = factory(require('../ApiClient')); 23 | } else { 24 | // Browser globals (root is window) 25 | if (!root.SwaggerJsClient) { 26 | root.SwaggerJsClient = {}; 27 | } 28 | root.SwaggerJsClient.RegisterReq = factory(root.SwaggerJsClient.ApiClient); 29 | } 30 | }(this, function(ApiClient) { 31 | 'use strict'; 32 | 33 | /** 34 | * The RegisterReq model module. 35 | * @module model/RegisterReq 36 | * @version 1.0.0 37 | */ 38 | 39 | /** 40 | * Constructs a new RegisterReq. 41 | * @alias module:model/RegisterReq 42 | * @class 43 | */ 44 | var exports = function() { 45 | }; 46 | 47 | /** 48 | * Constructs a RegisterReq from a plain JavaScript object, optionally creating a new instance. 49 | * Copies all relevant properties from data to obj if supplied or a new instance if not. 50 | * @param {Object} data The plain JavaScript object bearing properties of interest. 51 | * @param {module:model/RegisterReq} obj Optional instance to populate. 52 | * @return {module:model/RegisterReq} The populated RegisterReq instance. 53 | */ 54 | exports.constructFromObject = function(data, obj) { 55 | if (data) { 56 | obj = obj || new exports(); 57 | if (data.hasOwnProperty('username')) 58 | obj.username = ApiClient.convertToType(data['username'], 'String'); 59 | if (data.hasOwnProperty('password')) 60 | obj.password = ApiClient.convertToType(data['password'], 'String'); 61 | if (data.hasOwnProperty('mobile')) 62 | obj.mobile = ApiClient.convertToType(data['mobile'], 'String'); 63 | } 64 | return obj; 65 | } 66 | 67 | /** 68 | * @member {String} username 69 | */ 70 | exports.prototype.username = undefined; 71 | 72 | /** 73 | * @member {String} password 74 | */ 75 | exports.prototype.password = undefined; 76 | 77 | /** 78 | * @member {String} mobile 79 | */ 80 | exports.prototype.mobile = undefined; 81 | 82 | 83 | return exports; 84 | 85 | })); 86 | -------------------------------------------------------------------------------- /example/clients/javascript/src/model/UserInfoReply.js: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) 4 | * 5 | * OpenAPI spec version: 6 | * 7 | * NOTE: This class is auto generated by the swagger code generator program. 8 | * https://github.com/swagger-api/swagger-codegen.git 9 | * 10 | * Swagger Codegen version: 2.4.18 11 | * 12 | * Do not edit the class manually. 13 | * 14 | */ 15 | 16 | (function(root, factory) { 17 | if (typeof define === 'function' && define.amd) { 18 | // AMD. Register as an anonymous module. 19 | define(['ApiClient'], factory); 20 | } else if (typeof module === 'object' && module.exports) { 21 | // CommonJS-like environments that support module.exports, like Node. 22 | module.exports = factory(require('../ApiClient')); 23 | } else { 24 | // Browser globals (root is window) 25 | if (!root.SwaggerJsClient) { 26 | root.SwaggerJsClient = {}; 27 | } 28 | root.SwaggerJsClient.UserInfoReply = factory(root.SwaggerJsClient.ApiClient); 29 | } 30 | }(this, function(ApiClient) { 31 | 'use strict'; 32 | 33 | /** 34 | * The UserInfoReply model module. 35 | * @module model/UserInfoReply 36 | * @version 1.0.0 37 | */ 38 | 39 | /** 40 | * Constructs a new UserInfoReply. 41 | * @alias module:model/UserInfoReply 42 | * @class 43 | */ 44 | var exports = function() { 45 | }; 46 | 47 | /** 48 | * Constructs a UserInfoReply from a plain JavaScript object, optionally creating a new instance. 49 | * Copies all relevant properties from data to obj if supplied or a new instance if not. 50 | * @param {Object} data The plain JavaScript object bearing properties of interest. 51 | * @param {module:model/UserInfoReply} obj Optional instance to populate. 52 | * @return {module:model/UserInfoReply} The populated UserInfoReply instance. 53 | */ 54 | exports.constructFromObject = function(data, obj) { 55 | if (data) { 56 | obj = obj || new exports(); 57 | if (data.hasOwnProperty('name')) 58 | obj.name = ApiClient.convertToType(data['name'], 'String'); 59 | if (data.hasOwnProperty('age')) 60 | obj.age = ApiClient.convertToType(data['age'], 'Number'); 61 | if (data.hasOwnProperty('birthday')) 62 | obj.birthday = ApiClient.convertToType(data['birthday'], 'String'); 63 | if (data.hasOwnProperty('description')) 64 | obj.description = ApiClient.convertToType(data['description'], 'String'); 65 | if (data.hasOwnProperty('tag')) 66 | obj.tag = ApiClient.convertToType(data['tag'], ['String']); 67 | } 68 | return obj; 69 | } 70 | 71 | /** 72 | * @member {String} name 73 | */ 74 | exports.prototype.name = undefined; 75 | 76 | /** 77 | * @member {Number} age 78 | */ 79 | exports.prototype.age = undefined; 80 | 81 | /** 82 | * @member {String} birthday 83 | */ 84 | exports.prototype.birthday = undefined; 85 | 86 | /** 87 | * @member {String} description 88 | */ 89 | exports.prototype.description = undefined; 90 | 91 | /** 92 | * @member {Array.} tag 93 | */ 94 | exports.prototype.tag = undefined; 95 | 96 | 97 | return exports; 98 | 99 | })); 100 | -------------------------------------------------------------------------------- /example/clients/javascript/src/model/UserInfoReq.js: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) 4 | * 5 | * OpenAPI spec version: 6 | * 7 | * NOTE: This class is auto generated by the swagger code generator program. 8 | * https://github.com/swagger-api/swagger-codegen.git 9 | * 10 | * Swagger Codegen version: 2.4.18 11 | * 12 | * Do not edit the class manually. 13 | * 14 | */ 15 | 16 | (function(root, factory) { 17 | if (typeof define === 'function' && define.amd) { 18 | // AMD. Register as an anonymous module. 19 | define(['ApiClient'], factory); 20 | } else if (typeof module === 'object' && module.exports) { 21 | // CommonJS-like environments that support module.exports, like Node. 22 | module.exports = factory(require('../ApiClient')); 23 | } else { 24 | // Browser globals (root is window) 25 | if (!root.SwaggerJsClient) { 26 | root.SwaggerJsClient = {}; 27 | } 28 | root.SwaggerJsClient.UserInfoReq = factory(root.SwaggerJsClient.ApiClient); 29 | } 30 | }(this, function(ApiClient) { 31 | 'use strict'; 32 | 33 | /** 34 | * The UserInfoReq model module. 35 | * @module model/UserInfoReq 36 | * @version 1.0.0 37 | */ 38 | 39 | /** 40 | * Constructs a new UserInfoReq. 41 | * @alias module:model/UserInfoReq 42 | * @class 43 | */ 44 | var exports = function() { 45 | }; 46 | 47 | /** 48 | * Constructs a UserInfoReq from a plain JavaScript object, optionally creating a new instance. 49 | * Copies all relevant properties from data to obj if supplied or a new instance if not. 50 | * @param {Object} data The plain JavaScript object bearing properties of interest. 51 | * @param {module:model/UserInfoReq} obj Optional instance to populate. 52 | * @return {module:model/UserInfoReq} The populated UserInfoReq instance. 53 | */ 54 | exports.constructFromObject = function(data, obj) { 55 | if (data) { 56 | obj = obj || new exports(); 57 | if (data.hasOwnProperty('id')) 58 | obj.id = ApiClient.convertToType(data['id'], 'String'); 59 | } 60 | return obj; 61 | } 62 | 63 | /** 64 | * @member {String} id 65 | */ 66 | exports.prototype.id = undefined; 67 | 68 | 69 | return exports; 70 | 71 | })); 72 | -------------------------------------------------------------------------------- /example/clients/javascript/src/model/UserSearchReply.js: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) 4 | * 5 | * OpenAPI spec version: 6 | * 7 | * NOTE: This class is auto generated by the swagger code generator program. 8 | * https://github.com/swagger-api/swagger-codegen.git 9 | * 10 | * Swagger Codegen version: 2.4.18 11 | * 12 | * Do not edit the class manually. 13 | * 14 | */ 15 | 16 | (function(root, factory) { 17 | if (typeof define === 'function' && define.amd) { 18 | // AMD. Register as an anonymous module. 19 | define(['ApiClient', 'model/UserInfoReply'], factory); 20 | } else if (typeof module === 'object' && module.exports) { 21 | // CommonJS-like environments that support module.exports, like Node. 22 | module.exports = factory(require('../ApiClient'), require('./UserInfoReply')); 23 | } else { 24 | // Browser globals (root is window) 25 | if (!root.SwaggerJsClient) { 26 | root.SwaggerJsClient = {}; 27 | } 28 | root.SwaggerJsClient.UserSearchReply = factory(root.SwaggerJsClient.ApiClient, root.SwaggerJsClient.UserInfoReply); 29 | } 30 | }(this, function(ApiClient, UserInfoReply) { 31 | 'use strict'; 32 | 33 | /** 34 | * The UserSearchReply model module. 35 | * @module model/UserSearchReply 36 | * @version 1.0.0 37 | */ 38 | 39 | /** 40 | * Constructs a new UserSearchReply. 41 | * @alias module:model/UserSearchReply 42 | * @class 43 | */ 44 | var exports = function() { 45 | }; 46 | 47 | /** 48 | * Constructs a UserSearchReply from a plain JavaScript object, optionally creating a new instance. 49 | * Copies all relevant properties from data to obj if supplied or a new instance if not. 50 | * @param {Object} data The plain JavaScript object bearing properties of interest. 51 | * @param {module:model/UserSearchReply} obj Optional instance to populate. 52 | * @return {module:model/UserSearchReply} The populated UserSearchReply instance. 53 | */ 54 | exports.constructFromObject = function(data, obj) { 55 | if (data) { 56 | obj = obj || new exports(); 57 | if (data.hasOwnProperty('KeyWord')) 58 | obj.keyWord = ApiClient.convertToType(data['KeyWord'], [UserInfoReply]); 59 | } 60 | return obj; 61 | } 62 | 63 | /** 64 | * @member {Array.} keyWord 65 | */ 66 | exports.prototype.keyWord = undefined; 67 | 68 | 69 | return exports; 70 | 71 | })); 72 | -------------------------------------------------------------------------------- /example/clients/javascript/src/model/UserSearchReq.js: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) 4 | * 5 | * OpenAPI spec version: 6 | * 7 | * NOTE: This class is auto generated by the swagger code generator program. 8 | * https://github.com/swagger-api/swagger-codegen.git 9 | * 10 | * Swagger Codegen version: 2.4.18 11 | * 12 | * Do not edit the class manually. 13 | * 14 | */ 15 | 16 | (function(root, factory) { 17 | if (typeof define === 'function' && define.amd) { 18 | // AMD. Register as an anonymous module. 19 | define(['ApiClient'], factory); 20 | } else if (typeof module === 'object' && module.exports) { 21 | // CommonJS-like environments that support module.exports, like Node. 22 | module.exports = factory(require('../ApiClient')); 23 | } else { 24 | // Browser globals (root is window) 25 | if (!root.SwaggerJsClient) { 26 | root.SwaggerJsClient = {}; 27 | } 28 | root.SwaggerJsClient.UserSearchReq = factory(root.SwaggerJsClient.ApiClient); 29 | } 30 | }(this, function(ApiClient) { 31 | 'use strict'; 32 | 33 | /** 34 | * The UserSearchReq model module. 35 | * @module model/UserSearchReq 36 | * @version 1.0.0 37 | */ 38 | 39 | /** 40 | * Constructs a new UserSearchReq. 41 | * @alias module:model/UserSearchReq 42 | * @class 43 | */ 44 | var exports = function() { 45 | }; 46 | 47 | /** 48 | * Constructs a UserSearchReq from a plain JavaScript object, optionally creating a new instance. 49 | * Copies all relevant properties from data to obj if supplied or a new instance if not. 50 | * @param {Object} data The plain JavaScript object bearing properties of interest. 51 | * @param {module:model/UserSearchReq} obj Optional instance to populate. 52 | * @return {module:model/UserSearchReq} The populated UserSearchReq instance. 53 | */ 54 | exports.constructFromObject = function(data, obj) { 55 | if (data) { 56 | obj = obj || new exports(); 57 | if (data.hasOwnProperty('keyWord')) 58 | obj.keyWord = ApiClient.convertToType(data['keyWord'], 'String'); 59 | } 60 | return obj; 61 | } 62 | 63 | /** 64 | * @member {String} keyWord 65 | */ 66 | exports.prototype.keyWord = undefined; 67 | 68 | 69 | return exports; 70 | 71 | })); 72 | -------------------------------------------------------------------------------- /example/clients/javascript/test/api/GreetApi.spec.js: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) 4 | * 5 | * OpenAPI spec version: 6 | * 7 | * NOTE: This class is auto generated by the swagger code generator program. 8 | * https://github.com/swagger-api/swagger-codegen.git 9 | * 10 | * Swagger Codegen version: 2.4.18 11 | * 12 | * Do not edit the class manually. 13 | * 14 | */ 15 | 16 | (function(root, factory) { 17 | if (typeof define === 'function' && define.amd) { 18 | // AMD. 19 | define(['expect.js', '../../src/index'], factory); 20 | } else if (typeof module === 'object' && module.exports) { 21 | // CommonJS-like environments that support module.exports, like Node. 22 | factory(require('expect.js'), require('../../src/index')); 23 | } else { 24 | // Browser globals (root is window) 25 | factory(root.expect, root.SwaggerJsClient); 26 | } 27 | }(this, function(expect, SwaggerJsClient) { 28 | 'use strict'; 29 | 30 | var instance; 31 | 32 | beforeEach(function() { 33 | instance = new SwaggerJsClient.GreetApi(); 34 | }); 35 | 36 | describe('(package)', function() { 37 | describe('GreetApi', function() { 38 | describe('ping', function() { 39 | it('should call ping successfully', function(done) { 40 | // TODO: uncomment ping call and complete the assertions 41 | /* 42 | 43 | instance.ping(function(error, data, response) { 44 | if (error) { 45 | done(error); 46 | return; 47 | } 48 | // TODO: update response assertions 49 | expect(data).to.be.a(Object); 50 | // expect(data).to.be(null); 51 | 52 | done(); 53 | }); 54 | */ 55 | // TODO: uncomment and complete method invocation above, then delete this line and the next: 56 | done(); 57 | }); 58 | }); 59 | }); 60 | }); 61 | 62 | })); 63 | -------------------------------------------------------------------------------- /example/clients/javascript/test/api/UserApiApi.spec.js: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) 4 | * 5 | * OpenAPI spec version: 6 | * 7 | * NOTE: This class is auto generated by the swagger code generator program. 8 | * https://github.com/swagger-api/swagger-codegen.git 9 | * 10 | * Swagger Codegen version: 2.4.18 11 | * 12 | * Do not edit the class manually. 13 | * 14 | */ 15 | 16 | (function(root, factory) { 17 | if (typeof define === 'function' && define.amd) { 18 | // AMD. 19 | define(['expect.js', '../../src/index'], factory); 20 | } else if (typeof module === 'object' && module.exports) { 21 | // CommonJS-like environments that support module.exports, like Node. 22 | factory(require('expect.js'), require('../../src/index')); 23 | } else { 24 | // Browser globals (root is window) 25 | factory(root.expect, root.SwaggerJsClient); 26 | } 27 | }(this, function(expect, SwaggerJsClient) { 28 | 'use strict'; 29 | 30 | var instance; 31 | 32 | beforeEach(function() { 33 | instance = new SwaggerJsClient.UserApiApi(); 34 | }); 35 | 36 | describe('(package)', function() { 37 | describe('UserApiApi', function() { 38 | describe('getUserInfo', function() { 39 | it('should call getUserInfo successfully', function(done) { 40 | // TODO: uncomment, update parameter values for getUserInfo call and complete the assertions 41 | /* 42 | var id = "id_example"; 43 | var body = new SwaggerJsClient.UserInfoReq(); 44 | body.id = ""; 45 | 46 | instance.getUserInfo(id, body, function(error, data, response) { 47 | if (error) { 48 | done(error); 49 | return; 50 | } 51 | // TODO: update response assertions 52 | expect(data).to.be.a(SwaggerJsClient.UserInfoReply); 53 | expect(data.name).to.be.a('string'); 54 | expect(data.name).to.be(""); 55 | expect(data.age).to.be.a('number'); 56 | expect(data.age).to.be(0); 57 | expect(data.birthday).to.be.a('string'); 58 | expect(data.birthday).to.be(""); 59 | expect(data.description).to.be.a('string'); 60 | expect(data.description).to.be(""); 61 | { 62 | let dataCtr = data.tag; 63 | expect(dataCtr).to.be.an(Array); 64 | expect(dataCtr).to.not.be.empty(); 65 | for (let p in dataCtr) { 66 | let data = dataCtr[p]; 67 | expect(data).to.be.a('string'); 68 | expect(data).to.be(""); 69 | } 70 | } 71 | 72 | done(); 73 | }); 74 | */ 75 | // TODO: uncomment and complete method invocation above, then delete this line and the next: 76 | done(); 77 | }); 78 | }); 79 | describe('login', function() { 80 | it('should call login successfully', function(done) { 81 | // TODO: uncomment, update parameter values for login call and complete the assertions 82 | /* 83 | var body = new SwaggerJsClient.LoginReq(); 84 | body.username = ""; 85 | body.password = ""; 86 | 87 | instance.login(body, function(error, data, response) { 88 | if (error) { 89 | done(error); 90 | return; 91 | } 92 | // TODO: update response assertions 93 | expect(data).to.be.a(Object); 94 | // expect(data).to.be(null); 95 | 96 | done(); 97 | }); 98 | */ 99 | // TODO: uncomment and complete method invocation above, then delete this line and the next: 100 | done(); 101 | }); 102 | }); 103 | describe('register', function() { 104 | it('should call register successfully', function(done) { 105 | // TODO: uncomment, update parameter values for register call and complete the assertions 106 | /* 107 | var body = new SwaggerJsClient.RegisterReq(); 108 | body.username = ""; 109 | body.password = ""; 110 | body.mobile = ""; 111 | 112 | instance.register(body, function(error, data, response) { 113 | if (error) { 114 | done(error); 115 | return; 116 | } 117 | // TODO: update response assertions 118 | expect(data).to.be.a(Object); 119 | // expect(data).to.be(null); 120 | 121 | done(); 122 | }); 123 | */ 124 | // TODO: uncomment and complete method invocation above, then delete this line and the next: 125 | done(); 126 | }); 127 | }); 128 | describe('searchUser', function() { 129 | it('should call searchUser successfully', function(done) { 130 | // TODO: uncomment, update parameter values for searchUser call and complete the assertions 131 | /* 132 | var body = new SwaggerJsClient.UserSearchReq(); 133 | body.keyWord = ""; 134 | 135 | instance.searchUser(body, function(error, data, response) { 136 | if (error) { 137 | done(error); 138 | return; 139 | } 140 | // TODO: update response assertions 141 | expect(data).to.be.a(SwaggerJsClient.UserSearchReply); 142 | { 143 | let dataCtr = data.keyWord; 144 | expect(dataCtr).to.be.an(Array); 145 | expect(dataCtr).to.not.be.empty(); 146 | for (let p in dataCtr) { 147 | let data = dataCtr[p]; 148 | expect(data).to.be.a(SwaggerJsClient.UserInfoReply); 149 | expect(data.name).to.be.a('string'); 150 | expect(data.name).to.be(""); 151 | expect(data.age).to.be.a('number'); 152 | expect(data.age).to.be(0); 153 | expect(data.birthday).to.be.a('string'); 154 | expect(data.birthday).to.be(""); 155 | expect(data.description).to.be.a('string'); 156 | expect(data.description).to.be(""); 157 | { 158 | let dataCtr = data.tag; 159 | expect(dataCtr).to.be.an(Array); 160 | expect(dataCtr).to.not.be.empty(); 161 | for (let p in dataCtr) { 162 | let data = dataCtr[p]; 163 | expect(data).to.be.a('string'); 164 | expect(data).to.be(""); 165 | } 166 | } 167 | 168 | } 169 | } 170 | 171 | done(); 172 | }); 173 | */ 174 | // TODO: uncomment and complete method invocation above, then delete this line and the next: 175 | done(); 176 | }); 177 | }); 178 | }); 179 | }); 180 | 181 | })); 182 | -------------------------------------------------------------------------------- /example/clients/javascript/test/assert-equals.js: -------------------------------------------------------------------------------- 1 | (function(root, factory) { 2 | if (typeof define === 'function' && define.amd) { 3 | // AMD. 4 | define(factory); 5 | } else if (typeof module === 'object' && module.exports) { 6 | // CommonJS-like environments that support module.exports, like Node. 7 | module.exports = factory(); 8 | } else { 9 | // Browser globals (root is window) 10 | root.assertEquals = factory(); 11 | } 12 | }(this, function() { 13 | 'use strict'; 14 | 15 | var assertEquals = function(expected, actual, ptr) { 16 | if (!ptr) 17 | ptr = ""; 18 | if (actual === expected) 19 | return; 20 | if (expected instanceof Date || actual instanceof Date) { 21 | expected = toISODateString(expected); 22 | actual = toISODateString(actual); 23 | if (actual !== expected) 24 | fail(expected, actual, ptr, "date value incorrect;"); 25 | } 26 | if (!expected || !actual || typeof expected != 'object' && typeof actual != 'object') { 27 | if (typeof actual != typeof expected) 28 | fail(typeof expected, typeof actual, ptr, "value type incorrect;"); 29 | if (actual != expected) 30 | fail(expected, actual, ptr, "value incorrect;"); 31 | } 32 | return checkObject(expected, actual, ptr); 33 | } 34 | 35 | function toISODateString(value) { 36 | if (value instanceof Date) { 37 | // JavaScript's ISO string contains a milliseconds component that must be stripped out. 38 | value = value.toISOString().replace('.000', ''); 39 | } 40 | return value; 41 | } 42 | 43 | function checkObject(expected, actual, ptr) { 44 | if (undefOrNull(expected) || undefOrNull(actual)) 45 | fail(expected, actual, ptr, "missing value;"); 46 | if (typeof expected !== typeof actual) 47 | fail(typeof expected, typeof actual, ptr, "wrong type;"); 48 | if (expected.prototype !== actual.prototype) 49 | fail(expected.prototype, actual.prototype, ptr, "wrong prototype;"); 50 | try { 51 | var expectedKeys = Object.keys(expected); 52 | var actualKeys = Object.keys(actual); 53 | } catch (e) { 54 | fail(expectedKeys, actualKeys, ptr, "wrong keys;"); 55 | } 56 | if (actualKeys.length != expectedKeys.length) 57 | fail(expectedKeys.length, actualKeys.length, ptr, "key count incorrect;"); 58 | expectedKeys.sort(); 59 | actualKeys.sort(); 60 | for (var i = 0; i < expectedKeys.length; i++) { 61 | if (actualKeys[i] != expectedKeys[i]) 62 | fail(expectedKeys, actualKeys, ptr, "wrong keys;"); 63 | } 64 | for (i = 0; i < expectedKeys.length; i++) { 65 | var key = expectedKeys[i]; 66 | assertEquals(expected[key], actual[key], ptr + '/' + key); 67 | } 68 | } 69 | 70 | function undefOrNull(v) { 71 | return v === undefined || v === null; 72 | } 73 | 74 | function fail(expected, actual, ptr, msg) { 75 | var text = ptr + ' ' + msg + " expected: " + expected + ", actual: " + actual; 76 | console.log(text); 77 | throw new Error(text); 78 | } 79 | 80 | return assertEquals; 81 | })); 82 | -------------------------------------------------------------------------------- /example/clients/javascript/test/model/LoginReq.spec.js: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) 4 | * 5 | * OpenAPI spec version: 6 | * 7 | * NOTE: This class is auto generated by the swagger code generator program. 8 | * https://github.com/swagger-api/swagger-codegen.git 9 | * 10 | * Swagger Codegen version: 2.4.18 11 | * 12 | * Do not edit the class manually. 13 | * 14 | */ 15 | 16 | (function(root, factory) { 17 | if (typeof define === 'function' && define.amd) { 18 | // AMD. 19 | define(['expect.js', '../../src/index'], factory); 20 | } else if (typeof module === 'object' && module.exports) { 21 | // CommonJS-like environments that support module.exports, like Node. 22 | factory(require('expect.js'), require('../../src/index')); 23 | } else { 24 | // Browser globals (root is window) 25 | factory(root.expect, root.SwaggerJsClient); 26 | } 27 | }(this, function(expect, SwaggerJsClient) { 28 | 'use strict'; 29 | 30 | var instance; 31 | 32 | describe('(package)', function() { 33 | describe('LoginReq', function() { 34 | beforeEach(function() { 35 | instance = new SwaggerJsClient.LoginReq(); 36 | }); 37 | 38 | it('should create an instance of LoginReq', function() { 39 | // TODO: update the code to test LoginReq 40 | expect(instance).to.be.a(SwaggerJsClient.LoginReq); 41 | }); 42 | 43 | it('should have the property username (base name: "username")', function() { 44 | // TODO: update the code to test the property username 45 | expect(instance).to.have.property('username'); 46 | // expect(instance.username).to.be(expectedValueLiteral); 47 | }); 48 | 49 | it('should have the property password (base name: "password")', function() { 50 | // TODO: update the code to test the property password 51 | expect(instance).to.have.property('password'); 52 | // expect(instance.password).to.be(expectedValueLiteral); 53 | }); 54 | 55 | }); 56 | }); 57 | 58 | })); 59 | -------------------------------------------------------------------------------- /example/clients/javascript/test/model/RegisterReq.spec.js: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) 4 | * 5 | * OpenAPI spec version: 6 | * 7 | * NOTE: This class is auto generated by the swagger code generator program. 8 | * https://github.com/swagger-api/swagger-codegen.git 9 | * 10 | * Swagger Codegen version: 2.4.18 11 | * 12 | * Do not edit the class manually. 13 | * 14 | */ 15 | 16 | (function(root, factory) { 17 | if (typeof define === 'function' && define.amd) { 18 | // AMD. 19 | define(['expect.js', '../../src/index'], factory); 20 | } else if (typeof module === 'object' && module.exports) { 21 | // CommonJS-like environments that support module.exports, like Node. 22 | factory(require('expect.js'), require('../../src/index')); 23 | } else { 24 | // Browser globals (root is window) 25 | factory(root.expect, root.SwaggerJsClient); 26 | } 27 | }(this, function(expect, SwaggerJsClient) { 28 | 'use strict'; 29 | 30 | var instance; 31 | 32 | describe('(package)', function() { 33 | describe('RegisterReq', function() { 34 | beforeEach(function() { 35 | instance = new SwaggerJsClient.RegisterReq(); 36 | }); 37 | 38 | it('should create an instance of RegisterReq', function() { 39 | // TODO: update the code to test RegisterReq 40 | expect(instance).to.be.a(SwaggerJsClient.RegisterReq); 41 | }); 42 | 43 | it('should have the property username (base name: "username")', function() { 44 | // TODO: update the code to test the property username 45 | expect(instance).to.have.property('username'); 46 | // expect(instance.username).to.be(expectedValueLiteral); 47 | }); 48 | 49 | it('should have the property password (base name: "password")', function() { 50 | // TODO: update the code to test the property password 51 | expect(instance).to.have.property('password'); 52 | // expect(instance.password).to.be(expectedValueLiteral); 53 | }); 54 | 55 | it('should have the property mobile (base name: "mobile")', function() { 56 | // TODO: update the code to test the property mobile 57 | expect(instance).to.have.property('mobile'); 58 | // expect(instance.mobile).to.be(expectedValueLiteral); 59 | }); 60 | 61 | }); 62 | }); 63 | 64 | })); 65 | -------------------------------------------------------------------------------- /example/clients/javascript/test/model/UserInfoReply.spec.js: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) 4 | * 5 | * OpenAPI spec version: 6 | * 7 | * NOTE: This class is auto generated by the swagger code generator program. 8 | * https://github.com/swagger-api/swagger-codegen.git 9 | * 10 | * Swagger Codegen version: 2.4.18 11 | * 12 | * Do not edit the class manually. 13 | * 14 | */ 15 | 16 | (function(root, factory) { 17 | if (typeof define === 'function' && define.amd) { 18 | // AMD. 19 | define(['expect.js', '../../src/index'], factory); 20 | } else if (typeof module === 'object' && module.exports) { 21 | // CommonJS-like environments that support module.exports, like Node. 22 | factory(require('expect.js'), require('../../src/index')); 23 | } else { 24 | // Browser globals (root is window) 25 | factory(root.expect, root.SwaggerJsClient); 26 | } 27 | }(this, function(expect, SwaggerJsClient) { 28 | 'use strict'; 29 | 30 | var instance; 31 | 32 | describe('(package)', function() { 33 | describe('UserInfoReply', function() { 34 | beforeEach(function() { 35 | instance = new SwaggerJsClient.UserInfoReply(); 36 | }); 37 | 38 | it('should create an instance of UserInfoReply', function() { 39 | // TODO: update the code to test UserInfoReply 40 | expect(instance).to.be.a(SwaggerJsClient.UserInfoReply); 41 | }); 42 | 43 | it('should have the property name (base name: "name")', function() { 44 | // TODO: update the code to test the property name 45 | expect(instance).to.have.property('name'); 46 | // expect(instance.name).to.be(expectedValueLiteral); 47 | }); 48 | 49 | it('should have the property age (base name: "age")', function() { 50 | // TODO: update the code to test the property age 51 | expect(instance).to.have.property('age'); 52 | // expect(instance.age).to.be(expectedValueLiteral); 53 | }); 54 | 55 | it('should have the property birthday (base name: "birthday")', function() { 56 | // TODO: update the code to test the property birthday 57 | expect(instance).to.have.property('birthday'); 58 | // expect(instance.birthday).to.be(expectedValueLiteral); 59 | }); 60 | 61 | it('should have the property description (base name: "description")', function() { 62 | // TODO: update the code to test the property description 63 | expect(instance).to.have.property('description'); 64 | // expect(instance.description).to.be(expectedValueLiteral); 65 | }); 66 | 67 | it('should have the property tag (base name: "tag")', function() { 68 | // TODO: update the code to test the property tag 69 | expect(instance).to.have.property('tag'); 70 | // expect(instance.tag).to.be(expectedValueLiteral); 71 | }); 72 | 73 | }); 74 | }); 75 | 76 | })); 77 | -------------------------------------------------------------------------------- /example/clients/javascript/test/model/UserInfoReq.spec.js: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) 4 | * 5 | * OpenAPI spec version: 6 | * 7 | * NOTE: This class is auto generated by the swagger code generator program. 8 | * https://github.com/swagger-api/swagger-codegen.git 9 | * 10 | * Swagger Codegen version: 2.4.18 11 | * 12 | * Do not edit the class manually. 13 | * 14 | */ 15 | 16 | (function(root, factory) { 17 | if (typeof define === 'function' && define.amd) { 18 | // AMD. 19 | define(['expect.js', '../../src/index'], factory); 20 | } else if (typeof module === 'object' && module.exports) { 21 | // CommonJS-like environments that support module.exports, like Node. 22 | factory(require('expect.js'), require('../../src/index')); 23 | } else { 24 | // Browser globals (root is window) 25 | factory(root.expect, root.SwaggerJsClient); 26 | } 27 | }(this, function(expect, SwaggerJsClient) { 28 | 'use strict'; 29 | 30 | var instance; 31 | 32 | describe('(package)', function() { 33 | describe('UserInfoReq', function() { 34 | beforeEach(function() { 35 | instance = new SwaggerJsClient.UserInfoReq(); 36 | }); 37 | 38 | it('should create an instance of UserInfoReq', function() { 39 | // TODO: update the code to test UserInfoReq 40 | expect(instance).to.be.a(SwaggerJsClient.UserInfoReq); 41 | }); 42 | 43 | it('should have the property id (base name: "id")', function() { 44 | // TODO: update the code to test the property id 45 | expect(instance).to.have.property('id'); 46 | // expect(instance.id).to.be(expectedValueLiteral); 47 | }); 48 | 49 | }); 50 | }); 51 | 52 | })); 53 | -------------------------------------------------------------------------------- /example/clients/javascript/test/model/UserSearchReply.spec.js: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) 4 | * 5 | * OpenAPI spec version: 6 | * 7 | * NOTE: This class is auto generated by the swagger code generator program. 8 | * https://github.com/swagger-api/swagger-codegen.git 9 | * 10 | * Swagger Codegen version: 2.4.18 11 | * 12 | * Do not edit the class manually. 13 | * 14 | */ 15 | 16 | (function(root, factory) { 17 | if (typeof define === 'function' && define.amd) { 18 | // AMD. 19 | define(['expect.js', '../../src/index'], factory); 20 | } else if (typeof module === 'object' && module.exports) { 21 | // CommonJS-like environments that support module.exports, like Node. 22 | factory(require('expect.js'), require('../../src/index')); 23 | } else { 24 | // Browser globals (root is window) 25 | factory(root.expect, root.SwaggerJsClient); 26 | } 27 | }(this, function(expect, SwaggerJsClient) { 28 | 'use strict'; 29 | 30 | var instance; 31 | 32 | describe('(package)', function() { 33 | describe('UserSearchReply', function() { 34 | beforeEach(function() { 35 | instance = new SwaggerJsClient.UserSearchReply(); 36 | }); 37 | 38 | it('should create an instance of UserSearchReply', function() { 39 | // TODO: update the code to test UserSearchReply 40 | expect(instance).to.be.a(SwaggerJsClient.UserSearchReply); 41 | }); 42 | 43 | it('should have the property keyWord (base name: "KeyWord")', function() { 44 | // TODO: update the code to test the property keyWord 45 | expect(instance).to.have.property('keyWord'); 46 | // expect(instance.keyWord).to.be(expectedValueLiteral); 47 | }); 48 | 49 | }); 50 | }); 51 | 52 | })); 53 | -------------------------------------------------------------------------------- /example/clients/javascript/test/model/UserSearchReq.spec.js: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) 4 | * 5 | * OpenAPI spec version: 6 | * 7 | * NOTE: This class is auto generated by the swagger code generator program. 8 | * https://github.com/swagger-api/swagger-codegen.git 9 | * 10 | * Swagger Codegen version: 2.4.18 11 | * 12 | * Do not edit the class manually. 13 | * 14 | */ 15 | 16 | (function(root, factory) { 17 | if (typeof define === 'function' && define.amd) { 18 | // AMD. 19 | define(['expect.js', '../../src/index'], factory); 20 | } else if (typeof module === 'object' && module.exports) { 21 | // CommonJS-like environments that support module.exports, like Node. 22 | factory(require('expect.js'), require('../../src/index')); 23 | } else { 24 | // Browser globals (root is window) 25 | factory(root.expect, root.SwaggerJsClient); 26 | } 27 | }(this, function(expect, SwaggerJsClient) { 28 | 'use strict'; 29 | 30 | var instance; 31 | 32 | describe('(package)', function() { 33 | describe('UserSearchReq', function() { 34 | beforeEach(function() { 35 | instance = new SwaggerJsClient.UserSearchReq(); 36 | }); 37 | 38 | it('should create an instance of UserSearchReq', function() { 39 | // TODO: update the code to test UserSearchReq 40 | expect(instance).to.be.a(SwaggerJsClient.UserSearchReq); 41 | }); 42 | 43 | it('should have the property keyWord (base name: "keyWord")', function() { 44 | // TODO: update the code to test the property keyWord 45 | expect(instance).to.have.property('keyWord'); 46 | // expect(instance.keyWord).to.be(expectedValueLiteral); 47 | }); 48 | 49 | }); 50 | }); 51 | 52 | })); 53 | -------------------------------------------------------------------------------- /example/clients/php/.swagger-codegen-ignore: -------------------------------------------------------------------------------- 1 | # Swagger Codegen Ignore 2 | # Generated by swagger-codegen https://github.com/swagger-api/swagger-codegen 3 | 4 | # Use this file to prevent files from being overwritten by the generator. 5 | # The patterns follow closely to .gitignore or .dockerignore. 6 | 7 | # As an example, the C# client generator defines ApiClient.cs. 8 | # You can make changes and tell Swagger Codgen to ignore just this file by uncommenting the following line: 9 | #ApiClient.cs 10 | 11 | # You can match any string of characters against a directory, file or extension with a single asterisk (*): 12 | #foo/*/qux 13 | # The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux 14 | 15 | # You can recursively match patterns against a directory, file or extension with a double asterisk (**): 16 | #foo/**/qux 17 | # This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux 18 | 19 | # You can also negate patterns with an exclamation (!). 20 | # For example, you can ignore all files in a docs folder with the file extension .md: 21 | #docs/*.md 22 | # Then explicitly reverse the ignore rule for a single file: 23 | #!docs/README.md 24 | -------------------------------------------------------------------------------- /example/clients/php/SwaggerClient-php/.php_cs: -------------------------------------------------------------------------------- 1 | setUsingCache(true) 5 | ->setRules([ 6 | '@PSR2' => true, 7 | 'ordered_imports' => true, 8 | 'phpdoc_order' => true, 9 | 'array_syntax' => [ 'syntax' => 'short' ], 10 | 'strict_comparison' => true, 11 | 'strict_param' => true, 12 | 'no_trailing_whitespace' => false, 13 | 'no_trailing_whitespace_in_comment' => false, 14 | 'braces' => false, 15 | 'single_blank_line_at_eof' => false, 16 | 'blank_line_after_namespace' => false, 17 | ]) 18 | ->setFinder( 19 | PhpCsFixer\Finder::create() 20 | ->exclude('test') 21 | ->exclude('tests') 22 | ->in(__DIR__) 23 | ); 24 | -------------------------------------------------------------------------------- /example/clients/php/SwaggerClient-php/.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | sudo: false 3 | php: 4 | - 5.4 5 | - 5.5 6 | - 5.6 7 | - 7.0 8 | - hhvm 9 | before_install: "composer install" 10 | script: "vendor/bin/phpunit" 11 | -------------------------------------------------------------------------------- /example/clients/php/SwaggerClient-php/README.md: -------------------------------------------------------------------------------- 1 | # SwaggerClient-php 2 | No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen) 3 | 4 | This PHP package is automatically generated by the [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) project: 5 | 6 | - API version: 7 | - Build package: io.swagger.codegen.languages.PhpClientCodegen 8 | 9 | ## Requirements 10 | 11 | PHP 5.5 and later 12 | 13 | ## Installation & Usage 14 | ### Composer 15 | 16 | To install the bindings via [Composer](http://getcomposer.org/), add the following to `composer.json`: 17 | 18 | ``` 19 | { 20 | "repositories": [ 21 | { 22 | "type": "git", 23 | "url": "https://github.com/GIT_USER_ID/GIT_REPO_ID.git" 24 | } 25 | ], 26 | "require": { 27 | "GIT_USER_ID/GIT_REPO_ID": "*@dev" 28 | } 29 | } 30 | ``` 31 | 32 | Then run `composer install` 33 | 34 | ### Manual Installation 35 | 36 | Download the files and include `autoload.php`: 37 | 38 | ```php 39 | require_once('/path/to/SwaggerClient-php/vendor/autoload.php'); 40 | ``` 41 | 42 | ## Tests 43 | 44 | To run the unit tests: 45 | 46 | ``` 47 | composer install 48 | ./vendor/bin/phpunit 49 | ``` 50 | 51 | ## Getting Started 52 | 53 | Please follow the [installation procedure](#installation--usage) and then run the following: 54 | 55 | ```php 56 | ping(); 67 | print_r($result); 68 | } catch (Exception $e) { 69 | echo 'Exception when calling GreetApi->ping: ', $e->getMessage(), PHP_EOL; 70 | } 71 | 72 | ?> 73 | ``` 74 | 75 | ## Documentation for API Endpoints 76 | 77 | All URIs are relative to *http://localhost* 78 | 79 | Class | Method | HTTP request | Description 80 | ------------ | ------------- | ------------- | ------------- 81 | *GreetApi* | [**ping**](docs/Api/GreetApi.md#ping) | **GET** /user/ping | 82 | *UserApiApi* | [**getUserInfo**](docs/Api/UserApiApi.md#getuserinfo) | **GET** /api/user/{id} | 获取用户信息 83 | *UserApiApi* | [**login**](docs/Api/UserApiApi.md#login) | **POST** /api/user/login | 登录 84 | *UserApiApi* | [**register**](docs/Api/UserApiApi.md#register) | **POST** /api/user/register | 注册 85 | *UserApiApi* | [**searchUser**](docs/Api/UserApiApi.md#searchuser) | **GET** /api/user/search | 用户搜索 86 | 87 | 88 | ## Documentation For Models 89 | 90 | - [LoginReq](docs/Model/LoginReq.md) 91 | - [RegisterReq](docs/Model/RegisterReq.md) 92 | - [UserInfoReply](docs/Model/UserInfoReply.md) 93 | - [UserInfoReq](docs/Model/UserInfoReq.md) 94 | - [UserSearchReply](docs/Model/UserSearchReply.md) 95 | - [UserSearchReq](docs/Model/UserSearchReq.md) 96 | 97 | 98 | ## Documentation For Authorization 99 | 100 | 101 | ## apiKey 102 | 103 | - **Type**: API key 104 | - **API key parameter name**: Authorization 105 | - **Location**: HTTP header 106 | 107 | 108 | ## Author 109 | 110 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /example/clients/php/SwaggerClient-php/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "GIT_USER_ID/GIT_REPO_ID", 3 | "description": "", 4 | "keywords": [ 5 | "swagger", 6 | "php", 7 | "sdk", 8 | "api" 9 | ], 10 | "homepage": "http://swagger.io", 11 | "license": "proprietary", 12 | "authors": [ 13 | { 14 | "name": "Swagger and contributors", 15 | "homepage": "https://github.com/swagger-api/swagger-codegen" 16 | } 17 | ], 18 | "require": { 19 | "php": ">=5.5", 20 | "ext-curl": "*", 21 | "ext-json": "*", 22 | "ext-mbstring": "*", 23 | "guzzlehttp/guzzle": "^6.2" 24 | }, 25 | "require-dev": { 26 | "phpunit/phpunit": "^4.8", 27 | "squizlabs/php_codesniffer": "~2.6", 28 | "friendsofphp/php-cs-fixer": "~2.12" 29 | }, 30 | "autoload": { 31 | "psr-4": { "Swagger\\Client\\" : "lib/" } 32 | }, 33 | "autoload-dev": { 34 | "psr-4": { "Swagger\\Client\\" : "test/" } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /example/clients/php/SwaggerClient-php/docs/Api/GreetApi.md: -------------------------------------------------------------------------------- 1 | # Swagger\Client\GreetApi 2 | 3 | All URIs are relative to *http://localhost* 4 | 5 | Method | HTTP request | Description 6 | ------------- | ------------- | ------------- 7 | [**ping**](GreetApi.md#ping) | **GET** /user/ping | 8 | 9 | 10 | # **ping** 11 | > object ping() 12 | 13 | 14 | 15 | ### Example 16 | ```php 17 | ping(); 28 | print_r($result); 29 | } catch (Exception $e) { 30 | echo 'Exception when calling GreetApi->ping: ', $e->getMessage(), PHP_EOL; 31 | } 32 | ?> 33 | ``` 34 | 35 | ### Parameters 36 | This endpoint does not need any parameter. 37 | 38 | ### Return type 39 | 40 | **object** 41 | 42 | ### Authorization 43 | 44 | No authorization required 45 | 46 | ### HTTP request headers 47 | 48 | - **Content-Type**: application/json 49 | - **Accept**: application/json 50 | 51 | [[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) 52 | 53 | -------------------------------------------------------------------------------- /example/clients/php/SwaggerClient-php/docs/Api/UserApiApi.md: -------------------------------------------------------------------------------- 1 | # Swagger\Client\UserApiApi 2 | 3 | All URIs are relative to *http://localhost* 4 | 5 | Method | HTTP request | Description 6 | ------------- | ------------- | ------------- 7 | [**getUserInfo**](UserApiApi.md#getUserInfo) | **GET** /api/user/{id} | 获取用户信息 8 | [**login**](UserApiApi.md#login) | **POST** /api/user/login | 登录 9 | [**register**](UserApiApi.md#register) | **POST** /api/user/register | 注册 10 | [**searchUser**](UserApiApi.md#searchUser) | **GET** /api/user/search | 用户搜索 11 | 12 | 13 | # **getUserInfo** 14 | > \Swagger\Client\Model\UserInfoReply getUserInfo($id, $body) 15 | 16 | 获取用户信息 17 | 18 | ### Example 19 | ```php 20 | getUserInfo($id, $body); 33 | print_r($result); 34 | } catch (Exception $e) { 35 | echo 'Exception when calling UserApiApi->getUserInfo: ', $e->getMessage(), PHP_EOL; 36 | } 37 | ?> 38 | ``` 39 | 40 | ### Parameters 41 | 42 | Name | Type | Description | Notes 43 | ------------- | ------------- | ------------- | ------------- 44 | **id** | **string**| | 45 | **body** | [**\Swagger\Client\Model\UserInfoReq**](../Model/UserInfoReq.md)| | 46 | 47 | ### Return type 48 | 49 | [**\Swagger\Client\Model\UserInfoReply**](../Model/UserInfoReply.md) 50 | 51 | ### Authorization 52 | 53 | No authorization required 54 | 55 | ### HTTP request headers 56 | 57 | - **Content-Type**: application/json 58 | - **Accept**: application/json 59 | 60 | [[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) 61 | 62 | # **login** 63 | > object login($body) 64 | 65 | 登录 66 | 67 | ### Example 68 | ```php 69 | login($body); 81 | print_r($result); 82 | } catch (Exception $e) { 83 | echo 'Exception when calling UserApiApi->login: ', $e->getMessage(), PHP_EOL; 84 | } 85 | ?> 86 | ``` 87 | 88 | ### Parameters 89 | 90 | Name | Type | Description | Notes 91 | ------------- | ------------- | ------------- | ------------- 92 | **body** | [**\Swagger\Client\Model\LoginReq**](../Model/LoginReq.md)| | 93 | 94 | ### Return type 95 | 96 | **object** 97 | 98 | ### Authorization 99 | 100 | No authorization required 101 | 102 | ### HTTP request headers 103 | 104 | - **Content-Type**: application/json 105 | - **Accept**: application/json 106 | 107 | [[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) 108 | 109 | # **register** 110 | > object register($body) 111 | 112 | 注册 113 | 114 | 注册一个用户 115 | 116 | ### Example 117 | ```php 118 | register($body); 130 | print_r($result); 131 | } catch (Exception $e) { 132 | echo 'Exception when calling UserApiApi->register: ', $e->getMessage(), PHP_EOL; 133 | } 134 | ?> 135 | ``` 136 | 137 | ### Parameters 138 | 139 | Name | Type | Description | Notes 140 | ------------- | ------------- | ------------- | ------------- 141 | **body** | [**\Swagger\Client\Model\RegisterReq**](../Model/RegisterReq.md)| | 142 | 143 | ### Return type 144 | 145 | **object** 146 | 147 | ### Authorization 148 | 149 | No authorization required 150 | 151 | ### HTTP request headers 152 | 153 | - **Content-Type**: application/json 154 | - **Accept**: application/json 155 | 156 | [[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) 157 | 158 | # **searchUser** 159 | > \Swagger\Client\Model\UserSearchReply searchUser($body) 160 | 161 | 用户搜索 162 | 163 | ### Example 164 | ```php 165 | searchUser($body); 177 | print_r($result); 178 | } catch (Exception $e) { 179 | echo 'Exception when calling UserApiApi->searchUser: ', $e->getMessage(), PHP_EOL; 180 | } 181 | ?> 182 | ``` 183 | 184 | ### Parameters 185 | 186 | Name | Type | Description | Notes 187 | ------------- | ------------- | ------------- | ------------- 188 | **body** | [**\Swagger\Client\Model\UserSearchReq**](../Model/UserSearchReq.md)| | 189 | 190 | ### Return type 191 | 192 | [**\Swagger\Client\Model\UserSearchReply**](../Model/UserSearchReply.md) 193 | 194 | ### Authorization 195 | 196 | No authorization required 197 | 198 | ### HTTP request headers 199 | 200 | - **Content-Type**: application/json 201 | - **Accept**: application/json 202 | 203 | [[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) 204 | 205 | -------------------------------------------------------------------------------- /example/clients/php/SwaggerClient-php/docs/Model/LoginReq.md: -------------------------------------------------------------------------------- 1 | # LoginReq 2 | 3 | ## Properties 4 | Name | Type | Description | Notes 5 | ------------ | ------------- | ------------- | ------------- 6 | **username** | **string** | | [optional] 7 | **password** | **string** | | [optional] 8 | 9 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 10 | 11 | 12 | -------------------------------------------------------------------------------- /example/clients/php/SwaggerClient-php/docs/Model/RegisterReq.md: -------------------------------------------------------------------------------- 1 | # RegisterReq 2 | 3 | ## Properties 4 | Name | Type | Description | Notes 5 | ------------ | ------------- | ------------- | ------------- 6 | **username** | **string** | | [optional] 7 | **password** | **string** | | [optional] 8 | **mobile** | **string** | | [optional] 9 | 10 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 11 | 12 | 13 | -------------------------------------------------------------------------------- /example/clients/php/SwaggerClient-php/docs/Model/UserInfoReply.md: -------------------------------------------------------------------------------- 1 | # UserInfoReply 2 | 3 | ## Properties 4 | Name | Type | Description | Notes 5 | ------------ | ------------- | ------------- | ------------- 6 | **name** | **string** | | [optional] 7 | **age** | **int** | | [optional] 8 | **birthday** | **string** | | [optional] 9 | **description** | **string** | | [optional] 10 | **tag** | **string[]** | | [optional] 11 | 12 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 13 | 14 | 15 | -------------------------------------------------------------------------------- /example/clients/php/SwaggerClient-php/docs/Model/UserInfoReq.md: -------------------------------------------------------------------------------- 1 | # UserInfoReq 2 | 3 | ## Properties 4 | Name | Type | Description | Notes 5 | ------------ | ------------- | ------------- | ------------- 6 | **id** | **string** | | [optional] 7 | 8 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 9 | 10 | 11 | -------------------------------------------------------------------------------- /example/clients/php/SwaggerClient-php/docs/Model/UserSearchReply.md: -------------------------------------------------------------------------------- 1 | # UserSearchReply 2 | 3 | ## Properties 4 | Name | Type | Description | Notes 5 | ------------ | ------------- | ------------- | ------------- 6 | **key_word** | [**\Swagger\Client\Model\UserInfoReply[]**](UserInfoReply.md) | | [optional] 7 | 8 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 9 | 10 | 11 | -------------------------------------------------------------------------------- /example/clients/php/SwaggerClient-php/docs/Model/UserSearchReq.md: -------------------------------------------------------------------------------- 1 | # UserSearchReq 2 | 3 | ## Properties 4 | Name | Type | Description | Notes 5 | ------------ | ------------- | ------------- | ------------- 6 | **key_word** | **string** | | [optional] 7 | 8 | [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) 9 | 10 | 11 | -------------------------------------------------------------------------------- /example/clients/php/SwaggerClient-php/git_push.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ 3 | # 4 | # Usage example: /bin/sh ./git_push.sh wing328 swagger-petstore-perl "minor update" 5 | 6 | git_user_id=$1 7 | git_repo_id=$2 8 | release_note=$3 9 | 10 | if [ "$git_user_id" = "" ]; then 11 | git_user_id="GIT_USER_ID" 12 | echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id" 13 | fi 14 | 15 | if [ "$git_repo_id" = "" ]; then 16 | git_repo_id="GIT_REPO_ID" 17 | echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id" 18 | fi 19 | 20 | if [ "$release_note" = "" ]; then 21 | release_note="Minor update" 22 | echo "[INFO] No command line input provided. Set \$release_note to $release_note" 23 | fi 24 | 25 | # Initialize the local directory as a Git repository 26 | git init 27 | 28 | # Adds the files in the local repository and stages them for commit. 29 | git add . 30 | 31 | # Commits the tracked changes and prepares them to be pushed to a remote repository. 32 | git commit -m "$release_note" 33 | 34 | # Sets the new remote 35 | git_remote=`git remote` 36 | if [ "$git_remote" = "" ]; then # git remote not defined 37 | 38 | if [ "$GIT_TOKEN" = "" ]; then 39 | echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment." 40 | git remote add origin https://github.com/${git_user_id}/${git_repo_id}.git 41 | else 42 | git remote add origin https://${git_user_id}:${GIT_TOKEN}@github.com/${git_user_id}/${git_repo_id}.git 43 | fi 44 | 45 | fi 46 | 47 | git pull origin master 48 | 49 | # Pushes (Forces) the changes in the local repository up to the remote repository 50 | echo "Git pushing to https://github.com/${git_user_id}/${git_repo_id}.git" 51 | git push origin master 2>&1 | grep -v 'To https' 52 | 53 | -------------------------------------------------------------------------------- /example/clients/php/SwaggerClient-php/lib/ApiException.php: -------------------------------------------------------------------------------- 1 | responseHeaders = $responseHeaders; 77 | $this->responseBody = $responseBody; 78 | } 79 | 80 | /** 81 | * Gets the HTTP response header 82 | * 83 | * @return string[]|null HTTP response header 84 | */ 85 | public function getResponseHeaders() 86 | { 87 | return $this->responseHeaders; 88 | } 89 | 90 | /** 91 | * Gets the HTTP body of the server response either as Json or string 92 | * 93 | * @return mixed HTTP body of the server response either as \stdClass or string 94 | */ 95 | public function getResponseBody() 96 | { 97 | return $this->responseBody; 98 | } 99 | 100 | /** 101 | * Sets the deseralized response object (during deserialization) 102 | * 103 | * @param mixed $obj Deserialized response object 104 | * 105 | * @return void 106 | */ 107 | public function setResponseObject($obj) 108 | { 109 | $this->responseObject = $obj; 110 | } 111 | 112 | /** 113 | * Gets the deseralized response object (during deserialization) 114 | * 115 | * @return mixed the deserialized response object 116 | */ 117 | public function getResponseObject() 118 | { 119 | return $this->responseObject; 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /example/clients/php/SwaggerClient-php/lib/HeaderSelector.php: -------------------------------------------------------------------------------- 1 | selectAcceptHeader($accept); 54 | if ($accept !== null) { 55 | $headers['Accept'] = $accept; 56 | } 57 | 58 | $headers['Content-Type'] = $this->selectContentTypeHeader($contentTypes); 59 | return $headers; 60 | } 61 | 62 | /** 63 | * @param string[] $accept 64 | * @return array 65 | */ 66 | public function selectHeadersForMultipart($accept) 67 | { 68 | $headers = $this->selectHeaders($accept, []); 69 | 70 | unset($headers['Content-Type']); 71 | return $headers; 72 | } 73 | 74 | /** 75 | * Return the header 'Accept' based on an array of Accept provided 76 | * 77 | * @param string[] $accept Array of header 78 | * 79 | * @return string Accept (e.g. application/json) 80 | */ 81 | private function selectAcceptHeader($accept) 82 | { 83 | if (count($accept) === 0 || (count($accept) === 1 && $accept[0] === '')) { 84 | return null; 85 | } elseif (preg_grep("/application\/json/i", $accept)) { 86 | return 'application/json'; 87 | } else { 88 | return implode(',', $accept); 89 | } 90 | } 91 | 92 | /** 93 | * Return the content type based on an array of content-type provided 94 | * 95 | * @param string[] $contentType Array fo content-type 96 | * 97 | * @return string Content-Type (e.g. application/json) 98 | */ 99 | private function selectContentTypeHeader($contentType) 100 | { 101 | if (count($contentType) === 0 || (count($contentType) === 1 && $contentType[0] === '')) { 102 | return 'application/json'; 103 | } elseif (preg_grep("/application\/json/i", $contentType)) { 104 | return 'application/json'; 105 | } else { 106 | return implode(',', $contentType); 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /example/clients/php/SwaggerClient-php/lib/Model/LoginReq.php: -------------------------------------------------------------------------------- 1 | 'string', 61 | 'password' => 'string' 62 | ]; 63 | 64 | /** 65 | * Array of property to format mappings. Used for (de)serialization 66 | * 67 | * @var string[] 68 | */ 69 | protected static $swaggerFormats = [ 70 | 'username' => null, 71 | 'password' => null 72 | ]; 73 | 74 | /** 75 | * Array of property to type mappings. Used for (de)serialization 76 | * 77 | * @return array 78 | */ 79 | public static function swaggerTypes() 80 | { 81 | return self::$swaggerTypes; 82 | } 83 | 84 | /** 85 | * Array of property to format mappings. Used for (de)serialization 86 | * 87 | * @return array 88 | */ 89 | public static function swaggerFormats() 90 | { 91 | return self::$swaggerFormats; 92 | } 93 | 94 | /** 95 | * Array of attributes where the key is the local name, 96 | * and the value is the original name 97 | * 98 | * @var string[] 99 | */ 100 | protected static $attributeMap = [ 101 | 'username' => 'username', 102 | 'password' => 'password' 103 | ]; 104 | 105 | /** 106 | * Array of attributes to setter functions (for deserialization of responses) 107 | * 108 | * @var string[] 109 | */ 110 | protected static $setters = [ 111 | 'username' => 'setUsername', 112 | 'password' => 'setPassword' 113 | ]; 114 | 115 | /** 116 | * Array of attributes to getter functions (for serialization of requests) 117 | * 118 | * @var string[] 119 | */ 120 | protected static $getters = [ 121 | 'username' => 'getUsername', 122 | 'password' => 'getPassword' 123 | ]; 124 | 125 | /** 126 | * Array of attributes where the key is the local name, 127 | * and the value is the original name 128 | * 129 | * @return array 130 | */ 131 | public static function attributeMap() 132 | { 133 | return self::$attributeMap; 134 | } 135 | 136 | /** 137 | * Array of attributes to setter functions (for deserialization of responses) 138 | * 139 | * @return array 140 | */ 141 | public static function setters() 142 | { 143 | return self::$setters; 144 | } 145 | 146 | /** 147 | * Array of attributes to getter functions (for serialization of requests) 148 | * 149 | * @return array 150 | */ 151 | public static function getters() 152 | { 153 | return self::$getters; 154 | } 155 | 156 | /** 157 | * The original name of the model. 158 | * 159 | * @return string 160 | */ 161 | public function getModelName() 162 | { 163 | return self::$swaggerModelName; 164 | } 165 | 166 | 167 | 168 | 169 | 170 | /** 171 | * Associative array for storing property values 172 | * 173 | * @var mixed[] 174 | */ 175 | protected $container = []; 176 | 177 | /** 178 | * Constructor 179 | * 180 | * @param mixed[] $data Associated array of property values 181 | * initializing the model 182 | */ 183 | public function __construct(array $data = null) 184 | { 185 | $this->container['username'] = isset($data['username']) ? $data['username'] : null; 186 | $this->container['password'] = isset($data['password']) ? $data['password'] : null; 187 | } 188 | 189 | /** 190 | * Show all the invalid properties with reasons. 191 | * 192 | * @return array invalid properties with reasons 193 | */ 194 | public function listInvalidProperties() 195 | { 196 | $invalidProperties = []; 197 | 198 | return $invalidProperties; 199 | } 200 | 201 | /** 202 | * Validate all the properties in the model 203 | * return true if all passed 204 | * 205 | * @return bool True if all properties are valid 206 | */ 207 | public function valid() 208 | { 209 | return count($this->listInvalidProperties()) === 0; 210 | } 211 | 212 | 213 | /** 214 | * Gets username 215 | * 216 | * @return string 217 | */ 218 | public function getUsername() 219 | { 220 | return $this->container['username']; 221 | } 222 | 223 | /** 224 | * Sets username 225 | * 226 | * @param string $username username 227 | * 228 | * @return $this 229 | */ 230 | public function setUsername($username) 231 | { 232 | $this->container['username'] = $username; 233 | 234 | return $this; 235 | } 236 | 237 | /** 238 | * Gets password 239 | * 240 | * @return string 241 | */ 242 | public function getPassword() 243 | { 244 | return $this->container['password']; 245 | } 246 | 247 | /** 248 | * Sets password 249 | * 250 | * @param string $password password 251 | * 252 | * @return $this 253 | */ 254 | public function setPassword($password) 255 | { 256 | $this->container['password'] = $password; 257 | 258 | return $this; 259 | } 260 | /** 261 | * Returns true if offset exists. False otherwise. 262 | * 263 | * @param integer $offset Offset 264 | * 265 | * @return boolean 266 | */ 267 | public function offsetExists($offset) 268 | { 269 | return isset($this->container[$offset]); 270 | } 271 | 272 | /** 273 | * Gets offset. 274 | * 275 | * @param integer $offset Offset 276 | * 277 | * @return mixed 278 | */ 279 | public function offsetGet($offset) 280 | { 281 | return isset($this->container[$offset]) ? $this->container[$offset] : null; 282 | } 283 | 284 | /** 285 | * Sets value based on offset. 286 | * 287 | * @param integer $offset Offset 288 | * @param mixed $value Value to be set 289 | * 290 | * @return void 291 | */ 292 | public function offsetSet($offset, $value) 293 | { 294 | if (is_null($offset)) { 295 | $this->container[] = $value; 296 | } else { 297 | $this->container[$offset] = $value; 298 | } 299 | } 300 | 301 | /** 302 | * Unsets offset. 303 | * 304 | * @param integer $offset Offset 305 | * 306 | * @return void 307 | */ 308 | public function offsetUnset($offset) 309 | { 310 | unset($this->container[$offset]); 311 | } 312 | 313 | /** 314 | * Gets the string presentation of the object 315 | * 316 | * @return string 317 | */ 318 | public function __toString() 319 | { 320 | if (defined('JSON_PRETTY_PRINT')) { // use JSON pretty print 321 | return json_encode( 322 | ObjectSerializer::sanitizeForSerialization($this), 323 | JSON_PRETTY_PRINT 324 | ); 325 | } 326 | 327 | return json_encode(ObjectSerializer::sanitizeForSerialization($this)); 328 | } 329 | } 330 | 331 | 332 | -------------------------------------------------------------------------------- /example/clients/php/SwaggerClient-php/lib/Model/ModelInterface.php: -------------------------------------------------------------------------------- 1 | 'string' 61 | ]; 62 | 63 | /** 64 | * Array of property to format mappings. Used for (de)serialization 65 | * 66 | * @var string[] 67 | */ 68 | protected static $swaggerFormats = [ 69 | 'id' => null 70 | ]; 71 | 72 | /** 73 | * Array of property to type mappings. Used for (de)serialization 74 | * 75 | * @return array 76 | */ 77 | public static function swaggerTypes() 78 | { 79 | return self::$swaggerTypes; 80 | } 81 | 82 | /** 83 | * Array of property to format mappings. Used for (de)serialization 84 | * 85 | * @return array 86 | */ 87 | public static function swaggerFormats() 88 | { 89 | return self::$swaggerFormats; 90 | } 91 | 92 | /** 93 | * Array of attributes where the key is the local name, 94 | * and the value is the original name 95 | * 96 | * @var string[] 97 | */ 98 | protected static $attributeMap = [ 99 | 'id' => 'id' 100 | ]; 101 | 102 | /** 103 | * Array of attributes to setter functions (for deserialization of responses) 104 | * 105 | * @var string[] 106 | */ 107 | protected static $setters = [ 108 | 'id' => 'setId' 109 | ]; 110 | 111 | /** 112 | * Array of attributes to getter functions (for serialization of requests) 113 | * 114 | * @var string[] 115 | */ 116 | protected static $getters = [ 117 | 'id' => 'getId' 118 | ]; 119 | 120 | /** 121 | * Array of attributes where the key is the local name, 122 | * and the value is the original name 123 | * 124 | * @return array 125 | */ 126 | public static function attributeMap() 127 | { 128 | return self::$attributeMap; 129 | } 130 | 131 | /** 132 | * Array of attributes to setter functions (for deserialization of responses) 133 | * 134 | * @return array 135 | */ 136 | public static function setters() 137 | { 138 | return self::$setters; 139 | } 140 | 141 | /** 142 | * Array of attributes to getter functions (for serialization of requests) 143 | * 144 | * @return array 145 | */ 146 | public static function getters() 147 | { 148 | return self::$getters; 149 | } 150 | 151 | /** 152 | * The original name of the model. 153 | * 154 | * @return string 155 | */ 156 | public function getModelName() 157 | { 158 | return self::$swaggerModelName; 159 | } 160 | 161 | 162 | 163 | 164 | 165 | /** 166 | * Associative array for storing property values 167 | * 168 | * @var mixed[] 169 | */ 170 | protected $container = []; 171 | 172 | /** 173 | * Constructor 174 | * 175 | * @param mixed[] $data Associated array of property values 176 | * initializing the model 177 | */ 178 | public function __construct(array $data = null) 179 | { 180 | $this->container['id'] = isset($data['id']) ? $data['id'] : null; 181 | } 182 | 183 | /** 184 | * Show all the invalid properties with reasons. 185 | * 186 | * @return array invalid properties with reasons 187 | */ 188 | public function listInvalidProperties() 189 | { 190 | $invalidProperties = []; 191 | 192 | return $invalidProperties; 193 | } 194 | 195 | /** 196 | * Validate all the properties in the model 197 | * return true if all passed 198 | * 199 | * @return bool True if all properties are valid 200 | */ 201 | public function valid() 202 | { 203 | return count($this->listInvalidProperties()) === 0; 204 | } 205 | 206 | 207 | /** 208 | * Gets id 209 | * 210 | * @return string 211 | */ 212 | public function getId() 213 | { 214 | return $this->container['id']; 215 | } 216 | 217 | /** 218 | * Sets id 219 | * 220 | * @param string $id id 221 | * 222 | * @return $this 223 | */ 224 | public function setId($id) 225 | { 226 | $this->container['id'] = $id; 227 | 228 | return $this; 229 | } 230 | /** 231 | * Returns true if offset exists. False otherwise. 232 | * 233 | * @param integer $offset Offset 234 | * 235 | * @return boolean 236 | */ 237 | public function offsetExists($offset) 238 | { 239 | return isset($this->container[$offset]); 240 | } 241 | 242 | /** 243 | * Gets offset. 244 | * 245 | * @param integer $offset Offset 246 | * 247 | * @return mixed 248 | */ 249 | public function offsetGet($offset) 250 | { 251 | return isset($this->container[$offset]) ? $this->container[$offset] : null; 252 | } 253 | 254 | /** 255 | * Sets value based on offset. 256 | * 257 | * @param integer $offset Offset 258 | * @param mixed $value Value to be set 259 | * 260 | * @return void 261 | */ 262 | public function offsetSet($offset, $value) 263 | { 264 | if (is_null($offset)) { 265 | $this->container[] = $value; 266 | } else { 267 | $this->container[$offset] = $value; 268 | } 269 | } 270 | 271 | /** 272 | * Unsets offset. 273 | * 274 | * @param integer $offset Offset 275 | * 276 | * @return void 277 | */ 278 | public function offsetUnset($offset) 279 | { 280 | unset($this->container[$offset]); 281 | } 282 | 283 | /** 284 | * Gets the string presentation of the object 285 | * 286 | * @return string 287 | */ 288 | public function __toString() 289 | { 290 | if (defined('JSON_PRETTY_PRINT')) { // use JSON pretty print 291 | return json_encode( 292 | ObjectSerializer::sanitizeForSerialization($this), 293 | JSON_PRETTY_PRINT 294 | ); 295 | } 296 | 297 | return json_encode(ObjectSerializer::sanitizeForSerialization($this)); 298 | } 299 | } 300 | 301 | 302 | -------------------------------------------------------------------------------- /example/clients/php/SwaggerClient-php/lib/Model/UserSearchReply.php: -------------------------------------------------------------------------------- 1 | '\Swagger\Client\Model\UserInfoReply[]' 61 | ]; 62 | 63 | /** 64 | * Array of property to format mappings. Used for (de)serialization 65 | * 66 | * @var string[] 67 | */ 68 | protected static $swaggerFormats = [ 69 | 'key_word' => null 70 | ]; 71 | 72 | /** 73 | * Array of property to type mappings. Used for (de)serialization 74 | * 75 | * @return array 76 | */ 77 | public static function swaggerTypes() 78 | { 79 | return self::$swaggerTypes; 80 | } 81 | 82 | /** 83 | * Array of property to format mappings. Used for (de)serialization 84 | * 85 | * @return array 86 | */ 87 | public static function swaggerFormats() 88 | { 89 | return self::$swaggerFormats; 90 | } 91 | 92 | /** 93 | * Array of attributes where the key is the local name, 94 | * and the value is the original name 95 | * 96 | * @var string[] 97 | */ 98 | protected static $attributeMap = [ 99 | 'key_word' => 'KeyWord' 100 | ]; 101 | 102 | /** 103 | * Array of attributes to setter functions (for deserialization of responses) 104 | * 105 | * @var string[] 106 | */ 107 | protected static $setters = [ 108 | 'key_word' => 'setKeyWord' 109 | ]; 110 | 111 | /** 112 | * Array of attributes to getter functions (for serialization of requests) 113 | * 114 | * @var string[] 115 | */ 116 | protected static $getters = [ 117 | 'key_word' => 'getKeyWord' 118 | ]; 119 | 120 | /** 121 | * Array of attributes where the key is the local name, 122 | * and the value is the original name 123 | * 124 | * @return array 125 | */ 126 | public static function attributeMap() 127 | { 128 | return self::$attributeMap; 129 | } 130 | 131 | /** 132 | * Array of attributes to setter functions (for deserialization of responses) 133 | * 134 | * @return array 135 | */ 136 | public static function setters() 137 | { 138 | return self::$setters; 139 | } 140 | 141 | /** 142 | * Array of attributes to getter functions (for serialization of requests) 143 | * 144 | * @return array 145 | */ 146 | public static function getters() 147 | { 148 | return self::$getters; 149 | } 150 | 151 | /** 152 | * The original name of the model. 153 | * 154 | * @return string 155 | */ 156 | public function getModelName() 157 | { 158 | return self::$swaggerModelName; 159 | } 160 | 161 | 162 | 163 | 164 | 165 | /** 166 | * Associative array for storing property values 167 | * 168 | * @var mixed[] 169 | */ 170 | protected $container = []; 171 | 172 | /** 173 | * Constructor 174 | * 175 | * @param mixed[] $data Associated array of property values 176 | * initializing the model 177 | */ 178 | public function __construct(array $data = null) 179 | { 180 | $this->container['key_word'] = isset($data['key_word']) ? $data['key_word'] : null; 181 | } 182 | 183 | /** 184 | * Show all the invalid properties with reasons. 185 | * 186 | * @return array invalid properties with reasons 187 | */ 188 | public function listInvalidProperties() 189 | { 190 | $invalidProperties = []; 191 | 192 | return $invalidProperties; 193 | } 194 | 195 | /** 196 | * Validate all the properties in the model 197 | * return true if all passed 198 | * 199 | * @return bool True if all properties are valid 200 | */ 201 | public function valid() 202 | { 203 | return count($this->listInvalidProperties()) === 0; 204 | } 205 | 206 | 207 | /** 208 | * Gets key_word 209 | * 210 | * @return \Swagger\Client\Model\UserInfoReply[] 211 | */ 212 | public function getKeyWord() 213 | { 214 | return $this->container['key_word']; 215 | } 216 | 217 | /** 218 | * Sets key_word 219 | * 220 | * @param \Swagger\Client\Model\UserInfoReply[] $key_word key_word 221 | * 222 | * @return $this 223 | */ 224 | public function setKeyWord($key_word) 225 | { 226 | $this->container['key_word'] = $key_word; 227 | 228 | return $this; 229 | } 230 | /** 231 | * Returns true if offset exists. False otherwise. 232 | * 233 | * @param integer $offset Offset 234 | * 235 | * @return boolean 236 | */ 237 | public function offsetExists($offset) 238 | { 239 | return isset($this->container[$offset]); 240 | } 241 | 242 | /** 243 | * Gets offset. 244 | * 245 | * @param integer $offset Offset 246 | * 247 | * @return mixed 248 | */ 249 | public function offsetGet($offset) 250 | { 251 | return isset($this->container[$offset]) ? $this->container[$offset] : null; 252 | } 253 | 254 | /** 255 | * Sets value based on offset. 256 | * 257 | * @param integer $offset Offset 258 | * @param mixed $value Value to be set 259 | * 260 | * @return void 261 | */ 262 | public function offsetSet($offset, $value) 263 | { 264 | if (is_null($offset)) { 265 | $this->container[] = $value; 266 | } else { 267 | $this->container[$offset] = $value; 268 | } 269 | } 270 | 271 | /** 272 | * Unsets offset. 273 | * 274 | * @param integer $offset Offset 275 | * 276 | * @return void 277 | */ 278 | public function offsetUnset($offset) 279 | { 280 | unset($this->container[$offset]); 281 | } 282 | 283 | /** 284 | * Gets the string presentation of the object 285 | * 286 | * @return string 287 | */ 288 | public function __toString() 289 | { 290 | if (defined('JSON_PRETTY_PRINT')) { // use JSON pretty print 291 | return json_encode( 292 | ObjectSerializer::sanitizeForSerialization($this), 293 | JSON_PRETTY_PRINT 294 | ); 295 | } 296 | 297 | return json_encode(ObjectSerializer::sanitizeForSerialization($this)); 298 | } 299 | } 300 | 301 | 302 | -------------------------------------------------------------------------------- /example/clients/php/SwaggerClient-php/lib/Model/UserSearchReq.php: -------------------------------------------------------------------------------- 1 | 'string' 61 | ]; 62 | 63 | /** 64 | * Array of property to format mappings. Used for (de)serialization 65 | * 66 | * @var string[] 67 | */ 68 | protected static $swaggerFormats = [ 69 | 'key_word' => null 70 | ]; 71 | 72 | /** 73 | * Array of property to type mappings. Used for (de)serialization 74 | * 75 | * @return array 76 | */ 77 | public static function swaggerTypes() 78 | { 79 | return self::$swaggerTypes; 80 | } 81 | 82 | /** 83 | * Array of property to format mappings. Used for (de)serialization 84 | * 85 | * @return array 86 | */ 87 | public static function swaggerFormats() 88 | { 89 | return self::$swaggerFormats; 90 | } 91 | 92 | /** 93 | * Array of attributes where the key is the local name, 94 | * and the value is the original name 95 | * 96 | * @var string[] 97 | */ 98 | protected static $attributeMap = [ 99 | 'key_word' => 'keyWord' 100 | ]; 101 | 102 | /** 103 | * Array of attributes to setter functions (for deserialization of responses) 104 | * 105 | * @var string[] 106 | */ 107 | protected static $setters = [ 108 | 'key_word' => 'setKeyWord' 109 | ]; 110 | 111 | /** 112 | * Array of attributes to getter functions (for serialization of requests) 113 | * 114 | * @var string[] 115 | */ 116 | protected static $getters = [ 117 | 'key_word' => 'getKeyWord' 118 | ]; 119 | 120 | /** 121 | * Array of attributes where the key is the local name, 122 | * and the value is the original name 123 | * 124 | * @return array 125 | */ 126 | public static function attributeMap() 127 | { 128 | return self::$attributeMap; 129 | } 130 | 131 | /** 132 | * Array of attributes to setter functions (for deserialization of responses) 133 | * 134 | * @return array 135 | */ 136 | public static function setters() 137 | { 138 | return self::$setters; 139 | } 140 | 141 | /** 142 | * Array of attributes to getter functions (for serialization of requests) 143 | * 144 | * @return array 145 | */ 146 | public static function getters() 147 | { 148 | return self::$getters; 149 | } 150 | 151 | /** 152 | * The original name of the model. 153 | * 154 | * @return string 155 | */ 156 | public function getModelName() 157 | { 158 | return self::$swaggerModelName; 159 | } 160 | 161 | 162 | 163 | 164 | 165 | /** 166 | * Associative array for storing property values 167 | * 168 | * @var mixed[] 169 | */ 170 | protected $container = []; 171 | 172 | /** 173 | * Constructor 174 | * 175 | * @param mixed[] $data Associated array of property values 176 | * initializing the model 177 | */ 178 | public function __construct(array $data = null) 179 | { 180 | $this->container['key_word'] = isset($data['key_word']) ? $data['key_word'] : null; 181 | } 182 | 183 | /** 184 | * Show all the invalid properties with reasons. 185 | * 186 | * @return array invalid properties with reasons 187 | */ 188 | public function listInvalidProperties() 189 | { 190 | $invalidProperties = []; 191 | 192 | return $invalidProperties; 193 | } 194 | 195 | /** 196 | * Validate all the properties in the model 197 | * return true if all passed 198 | * 199 | * @return bool True if all properties are valid 200 | */ 201 | public function valid() 202 | { 203 | return count($this->listInvalidProperties()) === 0; 204 | } 205 | 206 | 207 | /** 208 | * Gets key_word 209 | * 210 | * @return string 211 | */ 212 | public function getKeyWord() 213 | { 214 | return $this->container['key_word']; 215 | } 216 | 217 | /** 218 | * Sets key_word 219 | * 220 | * @param string $key_word key_word 221 | * 222 | * @return $this 223 | */ 224 | public function setKeyWord($key_word) 225 | { 226 | $this->container['key_word'] = $key_word; 227 | 228 | return $this; 229 | } 230 | /** 231 | * Returns true if offset exists. False otherwise. 232 | * 233 | * @param integer $offset Offset 234 | * 235 | * @return boolean 236 | */ 237 | public function offsetExists($offset) 238 | { 239 | return isset($this->container[$offset]); 240 | } 241 | 242 | /** 243 | * Gets offset. 244 | * 245 | * @param integer $offset Offset 246 | * 247 | * @return mixed 248 | */ 249 | public function offsetGet($offset) 250 | { 251 | return isset($this->container[$offset]) ? $this->container[$offset] : null; 252 | } 253 | 254 | /** 255 | * Sets value based on offset. 256 | * 257 | * @param integer $offset Offset 258 | * @param mixed $value Value to be set 259 | * 260 | * @return void 261 | */ 262 | public function offsetSet($offset, $value) 263 | { 264 | if (is_null($offset)) { 265 | $this->container[] = $value; 266 | } else { 267 | $this->container[$offset] = $value; 268 | } 269 | } 270 | 271 | /** 272 | * Unsets offset. 273 | * 274 | * @param integer $offset Offset 275 | * 276 | * @return void 277 | */ 278 | public function offsetUnset($offset) 279 | { 280 | unset($this->container[$offset]); 281 | } 282 | 283 | /** 284 | * Gets the string presentation of the object 285 | * 286 | * @return string 287 | */ 288 | public function __toString() 289 | { 290 | if (defined('JSON_PRETTY_PRINT')) { // use JSON pretty print 291 | return json_encode( 292 | ObjectSerializer::sanitizeForSerialization($this), 293 | JSON_PRETTY_PRINT 294 | ); 295 | } 296 | 297 | return json_encode(ObjectSerializer::sanitizeForSerialization($this)); 298 | } 299 | } 300 | 301 | 302 | -------------------------------------------------------------------------------- /example/clients/php/SwaggerClient-php/phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | ./test/Api 11 | ./test/Model 12 | 13 | 14 | 15 | 16 | 17 | ./lib/Api 18 | ./lib/Model 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /example/clients/php/SwaggerClient-php/test/Api/GreetApiTest.php: -------------------------------------------------------------------------------- 1 | 73 | 74 | 75 | 76 | 77 | API documentation 78 | 79 | 80 | 81 | 102 | 103 | 104 | 105 |
106 | 107 | 108 | 109 | 131 | 132 | ` 133 | -------------------------------------------------------------------------------- /example/gozero/swagger.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "title": "", 5 | "version": "" 6 | }, 7 | "schemes": [ 8 | "http", 9 | "https" 10 | ], 11 | "consumes": [ 12 | "application/json" 13 | ], 14 | "produces": [ 15 | "application/json" 16 | ], 17 | "paths": { 18 | "/api/user/login": { 19 | "post": { 20 | "summary": "登录", 21 | "operationId": "login", 22 | "responses": { 23 | "200": { 24 | "description": "A successful response.", 25 | "schema": {} 26 | } 27 | }, 28 | "parameters": [ 29 | { 30 | "name": "body", 31 | "in": "body", 32 | "required": true, 33 | "schema": { 34 | "$ref": "#/definitions/LoginReq" 35 | } 36 | } 37 | ], 38 | "tags": [ 39 | "user-api" 40 | ] 41 | } 42 | }, 43 | "/api/user/register": { 44 | "post": { 45 | "summary": "注册", 46 | "description": "注册一个用户", 47 | "operationId": "register", 48 | "responses": { 49 | "200": { 50 | "description": "A successful response.", 51 | "schema": {} 52 | } 53 | }, 54 | "parameters": [ 55 | { 56 | "name": "body", 57 | "in": "body", 58 | "required": true, 59 | "schema": { 60 | "$ref": "#/definitions/RegisterReq" 61 | } 62 | } 63 | ], 64 | "tags": [ 65 | "user-api" 66 | ] 67 | } 68 | }, 69 | "/api/user/search": { 70 | "get": { 71 | "summary": "用户搜索", 72 | "operationId": "searchUser", 73 | "responses": { 74 | "200": { 75 | "description": "A successful response.", 76 | "schema": { 77 | "$ref": "#/definitions/UserSearchReply" 78 | } 79 | } 80 | }, 81 | "parameters": [ 82 | { 83 | "name": "body", 84 | "in": "body", 85 | "required": true, 86 | "schema": { 87 | "$ref": "#/definitions/UserSearchReq" 88 | } 89 | } 90 | ], 91 | "tags": [ 92 | "user-api" 93 | ] 94 | } 95 | }, 96 | "/api/user/{id}": { 97 | "get": { 98 | "summary": "获取用户信息", 99 | "operationId": "getUserInfo", 100 | "responses": { 101 | "200": { 102 | "description": "A successful response.", 103 | "schema": { 104 | "$ref": "#/definitions/UserInfoReply" 105 | } 106 | } 107 | }, 108 | "parameters": [ 109 | { 110 | "name": "id", 111 | "in": "path", 112 | "required": true, 113 | "type": "string" 114 | }, 115 | { 116 | "name": "body", 117 | "in": "body", 118 | "required": true, 119 | "schema": { 120 | "$ref": "#/definitions/UserInfoReq" 121 | } 122 | } 123 | ], 124 | "tags": [ 125 | "user-api" 126 | ] 127 | } 128 | }, 129 | "/user/ping": { 130 | "get": { 131 | "operationId": "ping", 132 | "responses": { 133 | "200": { 134 | "description": "A successful response.", 135 | "schema": {} 136 | } 137 | }, 138 | "tags": [ 139 | "greet" 140 | ] 141 | } 142 | } 143 | }, 144 | "definitions": { 145 | "LoginReq": { 146 | "type": "object", 147 | "properties": { 148 | "username": { 149 | "type": "string" 150 | }, 151 | "password": { 152 | "type": "string" 153 | } 154 | }, 155 | "title": "LoginReq" 156 | }, 157 | "RegisterReq": { 158 | "type": "object", 159 | "properties": { 160 | "username": { 161 | "type": "string" 162 | }, 163 | "password": { 164 | "type": "string" 165 | }, 166 | "mobile": { 167 | "type": "string" 168 | } 169 | }, 170 | "title": "RegisterReq" 171 | }, 172 | "UserInfoReply": { 173 | "type": "object", 174 | "properties": { 175 | "name": { 176 | "type": "string" 177 | }, 178 | "age": { 179 | "type": "integer", 180 | "format": "int32" 181 | }, 182 | "birthday": { 183 | "type": "string" 184 | }, 185 | "description": { 186 | "type": "string" 187 | }, 188 | "tag": { 189 | "type": "array", 190 | "items": { 191 | "type": "string" 192 | } 193 | } 194 | }, 195 | "title": "UserInfoReply" 196 | }, 197 | "UserInfoReq": { 198 | "type": "object", 199 | "properties": { 200 | "id": { 201 | "type": "string" 202 | } 203 | }, 204 | "title": "UserInfoReq" 205 | }, 206 | "UserSearchReply": { 207 | "type": "object", 208 | "properties": { 209 | "KeyWord": { 210 | "type": "array", 211 | "items": { 212 | "$ref": "#/definitions/UserInfoReply" 213 | } 214 | } 215 | }, 216 | "title": "UserSearchReply" 217 | }, 218 | "UserSearchReq": { 219 | "type": "object", 220 | "properties": { 221 | "keyWord": { 222 | "type": "string" 223 | } 224 | }, 225 | "title": "UserSearchReq" 226 | } 227 | }, 228 | "securityDefinitions": { 229 | "apiKey": { 230 | "type": "apiKey", 231 | "description": "Enter JWT Bearer token **_only_**", 232 | "name": "Authorization", 233 | "in": "header" 234 | } 235 | } 236 | } 237 | -------------------------------------------------------------------------------- /example/rest.swagger.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "title": "", 5 | "version": "" 6 | }, 7 | "schemes": [ 8 | "http", 9 | "https" 10 | ], 11 | "consumes": [ 12 | "application/json" 13 | ], 14 | "produces": [ 15 | "application/json" 16 | ], 17 | "paths": { 18 | "/api/user/login": { 19 | "post": { 20 | "summary": "登录", 21 | "operationId": "login", 22 | "responses": { 23 | "200": { 24 | "description": "A successful response.", 25 | "schema": {} 26 | } 27 | }, 28 | "parameters": [ 29 | { 30 | "name": "body", 31 | "in": "body", 32 | "required": true, 33 | "schema": { 34 | "$ref": "#/definitions/LoginReq" 35 | } 36 | } 37 | ], 38 | "tags": [ 39 | "user-api" 40 | ] 41 | } 42 | }, 43 | "/api/user/register": { 44 | "post": { 45 | "summary": "注册", 46 | "description": "注册一个用户", 47 | "operationId": "register", 48 | "responses": { 49 | "200": { 50 | "description": "A successful response.", 51 | "schema": {} 52 | } 53 | }, 54 | "parameters": [ 55 | { 56 | "name": "body", 57 | "in": "body", 58 | "required": true, 59 | "schema": { 60 | "$ref": "#/definitions/RegisterReq" 61 | } 62 | } 63 | ], 64 | "tags": [ 65 | "user-api" 66 | ] 67 | } 68 | }, 69 | "/api/user/search": { 70 | "get": { 71 | "summary": "用户搜索", 72 | "operationId": "searchUser", 73 | "responses": { 74 | "200": { 75 | "description": "A successful response.", 76 | "schema": { 77 | "$ref": "#/definitions/UserSearchReply" 78 | } 79 | } 80 | }, 81 | "parameters": [ 82 | { 83 | "name": "body", 84 | "in": "body", 85 | "required": true, 86 | "schema": { 87 | "$ref": "#/definitions/UserSearchReq" 88 | } 89 | } 90 | ], 91 | "tags": [ 92 | "user-api" 93 | ] 94 | } 95 | }, 96 | "/api/user/{id}": { 97 | "get": { 98 | "summary": "获取用户信息", 99 | "operationId": "getUserInfo", 100 | "responses": { 101 | "200": { 102 | "description": "A successful response.", 103 | "schema": { 104 | "$ref": "#/definitions/UserInfoReply" 105 | } 106 | } 107 | }, 108 | "parameters": [ 109 | { 110 | "name": "id", 111 | "in": "path", 112 | "required": true, 113 | "type": "string" 114 | }, 115 | { 116 | "name": "body", 117 | "in": "body", 118 | "required": true, 119 | "schema": { 120 | "$ref": "#/definitions/UserInfoReq" 121 | } 122 | } 123 | ], 124 | "tags": [ 125 | "user-api" 126 | ] 127 | } 128 | }, 129 | "/user/ping": { 130 | "get": { 131 | "operationId": "ping", 132 | "responses": { 133 | "200": { 134 | "description": "A successful response.", 135 | "schema": {} 136 | } 137 | }, 138 | "tags": [ 139 | "greet" 140 | ] 141 | } 142 | } 143 | }, 144 | "definitions": { 145 | "LoginReq": { 146 | "type": "object", 147 | "properties": { 148 | "username": { 149 | "type": "string" 150 | }, 151 | "password": { 152 | "type": "string" 153 | } 154 | }, 155 | "title": "LoginReq" 156 | }, 157 | "RegisterReq": { 158 | "type": "object", 159 | "properties": { 160 | "username": { 161 | "type": "string" 162 | }, 163 | "password": { 164 | "type": "string" 165 | }, 166 | "mobile": { 167 | "type": "string" 168 | } 169 | }, 170 | "title": "RegisterReq" 171 | }, 172 | "UserInfoReply": { 173 | "type": "object", 174 | "properties": { 175 | "name": { 176 | "type": "string" 177 | }, 178 | "age": { 179 | "type": "integer", 180 | "format": "int32" 181 | }, 182 | "birthday": { 183 | "type": "string" 184 | }, 185 | "description": { 186 | "type": "string" 187 | }, 188 | "tag": { 189 | "type": "array", 190 | "items": { 191 | "type": "string" 192 | } 193 | } 194 | }, 195 | "title": "UserInfoReply" 196 | }, 197 | "UserInfoReq": { 198 | "type": "object", 199 | "properties": { 200 | "id": { 201 | "type": "string" 202 | } 203 | }, 204 | "title": "UserInfoReq" 205 | }, 206 | "UserSearchReply": { 207 | "type": "object", 208 | "properties": { 209 | "KeyWord": { 210 | "type": "array", 211 | "items": { 212 | "$ref": "#/definitions/UserInfoReply" 213 | } 214 | } 215 | }, 216 | "title": "UserSearchReply" 217 | }, 218 | "UserSearchReq": { 219 | "type": "object", 220 | "properties": { 221 | "keyWord": { 222 | "type": "string" 223 | } 224 | }, 225 | "title": "UserSearchReq" 226 | } 227 | }, 228 | "securityDefinitions": { 229 | "apiKey": { 230 | "type": "apiKey", 231 | "description": "Enter JWT Bearer token **_only_**", 232 | "name": "Authorization", 233 | "in": "header" 234 | } 235 | } 236 | } 237 | -------------------------------------------------------------------------------- /example/swagger.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "title": "", 5 | "version": "" 6 | }, 7 | "schemes": [ 8 | "http", 9 | "https" 10 | ], 11 | "consumes": [ 12 | "application/json" 13 | ], 14 | "produces": [ 15 | "application/json" 16 | ], 17 | "paths": { 18 | "/api/user/login": { 19 | "post": { 20 | "summary": "登录", 21 | "operationId": "login", 22 | "responses": { 23 | "200": { 24 | "description": "A successful response.", 25 | "schema": {} 26 | } 27 | }, 28 | "parameters": [ 29 | { 30 | "name": "body", 31 | "in": "body", 32 | "required": true, 33 | "schema": { 34 | "$ref": "#/definitions/LoginReq" 35 | } 36 | } 37 | ], 38 | "tags": [ 39 | "user-api" 40 | ] 41 | } 42 | }, 43 | "/api/user/register": { 44 | "post": { 45 | "summary": "注册", 46 | "description": "注册一个用户", 47 | "operationId": "register", 48 | "responses": { 49 | "200": { 50 | "description": "A successful response.", 51 | "schema": {} 52 | } 53 | }, 54 | "parameters": [ 55 | { 56 | "name": "body", 57 | "in": "body", 58 | "required": true, 59 | "schema": { 60 | "$ref": "#/definitions/RegisterReq" 61 | } 62 | } 63 | ], 64 | "tags": [ 65 | "user-api" 66 | ] 67 | } 68 | }, 69 | "/api/user/search": { 70 | "get": { 71 | "summary": "用户搜索", 72 | "operationId": "searchUser", 73 | "responses": { 74 | "200": { 75 | "description": "A successful response.", 76 | "schema": { 77 | "$ref": "#/definitions/UserSearchReply" 78 | } 79 | } 80 | }, 81 | "parameters": [ 82 | { 83 | "name": "body", 84 | "in": "body", 85 | "required": true, 86 | "schema": { 87 | "$ref": "#/definitions/UserSearchReq" 88 | } 89 | } 90 | ], 91 | "tags": [ 92 | "user-api" 93 | ] 94 | } 95 | }, 96 | "/api/user/{id}": { 97 | "get": { 98 | "summary": "获取用户信息", 99 | "operationId": "getUserInfo", 100 | "responses": { 101 | "200": { 102 | "description": "A successful response.", 103 | "schema": { 104 | "$ref": "#/definitions/UserInfoReply" 105 | } 106 | } 107 | }, 108 | "parameters": [ 109 | { 110 | "name": "id", 111 | "in": "path", 112 | "required": true, 113 | "type": "string" 114 | }, 115 | { 116 | "name": "body", 117 | "in": "body", 118 | "required": true, 119 | "schema": { 120 | "$ref": "#/definitions/UserInfoReq" 121 | } 122 | } 123 | ], 124 | "tags": [ 125 | "user-api" 126 | ] 127 | } 128 | }, 129 | "/user/ping": { 130 | "get": { 131 | "operationId": "ping", 132 | "responses": { 133 | "200": { 134 | "description": "A successful response.", 135 | "schema": {} 136 | } 137 | }, 138 | "tags": [ 139 | "greet" 140 | ] 141 | } 142 | } 143 | }, 144 | "definitions": { 145 | "LoginReq": { 146 | "type": "object", 147 | "properties": { 148 | "username": { 149 | "type": "string" 150 | }, 151 | "password": { 152 | "type": "string" 153 | } 154 | }, 155 | "title": "LoginReq" 156 | }, 157 | "RegisterReq": { 158 | "type": "object", 159 | "properties": { 160 | "username": { 161 | "type": "string" 162 | }, 163 | "password": { 164 | "type": "string" 165 | }, 166 | "mobile": { 167 | "type": "string" 168 | } 169 | }, 170 | "title": "RegisterReq" 171 | }, 172 | "UserInfoReply": { 173 | "type": "object", 174 | "properties": { 175 | "name": { 176 | "type": "string" 177 | }, 178 | "age": { 179 | "type": "integer", 180 | "format": "int32" 181 | }, 182 | "birthday": { 183 | "type": "string" 184 | }, 185 | "description": { 186 | "type": "string" 187 | }, 188 | "tag": { 189 | "type": "array", 190 | "items": { 191 | "type": "string" 192 | } 193 | } 194 | }, 195 | "title": "UserInfoReply" 196 | }, 197 | "UserInfoReq": { 198 | "type": "object", 199 | "properties": { 200 | "id": { 201 | "type": "string" 202 | } 203 | }, 204 | "title": "UserInfoReq" 205 | }, 206 | "UserSearchReply": { 207 | "type": "object", 208 | "properties": { 209 | "KeyWord": { 210 | "type": "array", 211 | "items": { 212 | "$ref": "#/definitions/UserInfoReply" 213 | } 214 | } 215 | }, 216 | "title": "UserSearchReply" 217 | }, 218 | "UserSearchReq": { 219 | "type": "object", 220 | "properties": { 221 | "keyWord": { 222 | "type": "string" 223 | } 224 | }, 225 | "title": "UserSearchReq" 226 | } 227 | }, 228 | "securityDefinitions": { 229 | "apiKey": { 230 | "type": "apiKey", 231 | "description": "Enter JWT Bearer token **_only_**", 232 | "name": "Authorization", 233 | "in": "header" 234 | } 235 | } 236 | } 237 | -------------------------------------------------------------------------------- /example/sys/user.api: -------------------------------------------------------------------------------- 1 | type ( 2 | RegisterReq { 3 | Username string `json:"username"` 4 | Password string `json:"password"` 5 | Mobile string `json:"mobile"` 6 | } 7 | ) 8 | -------------------------------------------------------------------------------- /example/test.api: -------------------------------------------------------------------------------- 1 | info( 2 | title: "type title here" 3 | desc: "type desc here" 4 | author: "type author here" 5 | email: "type email here" 6 | version: "type version here" 7 | ) 8 | 9 | import "sys/user.api" 10 | 11 | service user-api { 12 | @doc( 13 | summary: 注册 14 | ) 15 | @handler register 16 | post /api/user/register (RegisterReq) 17 | } -------------------------------------------------------------------------------- /example/user.api: -------------------------------------------------------------------------------- 1 | info( 2 | title: "type title here" 3 | desc: "type desc here" 4 | author: "type author here" 5 | email: "type email here" 6 | version: "type version here" 7 | ) 8 | 9 | type ( 10 | 11 | //注册请求结构 12 | RegisterReq { 13 | Username string `json:"username"` 14 | Password string `json:"password"` 15 | Mobile string `json:"mobile"` 16 | } 17 | 18 | LoginReq { 19 | Username string `json:"username"` //测试 20 | Password string `json:"password"` //测试2 21 | AppId string `header:"appId"` //APPID-TEST 22 | } 23 | UserInfoReq { 24 | Id string `path:"id"` 25 | } 26 | 27 | UserInfoReply { 28 | Name string `json:"name"` 29 | Age int `json:"age"` 30 | Birthday string `json:"birthday"` 31 | Description string `json:"description"` 32 | Tag []string `json:"tag"` 33 | Tags [][]string `json:"tags"` 34 | } 35 | 36 | UserSearchReq { 37 | KeyWord string `form:"keyWord"` // 关键词 38 | } 39 | 40 | ErrorResponse { 41 | Code string `json:"code"` 42 | Message string `json:"message"` 43 | } 44 | ) 45 | 46 | @server( 47 | prefix: /api 48 | ) 49 | 50 | service user-api { 51 | @doc( 52 | summary: 注册 53 | ) 54 | @handler register 55 | post /user/register (RegisterReq) 56 | 57 | @doc( 58 | summary: 登录 59 | ) 60 | @handler login 61 | post /user/login (LoginReq) 62 | 63 | @doc( 64 | summary: 获取用户信息 65 | ) 66 | @handler getUserInfo 67 | /* 68 | @respdoc-400 ( 69 | 100101: out of authority 70 | 100102: user not exist 71 | ) // Error code list 72 | */ 73 | /* @respdoc-500 (ErrorResponse) // Server Error */ 74 | get /user/:id (UserInfoReq) returns (UserInfoReply) 75 | 76 | @doc( 77 | summary: 用户搜索 78 | ) 79 | @handler searchUser 80 | get /user/search (UserSearchReq) returns (UserInfoReply) 81 | } -------------------------------------------------------------------------------- /example/user.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "title": "type title here", 5 | "description": "type desc here", 6 | "version": "type version here" 7 | }, 8 | "schemes": [ 9 | "http", 10 | "https" 11 | ], 12 | "consumes": [ 13 | "application/json" 14 | ], 15 | "produces": [ 16 | "application/json" 17 | ], 18 | "paths": { 19 | "/api/user/login": { 20 | "post": { 21 | "summary": "登录", 22 | "operationId": "login", 23 | "responses": { 24 | "200": { 25 | "description": "A successful response.", 26 | "schema": {} 27 | } 28 | }, 29 | "parameters": [ 30 | { 31 | "name": "body", 32 | "in": "body", 33 | "required": true, 34 | "schema": { 35 | "$ref": "#/definitions/LoginReq" 36 | } 37 | } 38 | ], 39 | "tags": [ 40 | "user-api" 41 | ] 42 | } 43 | }, 44 | "/api/user/register": { 45 | "post": { 46 | "summary": "注册", 47 | "operationId": "register", 48 | "responses": { 49 | "200": { 50 | "description": "A successful response.", 51 | "schema": {} 52 | } 53 | }, 54 | "parameters": [ 55 | { 56 | "name": "body", 57 | "description": "注册请求结构", 58 | "in": "body", 59 | "required": true, 60 | "schema": { 61 | "$ref": "#/definitions/RegisterReq" 62 | } 63 | } 64 | ], 65 | "tags": [ 66 | "user-api" 67 | ] 68 | } 69 | }, 70 | "/api/user/search": { 71 | "get": { 72 | "summary": "用户搜索", 73 | "operationId": "searchUser", 74 | "responses": { 75 | "200": { 76 | "description": "A successful response.", 77 | "schema": { 78 | "$ref": "#/definitions/UserInfoReply" 79 | } 80 | } 81 | }, 82 | "parameters": [ 83 | { 84 | "name": "keyWord", 85 | "description": " 关键词", 86 | "in": "query", 87 | "required": true, 88 | "type": "string" 89 | } 90 | ], 91 | "tags": [ 92 | "user-api" 93 | ] 94 | } 95 | }, 96 | "/api/user/{id}": { 97 | "get": { 98 | "summary": "获取用户信息", 99 | "operationId": "getUserInfo", 100 | "responses": { 101 | "200": { 102 | "description": "A successful response.", 103 | "schema": { 104 | "$ref": "#/definitions/UserInfoReply" 105 | } 106 | }, 107 | "400": { 108 | "description": "Error code list", 109 | "schema": { 110 | "example": "{\"100101\":\"out of authority\",\"100102\":\"user not exist\"}" 111 | } 112 | }, 113 | "500": { 114 | "description": "Server Error", 115 | "schema": { 116 | "$ref": "#/definitions/ErrorResponse" 117 | } 118 | } 119 | }, 120 | "parameters": [ 121 | { 122 | "name": "id", 123 | "in": "path", 124 | "required": true, 125 | "type": "string" 126 | } 127 | ], 128 | "tags": [ 129 | "user-api" 130 | ] 131 | } 132 | } 133 | }, 134 | "definitions": { 135 | "ErrorResponse": { 136 | "type": "object", 137 | "properties": { 138 | "code": { 139 | "type": "string" 140 | }, 141 | "message": { 142 | "type": "string" 143 | } 144 | }, 145 | "title": "ErrorResponse", 146 | "required": [ 147 | "code", 148 | "message" 149 | ] 150 | }, 151 | "LoginReq": { 152 | "type": "object", 153 | "properties": { 154 | "username": { 155 | "type": "string", 156 | "description": "测试" 157 | }, 158 | "password": { 159 | "type": "string", 160 | "description": "测试2" 161 | } 162 | }, 163 | "title": "LoginReq", 164 | "required": [ 165 | "username", 166 | "password" 167 | ] 168 | }, 169 | "RegisterReq": { 170 | "type": "object", 171 | "properties": { 172 | "username": { 173 | "type": "string" 174 | }, 175 | "password": { 176 | "type": "string" 177 | }, 178 | "mobile": { 179 | "type": "string" 180 | } 181 | }, 182 | "title": "RegisterReq", 183 | "required": [ 184 | "username", 185 | "password", 186 | "mobile" 187 | ] 188 | }, 189 | "UserInfoReply": { 190 | "type": "object", 191 | "properties": { 192 | "name": { 193 | "type": "string" 194 | }, 195 | "age": { 196 | "type": "integer", 197 | "format": "int32" 198 | }, 199 | "birthday": { 200 | "type": "string" 201 | }, 202 | "description": { 203 | "type": "string" 204 | }, 205 | "tag": { 206 | "type": "array", 207 | "items": { 208 | "type": "string" 209 | } 210 | }, 211 | "tags": { 212 | "type": "array", 213 | "items": { 214 | "type": "array", 215 | "items": { 216 | "type": "string" 217 | } 218 | } 219 | } 220 | }, 221 | "title": "UserInfoReply", 222 | "required": [ 223 | "name", 224 | "age", 225 | "birthday", 226 | "description", 227 | "tag", 228 | "tags" 229 | ] 230 | }, 231 | "UserInfoReq": { 232 | "type": "object", 233 | "title": "UserInfoReq" 234 | }, 235 | "UserSearchReq": { 236 | "type": "object", 237 | "properties": { 238 | "keyWord": { 239 | "type": "string", 240 | "description": " 关键词" 241 | } 242 | }, 243 | "title": "UserSearchReq", 244 | "required": [ 245 | "keyWord" 246 | ] 247 | } 248 | }, 249 | "securityDefinitions": { 250 | "apiKey": { 251 | "type": "apiKey", 252 | "description": "Enter JWT Bearer token **_only_**", 253 | "name": "Authorization", 254 | "in": "header" 255 | } 256 | } 257 | } 258 | -------------------------------------------------------------------------------- /generate/generate.go: -------------------------------------------------------------------------------- 1 | package generate 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | "fmt" 7 | "io/ioutil" 8 | 9 | "github.com/zeromicro/go-zero/tools/goctl/plugin" 10 | ) 11 | 12 | func Do(filename string, host string, basePath string, schemes string, in *plugin.Plugin) error { 13 | swagger, err := applyGenerate(in, host, basePath, schemes) 14 | if err != nil { 15 | fmt.Println(err) 16 | } 17 | var formatted bytes.Buffer 18 | enc := json.NewEncoder(&formatted) 19 | enc.SetIndent("", " ") 20 | 21 | if err := enc.Encode(swagger); err != nil { 22 | fmt.Println(err) 23 | } 24 | 25 | output := in.Dir + "/" + filename 26 | 27 | err = ioutil.WriteFile(output, formatted.Bytes(), 0666) 28 | if err != nil { 29 | fmt.Println(err) 30 | } 31 | return err 32 | } 33 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/zeromicro/goctl-swagger 2 | 3 | go 1.16 4 | 5 | require ( 6 | github.com/grpc-ecosystem/grpc-gateway v1.16.0 7 | github.com/urfave/cli/v2 v2.11.0 8 | github.com/zeromicro/go-zero v1.6.5 9 | github.com/zeromicro/go-zero/tools/goctl v1.6.5 10 | golang.org/x/oauth2 v0.17.0 11 | ) 12 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "runtime" 7 | 8 | "github.com/urfave/cli/v2" 9 | "github.com/zeromicro/goctl-swagger/action" 10 | ) 11 | 12 | var ( 13 | version = "20220621" 14 | commands = []*cli.Command{ 15 | { 16 | Name: "swagger", 17 | Usage: "generates swagger.json", 18 | Action: action.Generator, 19 | Flags: []cli.Flag{ 20 | &cli.StringFlag{ 21 | Name: "host", 22 | Usage: "api request address", 23 | }, 24 | &cli.StringFlag{ 25 | Name: "basepath", 26 | Usage: "url request prefix", 27 | }, 28 | &cli.StringFlag{ 29 | Name: "filename", 30 | Usage: "swagger save file name", 31 | }, 32 | &cli.StringFlag{ 33 | Name: "schemes", 34 | Usage: "swagger support schemes: http, https, ws, wss", 35 | }, 36 | }, 37 | }, 38 | } 39 | ) 40 | 41 | func main() { 42 | app := cli.NewApp() 43 | app.Usage = "a plugin of goctl to generate swagger.json" 44 | app.Version = fmt.Sprintf("%s %s/%s", version, runtime.GOOS, runtime.GOARCH) 45 | app.Commands = commands 46 | if err := app.Run(os.Args); err != nil { 47 | fmt.Printf("goctl-swagger: %+v\n", err) 48 | } 49 | } 50 | --------------------------------------------------------------------------------