hackerman 93488f4195
Resolve several issues in generated Go code (#8491)
* [go] use regular stdlib import names

* [go] support primitive oneOf types

See #8489

* [go] improve pbv/pbr handling

Improves the way pass-by-value and pass-by-reference variables are used.

Closes #8489

* [go] improve generated documentation

* [go] adopt pointer changes in interface

* [go] regenerate sample

* [go] resolve pointer issues

* [go] regenerate clients and avoid pointers on primitive return values

* [go] improve Exec() return value handling

* [go] regernate files

* [go] use go modules

* [go] properly handle polymorph decode

If polymorphism without discriminator was used, the previous code was unable to properly decode the vaules. By using a strict decoder, which rejects unknown fields, type guessing now works.

* [go] make GetActualInstance not panic on nil

* [go] return GenericOpenAPIError as pointer

* [go] clarify helper function godoc

* [go] address test regression error type

* [go] regenerate go samples

* [go] resolve go mod issues and test regressions

* [go] resolve merge conflicts and regenerate

* [go] resolve merge conflicts

* [go] Replace spaces with tabs

Co-authored-by: Jiri Kuncar <jiri.kuncar@gmail.com>

* [go] Replace spaces with tabs

Co-authored-by: Jiri Kuncar <jiri.kuncar@gmail.com>

Co-authored-by: Jiri Kuncar <jiri.kuncar@gmail.com>
2022-01-21 16:54:09 +08:00

44 lines
1.3 KiB
Go

package main
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
sw "go-petstore"
)
func TestBanana(t *testing.T) {
assert := assert.New(t)
lengthCm := float32(2.3)
lengthCm2 := float32(2.4)
newBanana := (sw.Banana{LengthCm: &lengthCm})
newBanana.LengthCm = &lengthCm2
assert.Equal(newBanana.LengthCm, &lengthCm2, "Banana LengthCm should be equal")
// test additioanl properties
jsonBanana := `{"fruits":["apple","peach"],"lengthCm":3.1}`
jsonMap := make(map[string]interface{})
json.Unmarshal([]byte(jsonBanana), &jsonMap)
newBanana2 := (sw.Banana{})
lengthCm3 := float32(3.1)
json.Unmarshal([]byte(jsonBanana), &newBanana2)
assert.Equal(newBanana2.LengthCm, &lengthCm3, "Banana2 LengthCm should be equal")
assert.Equal(newBanana2.AdditionalProperties["fruits"], jsonMap["fruits"], "Banana2 AdditonalProperties should be equal")
newBanana2Json, _ := json.Marshal(newBanana2)
assert.Equal(string(newBanana2Json), jsonBanana, "Banana2 JSON string should be equal")
}
func TestDog(t *testing.T) {
assert := assert.New(t)
newDog := (sw.Dog{})
jsonDog := `{"breed":"Shepherd","className":"dog","color":"white"}`
json.Unmarshal([]byte(jsonDog), &newDog)
breedString := "Shepherd"
//assert.Nil(newDog)
assert.Equal(*newDog.Breed, breedString, "Breed should be `Shepherd`")
}