Skip to content

Commit

Permalink
Merge pull request #10155 from swagger-api/go_samples
Browse files Browse the repository at this point in the history
Go samples
  • Loading branch information
HugoMario committed Apr 6, 2020
2 parents 95a3cf0 + 1f7133c commit 72803fb
Show file tree
Hide file tree
Showing 146 changed files with 11,244 additions and 7 deletions.
4 changes: 2 additions & 2 deletions bin/go-petstore-server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ fi
# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -Dlogback.configurationFile=bin/logback.xml"

ags="$@ generate -t modules/swagger-codegen/target/classes/go-server -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l go-server -o samples/server/petstore/go-api-server -DpackageName=petstoreserver --additional-properties hideGenerationTimestamp=true -Dservice"
ags="$@ generate -i modules/swagger-codegen/src/test/resources/3_0_0/petstore.yaml -l go-server -o samples/server/petstore/go-api-server -DpackageName=petstoreserver --additional-properties hideGenerationTimestamp=true -Dservice"

# java $JAVA_OPTS -jar $executable $ags
java $JAVA_OPTS -jar $executable $ags
4 changes: 2 additions & 2 deletions bin/go-petstore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ fi

# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -Dlogback.configurationFile=bin/logback.xml"
ags="$@ generate -t modules/swagger-codegen/target/classes/go -i modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -l go -o samples/client/petstore/go/go-petstore -DpackageName=petstore "
ags="$@ generate -i modules/swagger-codegen/src/test/resources/3_0_0/petstore-with-fake-endpoints-models-for-testing.yaml -l go -o samples/client/petstore/go/go-petstore -DpackageName=petstore "

