Skip to content

Commit

Permalink
Merge pull request #87 from masseelch/main
Browse files Browse the repository at this point in the history
feat(dsl): set schema type to "object" if properties are set
  • Loading branch information
ernado authored Dec 20, 2021
2 parents b20c283 + b7e780f commit 7d0e757
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions dsl.go
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,7 @@ func (s *Schema) SetFormat(f string) *Schema {

// SetProperties sets the Properties of the Schema.
func (s *Schema) SetProperties(p *Properties) *Schema {
s.SetType("object")
if p != nil {
s.Properties = *p
}
Expand All @@ -798,6 +799,7 @@ func (s *Schema) SetProperties(p *Properties) *Schema {

// AddOptionalProperties adds the Properties to the Properties of the Schema.
func (s *Schema) AddOptionalProperties(ps ...*Property) *Schema {
s.SetType("object")
for _, p := range ps {
if p != nil {
s.Properties = append(s.Properties, *p)
Expand Down
4 changes: 3 additions & 1 deletion dsl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ func TestBuilder(t *testing.T) {
Description: "Success",
Content: map[string]ogen.Media{
string(ir.ContentTypeJSON): {Schema: ogen.Schema{
Type: "object",
Description: "Success",
Properties: []ogen.Property{
{Name: "prop1", Schema: &ogen.Schema{Type: "integer", Format: "int32"}},
Expand Down Expand Up @@ -168,6 +169,7 @@ func TestBuilder(t *testing.T) {
Description: "An Error Response",
Content: map[string]ogen.Media{
string(ir.ContentTypeJSON): {Schema: ogen.Schema{
Type: "object",
Description: "Error Response Schema",
Properties: []ogen.Property{
{Name: "code", Schema: &ogen.Schema{Type: "integer", Format: "int32"}},
Expand Down Expand Up @@ -342,7 +344,7 @@ func TestBuilder(t *testing.T) {
assert.Equal(t, &ogen.Schema{
Ref: "ref",
Description: "desc",
Type: "string",
Type: "object",
Format: "",
Properties: []ogen.Property{{Name: "prop"}},
Required: []string{"prop"},
Expand Down

0 comments on commit 7d0e757

Please sign in to comment.