package spec

import (
	"encoding/json"
	"io/ioutil"
	"net/http"
	"net/url"

	"github.com/rightlag/go-swagger-object-model"
)

func LoadSchema(u *url.URL) (*models.Schema, error) {
	response, err := http.Get(u.String())
	if err != nil {
		return nil, err
	}
	defer response.Body.Close()
	specification, err := ioutil.ReadAll(response.Body)
	if err != nil {
		return nil, err
	}
	var schema models.Schema
	json.Unmarshal(specification, &schema)
	if err != nil {
		return nil, err
	}
	return &schema, nil
}

package spec

import (
	"encoding/json"
	"io/ioutil"
	"net/http"
	"net/url"

	"github.com/rightlag/go-swagger-object-model"
)

func LoadSchema(u *url.URL) (*models.Schema, error) {
	var schema models.Schema
	response, err := http.Get(u.String())
	if err != nil {
		return nil, err
	}
	defer response.Body.Close()
	specification, err := ioutil.ReadAll(response.Body)
	if err != nil {
		return nil, err
	}
	json.Unmarshal(specification, &schema)
	if err != nil {
		return nil, err
	}
	return &schema, nil
}

--- 
+++ 
@@ -10,7 +10,6 @@
 )
 
 func LoadSchema(u *url.URL) (*models.Schema, error) {
-	var schema models.Schema
 	response, err := http.Get(u.String())
 	if err != nil {
 		return nil, err
@@ -20,6 +19,7 @@
 	if err != nil {
 		return nil, err
 	}
+	var schema models.Schema
 	json.Unmarshal(specification, &schema)
 	if err != nil {
 		return nil, err
Move nil schema declaration to L22

No sense in creating nil declaration of Schema object prior to reading
the response body of the HTTP request.
