|
| 1 | +# Go API client for petstore |
| 2 | + |
| 3 | +This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. |
| 4 | + |
| 5 | +## Overview |
| 6 | +This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [OpenAPI-spec](https://www.openapis.org/) from a remote server, you can easily generate an API client. |
| 7 | + |
| 8 | +- API version: 1.0.0 |
| 9 | +- Package version: 1.0.0 |
| 10 | +- Generator version: 7.16.0-SNAPSHOT |
| 11 | +- Build package: org.openapitools.codegen.languages.GoClientCodegen |
| 12 | + |
| 13 | +## Installation |
| 14 | + |
| 15 | +Install the following dependencies: |
| 16 | + |
| 17 | +```sh |
| 18 | +go get github.com/stretchr/testify/assert |
| 19 | +go get golang.org/x/oauth2 |
| 20 | +go get golang.org/x/net/context |
| 21 | +``` |
| 22 | + |
| 23 | +Put the package under your project folder and add the following in import: |
| 24 | + |
| 25 | +```go |
| 26 | +import petstore "github.com/GIT_USER_ID/GIT_REPO_ID" |
| 27 | +``` |
| 28 | + |
| 29 | +To use a proxy, set the environment variable `HTTP_PROXY`: |
| 30 | + |
| 31 | +```go |
| 32 | +os.Setenv("HTTP_PROXY", "http://proxy_name:proxy_port") |
| 33 | +``` |
| 34 | + |
| 35 | +## Configuration of Server URL |
| 36 | + |
| 37 | +Default configuration comes with `Servers` field that contains server objects as defined in the OpenAPI specification. |
| 38 | + |
| 39 | +### Select Server Configuration |
| 40 | + |
| 41 | +For using other server than the one defined on index 0 set context value `petstore.ContextServerIndex` of type `int`. |
| 42 | + |
| 43 | +```go |
| 44 | +ctx := context.WithValue(context.Background(), petstore.ContextServerIndex, 1) |
| 45 | +``` |
| 46 | + |
| 47 | +### Templated Server URL |
| 48 | + |
| 49 | +Templated server URL is formatted using default variables from configuration or from context value `petstore.ContextServerVariables` of type `map[string]string`. |
| 50 | + |
| 51 | +```go |
| 52 | +ctx := context.WithValue(context.Background(), petstore.ContextServerVariables, map[string]string{ |
| 53 | + "basePath": "v2", |
| 54 | +}) |
| 55 | +``` |
| 56 | + |
| 57 | +Note, enum values are always validated and all unused variables are silently ignored. |
| 58 | + |
| 59 | +### URLs Configuration per Operation |
| 60 | + |
| 61 | +Each operation can use different server URL defined using `OperationServers` map in the `Configuration`. |
| 62 | +An operation is uniquely identified by `"{classname}Service.{nickname}"` string. |
| 63 | +Similar rules for overriding default operation server index and variables applies by using `petstore.ContextOperationServerIndices` and `petstore.ContextOperationServerVariables` context maps. |
| 64 | + |
| 65 | +```go |
| 66 | +ctx := context.WithValue(context.Background(), petstore.ContextOperationServerIndices, map[string]int{ |
| 67 | + "{classname}Service.{nickname}": 2, |
| 68 | +}) |
| 69 | +ctx = context.WithValue(context.Background(), petstore.ContextOperationServerVariables, map[string]map[string]string{ |
| 70 | + "{classname}Service.{nickname}": { |
| 71 | + "port": "8443", |
| 72 | + }, |
| 73 | +}) |
| 74 | +``` |
| 75 | + |
| 76 | +## Documentation for API Endpoints |
| 77 | + |
| 78 | +All URIs are relative to *http://petstore.swagger.io/v2* |
| 79 | + |
| 80 | +Class | Method | HTTP request | Description |
| 81 | +------------ | ------------- | ------------- | ------------- |
| 82 | +*PetAPI* | [**AddPet**](docs/PetAPI.md#addpet) | **Post** /pet | Add a new pet to the store |
| 83 | + |
| 84 | + |
| 85 | +## Documentation For Models |
| 86 | + |
| 87 | + - [Category](docs/Category.md) |
| 88 | + - [Pet](docs/Pet.md) |
| 89 | + - [Tag](docs/Tag.md) |
| 90 | + |
| 91 | + |
| 92 | +## Documentation For Authorization |
| 93 | + |
| 94 | + |
| 95 | +Authentication schemes defined for the API: |
| 96 | +### petstore_auth |
| 97 | + |
| 98 | + |
| 99 | +- **Type**: OAuth |
| 100 | +- **Flow**: implicit |
| 101 | +- **Authorization URL**: http://petstore.swagger.io/api/oauth/dialog |
| 102 | +- **Scopes**: |
| 103 | + - **write:pets**: modify pets in your account |
| 104 | + - **read:pets**: read your pets |
| 105 | + |
| 106 | +Example |
| 107 | + |
| 108 | +```go |
| 109 | +auth := context.WithValue(context.Background(), petstore.ContextAccessToken, "ACCESSTOKENSTRING") |
| 110 | +r, err := client.Service.Operation(auth, args) |
| 111 | +``` |
| 112 | + |
| 113 | +Or via OAuth2 module to automatically refresh tokens and perform user authentication. |
| 114 | + |
| 115 | +```go |
| 116 | +import "golang.org/x/oauth2" |
| 117 | + |
| 118 | +/* Perform OAuth2 round trip request and obtain a token */ |
| 119 | + |
| 120 | +tokenSource := oauth2cfg.TokenSource(createContext(httpClient), &token) |
| 121 | +auth := context.WithValue(oauth2.NoContext, petstore.ContextOAuth2, tokenSource) |
| 122 | +r, err := client.Service.Operation(auth, args) |
| 123 | +``` |
| 124 | + |
| 125 | + |
| 126 | +## Documentation for Utility Methods |
| 127 | + |
| 128 | +Due to the fact that model structure members are all pointers, this package contains |
| 129 | +a number of utility functions to easily obtain pointers to values of basic types. |
| 130 | +Each of these functions takes a value of the given basic type and returns a pointer to it: |
| 131 | + |
| 132 | +* `PtrBool` |
| 133 | +* `PtrInt` |
| 134 | +* `PtrInt32` |
| 135 | +* `PtrInt64` |
| 136 | +* `PtrFloat` |
| 137 | +* `PtrFloat32` |
| 138 | +* `PtrFloat64` |
| 139 | +* `PtrString` |
| 140 | +* `PtrTime` |
| 141 | + |
| 142 | +## Author |
| 143 | + |
| 144 | + |
| 145 | + |
0 commit comments