alex-korobko 42544b8234 Issue 1766 Modified mustache files for Go to support nullable in the … (#1869)
* Issue 1766 Modified mustache files for Go to support nullable in the spec v3.0+; Updated model files running .sh scripts for Go.

* Add "nullable" to fake yaml

* Add sample script for OAS3

* Fix output folder (openapi3)

* Run bin/openapi3/go-petstore.sh

* Update samples

* Update jaxrs-jersey

* Update python and php samples

* Add bin/openapi3/go-gin-petstore-server.sh

* Run bin/openapi3/go-gin-petstore-server.sh

* Update bin/openapi3/go-petstore-server.sh to generate "nullable" samples

* Run bin/openapi3/go-petstore-server.sh

* Fix duplicated `import`
2019-02-15 11:08:52 +09:00
..

Go API Server for petstoreserver

This is a sample server Petstore server. For this sample, you can use the api key special-key to test the authorization filters.

Overview

This server was generated by the [openapi-generator] (https://openapi-generator.tech) project. By using the OpenAPI-Spec from a remote server, you can easily generate a server stub.

To see how to make this your own, look here:

README

  • API version: 1.0.0

Running the server

To run the server, follow these simple steps:

go run main.go

To run the server in a docker container

docker build --network=host -t petstoreserver .

Once image is built use

docker run --rm -it petstoreserver 

Known Issue

The endpoint /v2/pet/findByTags and /v2/pet/:petId are conflict with gin. This is a known issue of gin. Please refer gin-gonic/gin#388

You can manually fix it by updating the path and handler. Please refer gin-gonic/gin/issues/205#issuecomment-296155497 and an example below.

routers.go

var routes = Routes{
	{
		"Index",
		"GET",
		"/v2/",
		Index,
	},

-	{
-		"FindPetsByTags",
-		strings.ToUpper("Get"),
-		"/v2/pet/findByTags",
-		FindPetsByTags,
-	},

	{
		"GetPetById",
		strings.ToUpper("Get"),
		"/v2/pet/:petId",
		GetPetById,
	},
}

api_pet.go

// GetPetById - Find pet by ID
func GetPetById(c *gin.Context) {
-       c.JSON(http.StatusOK, gin.H{})
+       petId := c.Param("petId")
+
+       if petId == "findByTags" {
+               FindPetsByTags(c)
+       } else {
+               c.JSON(http.StatusOK, gin.H{})
+       }
}