Why can $Y$ be assumed affine? I'm reading some online notes (http://www.uio.no/studier/emner/matnat/math/MAT4215/v15/notes4.pdf) and wanted to ask about the first sentence of this proof:

I'm very new to fiber products of schemes.  What is the principle that allows us to conclude Proposition 0.3 in general if we know that it is true for $Y$ affine?
 A: Note that $\operatorname{Spec} k(y)$ (that's most likely a typo in the diagram above the proposition in the notes) consists of a single point, and as such, the image of that point in $Y$ (which is $y$) is contained in some affine subscheme of $Y$.
We see that whatever there is of $Y$ outside of this affine neighbourhood is irrelevant for our purposes: Restrict $X$ to the inverse image over $\phi$ of this affine neighbourhood, and the resulting product scheme is unchanged, as seen by the universal property of the fiber product (the new product scheme fulfills the universal property of the old one, therefore they are the same scheme, up to unique isomorphism).
More generally, the same argument says that if we have schemes and morphisms $f:X\to Y$ and $g:Z\to Y$, and the (topological) image of $Z$ is contained in some open subscheme $Y'\subseteq Y$, then $Z\times_YX\cong Z\times_{Y'} X'$, where $X'$ is the open subscheme of $X$ given by the topological subspace $f^{-1}(Y')$.
A: Here are the details of Arthur's answer.  
Let $f:X \rightarrow Y$ be a morphism of schemes.  If $U \subseteq X$ is open, then the composition of the inclusion morphism $U \rightarrow X$ followed by $f$ is called the restriction of $f$ to $U$.  
Now let $V \subseteq Y$ be open, and suppose that the image of $f$ is contained in $V$.  Then there is a unique morphism $f':X \rightarrow V$ such that $f$ is equal to the composition of $f'$ followed by the inclusion morphism.
In particular, let $j$ be the inclusion morphism of an open set $V$ into a scheme $Y$.  If $f, g: X \rightarrow V$ are morphisms such that $j \circ f = j \circ g$, then $f = g$.  
Lemma: Suppose that $U$ is any open subset of $X$ for which $f(U) \subseteq V$.  Then there is a unique morphism $f': U \rightarrow V$ such that the composition of the inclusion morphism of $U$ into $X$ followed by $f$ is equal to $f'$ followed by the inclusion morphism of $V$ into $Y$.
As a consequence of the lemma: 
Proposition: Let $f: X \rightarrow S, g: Y \rightarrow S$ be two schemes over a scheme $S$.  Let $S_0 \subseteq S$ be open, and let $X_0 \subseteq X$ be the preimage of $S_0$ under $f$.  Also assume that the image of $g$ is contained in $S_0$.  Let $f_0: X_0 \rightarrow S_0$ and $g_0: Y \rightarrow S_0$ be the morphisms as in the lemma.  Then $X_0 \times_{S_0} Y \cong X \times_S Y$.
Proof: Let $Z = X_0 \times_{S_0} Y$, with projections $p_0: Z \rightarrow X_0$ and $q: Z \rightarrow Y$ such that $f_0 \circ p_0 = g_0 \circ q$.  Let $a: S_0 \rightarrow S, i: X_0 \rightarrow X$ be the inclusion morphisms, so $a \circ f = f_0 \circ i, a \circ g = g_0$. 
By composition, we obtain a morphism $p = i \circ p_0: Z \rightarrow X$, with $f \circ p = g \circ q$ as morphisms $Z \rightarrow S$.  We claim that $Z$, together with the morphisms $p, q$, is a fibre product of $X$ and $Y$ over $S$.  
Let $H$ be any scheme, and suppose that $\phi: H \rightarrow X, \psi: H \rightarrow Y$ are morphisms with $f \circ \phi = g \circ \psi$.  We need to show that there is a unique morphism $\pi: H \rightarrow Z$ such that $p \circ \pi = \phi$ and $q \circ \pi = \psi$.
Since $f \circ \phi = g \circ \psi$, the image of $\phi$ is mapped into $S_0$ by $f$, which means that the image of $\phi$ is contained in $X_0$.  Thus there is a unique morphism $\phi_0: H \rightarrow X_0$ such that $i \circ \phi_0 = \phi$.  
Now $a \circ f_0 \circ \phi_0 = f \circ i \circ \phi_0 = f \circ \phi = g \circ \psi =a \circ g_0 \circ \psi$, and canceling the $a$ (I think we can do that) we get $f_0 \circ \phi_0 = g_0 \circ \psi$, so there exists a unique morphism $\pi_0: H \rightarrow Z$ such that $p_0 \circ \pi_0 = \phi_0$ and $q \circ \pi_0 = \psi$.  
From $p_0 \circ \pi_0 = \phi_0$ we get $i \circ p_0 \circ \pi_0 = i \circ \phi_0$, or $p \circ \pi_0 = \phi$.  Also, $q \circ \pi_0 = \psi$ as we just mentioned.
For uniqueness, suppose $\pi: H \rightarrow Z$ is another morphism with $p \circ \pi = \phi$ and $q \circ \pi = \psi$.  From $i \circ p_0 \circ \pi = i \circ \phi_0$, we get $p_0 \circ \pi = \phi_0$, and considering also $q \circ \pi = \psi$, we have $\pi = \pi_0$ by the uniqueness of $Z$ as a fiber product over $X_0$ and $Y$ over $S_0$.  $\blacksquare$
