Skip to content

Commit

Permalink
Update test - disable required check to render all examples
Browse files Browse the repository at this point in the history
Test default behaviour when required check is not disabled
  • Loading branch information
martinsirbe committed May 23, 2024
1 parent 2aac9d8 commit 62a8c1b
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions renderer/mock_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package renderer
import (
"context"
"encoding/json"

"github.com/pb33f/libopenapi/datamodel/high/base"
"github.com/pb33f/libopenapi/datamodel/low"
lowbase "github.com/pb33f/libopenapi/datamodel/low/base"
Expand Down Expand Up @@ -443,9 +444,46 @@ properties:

fake := createFakeMock(yml, nil, nil)
mg := NewMockGenerator(JSON)
mg.DisableRequiredCheck()

mock, err := mg.GenerateMock(fake, "")
require.NoError(t, err)

assert.Equal(t, `{"active":true,"balance":99.99,"id":123,"name":"John Doe","tags":["tag1","tag2","tag3"]}`, string(mock))
}

func TestMockGenerator_GenerateExamplesForRequiredProperties(t *testing.T) {

yml := `type: object
required:
- id
- name
properties:
id:
type: integer
example: 123
name:
type: string
example: "John Doe"
active:
type: boolean
example: true
balance:
type: number
format: float
example: 99.99
tags:
type: array
items:
type: string
example: ["tag1", "tag2", "tag3"]
`

fake := createFakeMock(yml, nil, nil)
mg := NewMockGenerator(JSON)

mock, err := mg.GenerateMock(fake, "")
require.NoError(t, err)

assert.Equal(t, `{"id":123,"name":"John Doe"}`, string(mock))
}

0 comments on commit 62a8c1b

Please sign in to comment.