(1) When declaratory relief is sought all persons shall be made parties who have or claim any interest which would be affected by the declaration, and a declaration may not prejudice the rights of persons not parties to the proceeding.
(2) In any proceeding which involves the validity of a municipal or county ordinance or franchise, the municipality or county shall be made a party, and shall be entitled to be heard.
(3) If a statute or state franchise or permit is alleged to be invalid, the attorney general shall be served with a copy of the proceeding and be entitled to be heard.