You didn't say whether or not the latch works. If that's okay, then the usual reason for a door to swing open on it's own (when it's not latched, anyway) is because the hinge edge is not quite vertical--causing the door to lean, thus causing the self-opening.
You also didn't say what sort of door is involved, but I'm guessing you're referring to an entry door to a house or to a room within the house. If that's the case, then either the door was originally hung improperly or the casing (where the door attaches to one wall via hinges) is also leaning.
Either way, it can be a real challenge. If it's the wall is leaning, straightening the thing is no easy fix. Unless you have a buddy who knows how to unkink your entire house, that is!
If the wall is fairly straight (few are literally perfect), and the hinges were set slightly "crooked" from Day One, it's often hard to drill new pilot holes for the hinge screws that will work--because the needed adjustment is generally so small that the new holes will "bleed over" into the old holes, leaving you with too little wood to hold the screws securely.
However, you can sometimes get around this by moving the hinges up OR down on BOTH the door AND the casing. It's not a "perfect" procedure in that you may have to settle for less than optimum hinge placement to keep the door straight and secure--since the original placement should have been in the best spots for that door.
But it's better than nothing.