Preheat the oven to 400°F (200°C).
In a large skillet, heat the olive oil over medium heat.
Add the sliced onions to the skillet with a pinch of salt.
Cook the onions, stirring often, for about 15-20 minutes until they turn golden brown.
Stir in the chopped mushrooms and thyme, cooking for another 5-7 minutes.
Season the mixture with black pepper and additional salt to taste, then remove from heat.
Roll out the puff pastry on a lightly floured surface and cut it into squares.
Place the pastry squares on a baking sheet lined with parchment paper.
Spoon a generous amount of the onion and mushroom mixture onto each pastry square.
Brush the edges of the pastry with the egg wash.
Optional: sprinkle grated cheese on top of the filling.
Bake in the preheated oven for 20-25 minutes, or until golden brown.
Remove from the oven and let cool slightly before serving.