Skip to content

Commit

Permalink
more test coverage and filling gaps on schema renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
daveshanley committed May 1, 2024
1 parent 7f945e3 commit 8a1d3ae
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions renderer/schema_renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ func (wr *SchemaRenderer) DiveIntoSchema(schema *base.Schema, key string, struct
structure[key] = wr.RandomWord(minLength, maxLength, 0)
case binaryType:
structure[key] = base64.StdEncoding.EncodeToString([]byte(wr.RandomWord(minLength, maxLength, 0)))
case bigIntType:
structure[key] = fmt.Sprint(wr.RandomInt(minLength, maxLength))
case decimalType:
structure[key] = fmt.Sprint(wr.RandomFloat64())
default:
// if there is a pattern supplied, then try and generate a string from it.
if schema.Pattern != "" {
Expand Down
27 changes: 27 additions & 0 deletions renderer/schema_renderer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,33 @@ properties:
assert.Equal(t, `{"bigint":8821239038968084,"bigintStr":"9223372036854775808","decimal":3.141592653589793,"decimalStr":"3.14159265358979344719667586"}`, string(rendered))
}

func TestRenderSchema_NonStandard_Format_NoExamples(t *testing.T) {
testObject := `type: object
properties:
bigint:
type: integer
format: bigint
bigintStr:
type: string
format: bigint
decimal:
type: number
format: decimal
decimalStr:
type: string
format: decimal
`

compiled := getSchema([]byte(testObject))
schema := make(map[string]any)
wr := createSchemaRenderer()
wr.DiveIntoSchema(compiled, "pb33f", schema, 0)
assert.NotEmpty(t, schema["pb33f"].(map[string]interface{})["bigint"])
assert.NotEmpty(t, schema["pb33f"].(map[string]interface{})["bigintStr"])
assert.NotEmpty(t, schema["pb33f"].(map[string]interface{})["decimal"])
assert.NotEmpty(t, schema["pb33f"].(map[string]interface{})["decimalStr"])
}

func TestCreateRendererUsingDefaultDictionary(t *testing.T) {
assert.NotNil(t, CreateRendererUsingDefaultDictionary())
}
Expand Down

0 comments on commit 8a1d3ae

Please sign in to comment.