# java $JAVA_OPTS -jar $executable $ags
java $JAVA_OPTS -jar $executable $ags
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ public int compare(String o1, String o2) {
continue;
}
Map<String, Object> modelTemplate = (Map<String, Object>) ((List<Object>) models.get("models")).get(0);
if (isJavaCodegen(config.getName())) {
if (isAliasVerifierGenerator(config.getName())) {
// Special handling of aliases only applies to Java
if (modelTemplate != null && modelTemplate.containsKey("model")) {
CodegenModel codegenModel = (CodegenModel) modelTemplate.get("model");
Expand Down Expand Up @@ -1112,9 +1112,11 @@ private Map<String, SecurityScheme> getAuthMethods(List<SecurityRequirement> sec
return authMethods;
}

private boolean isJavaCodegen(String name) {
private boolean isAliasVerifierGenerator(String name) {
return name.equalsIgnoreCase("java")
|| name.equalsIgnoreCase("inflector");
|| name.equalsIgnoreCase("inflector")
|| name.equalsIgnoreCase("go")
|| name.equalsIgnoreCase("go-server");
}

private Boolean getCustomOptionBooleanValue(String option) {
Expand Down
24 changes: 24 additions & 0 deletions samples/client/petstore/go/go-petstore/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so

# Folders
_obj
_test

# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out

*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*

_testmain.go

*.exe
*.test
*.prof
23 changes: 23 additions & 0 deletions samples/client/petstore/go/go-petstore/.swagger-codegen-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Swagger Codegen Ignore
# Generated by swagger-codegen https://github.com/swagger-api/swagger-codegen

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell Swagger Codgen to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.0.20-SNAPSHOT
8 changes: 8 additions & 0 deletions samples/client/petstore/go/go-petstore/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
language: go

install:
- go get -d -v .

script:
- go build -v ./

179 changes: 179 additions & 0 deletions samples/client/petstore/go/go-petstore/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
# Go API client for petstore

This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\

## Overview
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.

- API version: 1.0.0
- Package version: 1.0.0
- Build package: io.swagger.codegen.v3.generators.go.GoClientCodegen

## Installation
Put the package under your project folder and add the following in import:
```golang
import "./petstore"
```

## Documentation for API Endpoints

All URIs are relative to *http:https://petstore.swagger.io:80/v2*

Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*AnimalApi* | [**AddAnimal**](docs/AnimalApi.md#addanimal) | **Post** /animal | Add a new animal to the store
*AnimalApi* | [**DeleteAnimal**](docs/AnimalApi.md#deleteanimal) | **Delete** /animal/{animalId} | Deletes a animal
*AnimalApi* | [**GetAnimalById**](docs/AnimalApi.md#getanimalbyid) | **Get** /animal/{animalId} | Find animal by ID
*AnimalApi* | [**UpdateAnimal**](docs/AnimalApi.md#updateanimal) | **Put** /animal | Update an existing animal
*AnimalApi* | [**UpdateAnimalWithForm**](docs/AnimalApi.md#updateanimalwithform) | **Post** /animal/{animalId} | Updates a animal
*AnotherFakeApi* | [**TestSpecialTags**](docs/AnotherFakeApi.md#testspecialtags) | **Patch** /another-fake/dummy | To test special tags
*DogApi* | [**AddDog**](docs/DogApi.md#adddog) | **Post** /dog | Add a new dog to the store
*DogApi* | [**DeleteDog**](docs/DogApi.md#deletedog) | **Delete** /dog/{dogId} | Deletes a dog
*DogApi* | [**GetDogById**](docs/DogApi.md#getdogbyid) | **Get** /dog/{dogId} | Find dog by ID
*DogApi* | [**UpdateDog**](docs/DogApi.md#updatedog) | **Put** /dog | Update an existing dog
*DogApi* | [**UpdateDogWithForm**](docs/DogApi.md#updatedogwithform) | **Post** /dog/{dogId} | Updates a dog
*FakeApi* | [**FakeOuterBooleanSerialize**](docs/FakeApi.md#fakeouterbooleanserialize) | **Post** /fake/outer/boolean |
*FakeApi* | [**FakeOuterCompositeSerialize**](docs/FakeApi.md#fakeoutercompositeserialize) | **Post** /fake/outer/composite |
*FakeApi* | [**FakeOuterNumberSerialize**](docs/FakeApi.md#fakeouternumberserialize) | **Post** /fake/outer/number |
*FakeApi* | [**FakeOuterStringSerialize**](docs/FakeApi.md#fakeouterstringserialize) | **Post** /fake/outer/string |
*FakeApi* | [**TestClientModel**](docs/FakeApi.md#testclientmodel) | **Patch** /fake | To test \&quot;client\&quot; model
*FakeApi* | [**TestEndpointParameters**](docs/FakeApi.md#testendpointparameters) | **Post** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
*FakeApi* | [**TestEnumParameters**](docs/FakeApi.md#testenumparameters) | **Get** /fake | To test enum parameters
*FakeApi* | [**TestEnumRequestBody**](docs/FakeApi.md#testenumrequestbody) | **Post** /fake/enum/form | To test enum parameters
*FakeApi* | [**TestInlineAdditionalProperties**](docs/FakeApi.md#testinlineadditionalproperties) | **Post** /fake/inline-additionalProperties | test inline additionalProperties
*FakeApi* | [**TestJsonFormData**](docs/FakeApi.md#testjsonformdata) | **Post** /fake/jsonFormData | test json serialization of form data
*FakeClassnameTags123Api* | [**TestClassname**](docs/FakeClassnameTags123Api.md#testclassname) | **Patch** /fake_classname_test | To test class name in snake case
*PetApi* | [**AddPet**](docs/PetApi.md#addpet) | **Post** /pet | Add a new pet to the store
*PetApi* | [**DeletePet**](docs/PetApi.md#deletepet) | **Delete** /pet/{petId} | Deletes a pet
*PetApi* | [**DoCategoryStuff**](docs/PetApi.md#docategorystuff) | **Post** /pet/category |
*PetApi* | [**FindPetsByStatus**](docs/PetApi.md#findpetsbystatus) | **Get** /pet/findByStatus | Finds Pets by status
*PetApi* | [**FindPetsByTags**](docs/PetApi.md#findpetsbytags) | **Get** /pet/findByTags | Finds Pets by tags
*PetApi* | [**GetAllPets**](docs/PetApi.md#getallpets) | **Get** /allPets |
*PetApi* | [**GetPetById**](docs/PetApi.md#getpetbyid) | **Get** /pet/{petId} | Find pet by ID
*PetApi* | [**GetRandomPet**](docs/PetApi.md#getrandompet) | **Get** /randomPet |
*PetApi* | [**UpdatePet**](docs/PetApi.md#updatepet) | **Put** /pet | Update an existing pet
*PetApi* | [**UpdatePetWithForm**](docs/PetApi.md#updatepetwithform) | **Post** /pet/{petId} | Updates a pet in the store with form data
*PetApi* | [**UploadFile**](docs/PetApi.md#uploadfile) | **Post** /pet/{petId}/uploadImage | uploads an image
*StoreApi* | [**DeleteOrder**](docs/StoreApi.md#deleteorder) | **Delete** /store/order/{order_id} | Delete purchase order by ID
*StoreApi* | [**GetInventory**](docs/StoreApi.md#getinventory) | **Get** /store/inventory | Returns pet inventories by status
*StoreApi* | [**GetOrderById**](docs/StoreApi.md#getorderbyid) | **Get** /store/order/{order_id} | Find purchase order by ID
*StoreApi* | [**PlaceOrder**](docs/StoreApi.md#placeorder) | **Post** /store/order | Place an order for a pet
*UserApi* | [**CreateUser**](docs/UserApi.md#createuser) | **Post** /user | Create user
*UserApi* | [**CreateUsersWithArrayInput**](docs/UserApi.md#createuserswitharrayinput) | **Post** /user/createWithArray | Creates list of users with given input array
*UserApi* | [**CreateUsersWithListInput**](docs/UserApi.md#createuserswithlistinput) | **Post** /user/createWithList | Creates list of users with given input array
*UserApi* | [**DeleteUser**](docs/UserApi.md#deleteuser) | **Delete** /user/{username} | Delete user
*UserApi* | [**GetUserByName**](docs/UserApi.md#getuserbyname) | **Get** /user/{username} | Get user by user name
*UserApi* | [**LoginUser**](docs/UserApi.md#loginuser) | **Get** /user/login | Logs user into the system
*UserApi* | [**LogoutUser**](docs/UserApi.md#logoutuser) | **Get** /user/logout | Logs out current logged in user session
*UserApi* | [**UpdateUser**](docs/UserApi.md#updateuser) | **Put** /user/{username} | Updated user

## Documentation For Models

- [AdditionalPropertiesClass](docs/AdditionalPropertiesClass.md)
- [AllOfSubCategoryCategory](docs/AllOfSubCategoryCategory.md)
- [AllOfSubCategoryPetsItems](docs/AllOfSubCategoryPetsItems.md)
- [Animal](docs/Animal.md)
- [ArrayOfArrayOfNumberOnly](docs/ArrayOfArrayOfNumberOnly.md)
- [ArrayOfNumberOnly](docs/ArrayOfNumberOnly.md)
- [ArrayTest](docs/ArrayTest.md)
- [Body](docs/Body.md)
- [Body1](docs/Body1.md)
- [Body2](docs/Body2.md)
- [Body3](docs/Body3.md)
- [Body4](docs/Body4.md)
- [Body5](docs/Body5.md)
- [Body6](docs/Body6.md)
- [Body7](docs/Body7.md)
- [Capitalization](docs/Capitalization.md)
- [Cat](docs/Cat.md)
- [Category](docs/Category.md)
- [ClassModel](docs/ClassModel.md)
- [Client](docs/Client.md)
- [Dog](docs/Dog.md)
- [EnumArrays](docs/EnumArrays.md)
- [EnumTest](docs/EnumTest.md)
- [FormatTest](docs/FormatTest.md)
- [HasOnlyReadOnly](docs/HasOnlyReadOnly.md)
- [List](docs/List.md)
- [MapTest](docs/MapTest.md)
- [MixedPropertiesAndAdditionalPropertiesClass](docs/MixedPropertiesAndAdditionalPropertiesClass.md)
- [Model200Response](docs/Model200Response.md)
- [ModelApiResponse](docs/ModelApiResponse.md)
- [ModelReturn](docs/ModelReturn.md)
- [Name](docs/Name.md)
- [NullableEnumModel](docs/NullableEnumModel.md)
- [NumberOnly](docs/NumberOnly.md)
- [OneOfAllPetsResponseItems](docs/OneOfAllPetsResponseItems.md)
- [OneOfSinglePetResponsePet](docs/OneOfSinglePetResponsePet.md)
- [Order](docs/Order.md)
- [OuterComposite](docs/OuterComposite.md)
- [Pet](docs/Pet.md)
- [ReadOnlyFirst](docs/ReadOnlyFirst.md)
- [SinglePetResponse](docs/SinglePetResponse.md)
- [SpecialModelName](docs/SpecialModelName.md)
- [SubCategory](docs/SubCategory.md)
- [Tag](docs/Tag.md)
- [User](docs/User.md)

## Documentation For Authorization

## api_key
- **Type**: API key

Example
```golang
auth := context.WithValue(context.Background(), sw.ContextAPIKey, sw.APIKey{
Key: "APIKEY",
Prefix: "Bearer", // Omit if not necessary.
})
r, err := client.Service.Operation(auth, args)
```
## api_key_query
- **Type**: API key

Example
```golang
auth := context.WithValue(context.Background(), sw.ContextAPIKey, sw.APIKey{
Key: "APIKEY",
Prefix: "Bearer", // Omit if not necessary.
})
r, err := client.Service.Operation(auth, args)
```
## http_basic_test
- **Type**: HTTP basic authentication

Example
```golang
auth := context.WithValue(context.Background(), sw.ContextBasicAuth, sw.BasicAuth{
UserName: "username",
Password: "password",
})
r, err := client.Service.Operation(auth, args)
```
## petstore_auth
- **Type**: OAuth
- **Flow**: implicit
- **Authorization URL**: http:https://petstore.swagger.io/api/oauth/dialog
- **Scopes**:
- ****:

Example
```golang
auth := context.WithValue(context.Background(), sw.ContextAccessToken, "ACCESSTOKENSTRING")
r, err := client.Service.Operation(auth, args)
```

Or via OAuth2 module to automatically refresh tokens and perform user authentication.
```golang
import "golang.org/x/oauth2"

/* Perform OAuth2 round trip request and obtain a token */

tokenSource := oauth2cfg.TokenSource(createContext(httpClient), &token)
auth := context.WithValue(oauth2.NoContext, sw.ContextOAuth2, tokenSource)
r, err := client.Service.Operation(auth, args)
```

## Author

[email protected]
Loading

0 comments on commit 72803fb

Please sign in to comment.