R' Elazar said in the name of R' Yossi Ben Zimra:
"Whoever engages in fasting on the Sabbath, they rip up on his behalf (even) a decree of 70 years of evil. But even so, they return and exact punishment from him for (neglecting) the law of enjoying the Sabbath." What should he do to fix this? Rav Nachman Bar Yitzchak said: "Let him fast again for (the sin) of the (first) fast." (Brachos, 31b ,near the bottom)
Although in general we pasken that one is not allowed to fast on Shabbos, and most Rishonim and Poskim equate this Gemara with two similar passages (see Shabbos 11a and Taanis 12b which specifically talks about fasting on Shabbos for a bad dream only), there is still basis to allow your fast before the operation in your situation.
The basic source to follow up on, besides the Gemara, is Tur/and Shulchan Aruch 288 with commentaries. It does seem pretty clear that people, especially nowadays, should not fast on Shabbos (some Poskim even say we should no longer fast for a bad dream at all). (However, by reading all comments you get the feeling that small exceptions linger; like fasting on Shabbos Rosh HaShannah for instance according to some.)
Our Gemara above, does not mention a fast for a bad dream. It seems on its face to say that anyone who decides to fast on Shabbos (dream or no dream) benefits (and loses). Rashi here says that the fact someone is suffering by losing all pleasure when everyone around him is rejoicing helps annul the decree. Rashi does not mention that a dream is involved at all.
I think the Ritva, also seems to hold this Gemara is not focused on a bad dream. Rather, it is the fact that a person decides to be so serious with himself and his low spiritual state, that he wants to genuinely take off a Sabbath (when everyone else takes it easy) and focus on returning to Hashem and His service wholeheartedly. Such a man truly desrves help to reach a higher spiritual level and is granted the gift of having any strong evil decree ripped up.
Even according to most Poskim, who say it is only a bad dream that one may fast over on Shabbos, you can still fast for the operation based on their principle. The reason one is allowed to fast for a bad dream on Shabbos, is because the fast will help him repent quickly, and thereby atone and cancel the ill dream's decree. Therefore, the act of fasting is actually counted as ENJOYING Shabbos, because it relieves anxiety! (see Rashba and others)
So follow my logic please. You can take the deteriorating situation with the leg as a message from heaven. If after introspection, it spurs you on to decide to utilize that Sabbath for prayer and learning in repentance, you have halachic basis to do so if you look forward to enjoying a raised spiritual level.
In combination, it is obvious that guaranteeing your doctor will be there now (who knows for sure if he will be back in two months right?) and guaranteeing the problem (although not immediately painful and life threatening) will not surprise you or get worse in two months (doctors' diagnoses are not infallible right?) is certainly a legitimate halchic concern.
In further combination, we have the Gemara in Shabbos 151b, see also Yoma 85b) R. Shimon ben Gamliel said, "We violate Shabbos for a one day old baby. The Torah said to violate one Shabbos for him so that he may observe many Shabbasos."
By that logic, we can say that you should avoid one enjoyment of one Shabbos by fasting, so you can relieve the discomfort of spending 8 or more Shabosos with a bad leg.
(The Orh HaChayim also brings the opinion of the Ma'abit, who says that fasting on Shabbos is really only prohibited for 24 hours straight (sundown to sundown). So if you can break it in any way on Shabbos, you have technically not violated the prohibition of fasting on Shabbos. However, although a Taanis Cholom (for a bad dream) is only from morning to night, I am not sure if our interpretation of our Gemara in brachos 31b is for only half a day as well. It sounds like it is the whole day (24hrs) so breaking it would be counterproductive anyway?)
Finally, if you had recently fasted on Yom Kippur, and your Shabbos is a few days later, you might think that it is silly to fast based on personal repentance ala 31b, because you already reached the pinnacle of spirituality a few days ago!?
I remember a story from Yeshiva many years ago about R' Saadia Gaon. He was staying by a house as a guest, but the host was not informed about who he was hosting. When the host found out he begged the Rav forgiveness for not treating him better. Rav Saadia protested that he was treated very well! The host said, but if I knew who you really really were...I would have realized to treat you even better!
Rav Saadiah cried and said...Hashem, yesterday I thought I knew who You were, but today I became aware of how much greater you really are! How much teshuvah I must do to make up for my neglect yesterday in honoring You as my Creator!
So you can even achieve greater repentance and rip up decrees even a few days after Yom Kippur too.
However, if you do it, you should fast again on a later date for missing Shabbos enjoyment, (I believe 288 shows that the make-up is from sun-up to sundown only)and you should be humble and try to not let anyone know, if possible.
I hope this helps, :)