Skip to content

Commit

Permalink
test: add regression test for pointer optionals
Browse files Browse the repository at this point in the history
  • Loading branch information
tdakkota committed Sep 10, 2024
1 parent 66d4902 commit 350f441
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
38 changes: 38 additions & 0 deletions _testdata/positive/sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,23 @@
}
}
}
},
"/testIssue1310": {
"get": {
"operationId": "testIssue1310",
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Issue1310"
}
}
}
}
}
}
}
},
"components": {
Expand Down Expand Up @@ -1973,6 +1990,27 @@
"type": "string"
}
}
},
"Issue1310": {
"description": "An API error",
"type": "object",
"properties": {
"title": {
"description": "A short, human-readable summary of the problem type. This value should not change between occurrences of the error.",
"example": "Bad Request",
"type": "string"
},
"details": {
"description": "A human-readable explanation specific to this occurrence of the problem.",
"example": "Property foo is required but is missing.",
"type": "string"
},
"properties": {
"description": "Optional map of properties",
"nullable": true,
"type": "object"
}
}
}
},
"parameters": {
Expand Down
15 changes: 15 additions & 0 deletions internal/integration/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,21 @@ func TestJSONGenerics(t *testing.T) {
})
}
})
t.Run("Issue1310", func(t *testing.T) {
t.Parallel()

val := api.Issue1310{
Title: api.NewOptString("Bad Request"),
Details: api.NewOptString("This is an example error"),
Properties: api.NewOptIssue1310Properties(&api.Issue1310Properties{}),
}
encoded := encodeObject(&val)

var decoded api.Issue1310
decodeObject(t, encoded, &decoded)
require.Equal(t, val, decoded)
require.JSONEq(t, string(encoded), string(encodeObject(&decoded)))
})
}

func TestJSONArray(t *testing.T) {
Expand Down

0 comments on commit 350f441

Please sign in to comment.