feat: complete API-driven projects with infrastructure and business acceptance
This commit is contained in:
48
openapi/schemaJSON_test.go
Normal file
48
openapi/schemaJSON_test.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package openapi
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.yuntuo.hk/k2safe/go-omni/httpx"
|
||||
)
|
||||
|
||||
func TestSchemaAdditionalPropertiesAndExactNumbers(t *testing.T) {
|
||||
for _, text := range []string{
|
||||
`{"type":"object","additionalProperties":false}`,
|
||||
`{"type":"object","additionalProperties":true}`,
|
||||
`{"type":"object","additionalProperties":{"type":"string"}}`,
|
||||
`{"type":"integer","default":18446744073709551615,"enum":[18446744073709551615]}`,
|
||||
} {
|
||||
var s Schema
|
||||
if err := json.Unmarshal([]byte(text), &s); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b, err := json.Marshal(s)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if strings.Contains(text, "18446744073709551615") && !strings.Contains(string(b), "18446744073709551615") {
|
||||
t.Fatalf("lost precision: %s", b)
|
||||
}
|
||||
var roundTrip Schema
|
||||
if err = json.Unmarshal(b, &roundTrip); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
api, _ := New("Exact numbers", "1")
|
||||
s := &Schema{Type: "integer", Enum: []any{json.Number("18446744073709551615")}}
|
||||
err := api.Handle(discardSchemaRoutes{}, Operation{Method: "get", Path: "/id", OperationID: "readId", Responses: map[int]Response{200: {Description: "ok", Schema: s}}}, func(*httpx.Context) error { return nil })
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
data, _ := api.JSON()
|
||||
if !strings.Contains(string(data), "18446744073709551615") {
|
||||
t.Fatal(string(data))
|
||||
}
|
||||
}
|
||||
|
||||
type discardSchemaRoutes struct{}
|
||||
|
||||
func (discardSchemaRoutes) Handle(string, string, httpx.Handler, ...httpx.Middleware) {}
|
||||
Reference in New Issue
Block a user