Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support recursive arrays / arrays of references (plus a bunch of other changes) #55

Merged
merged 13 commits into from
Feb 4, 2019
Merged
Prev Previous commit
Next Next commit
removed spare lines & some more crud
  • Loading branch information
mwlazlo committed Oct 17, 2018
commit 9abfb9760fd3524af5085693f9f75a999aae9412
13 changes: 0 additions & 13 deletions generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"errors"
"fmt"
"sort"
"strings"
"unicode"
)
Expand Down Expand Up @@ -33,7 +32,6 @@ func New(schemas ...*Schema) *Generator {

// CreateTypes creates types from the JSON schemas, keyed by the golang name.
func (g *Generator) CreateTypes() (err error) {

if err := g.resolver.Init(); err != nil {
return err
}
Expand Down Expand Up @@ -265,17 +263,6 @@ func contains(s []string, e string) bool {
return false
}

func getOrderedKeyNamesFromSchemaMap(m map[string]*Schema) []string {
keys := make([]string, len(m))
idx := 0
for k := range m {
keys[idx] = k
idx++
}
sort.Strings(keys)
return keys
}

func getPrimitiveTypeName(schemaType string, subType string, pointer bool) (name string, err error) {
switch schemaType {
case "array":
Expand Down
1 change: 0 additions & 1 deletion input.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
)

func ReadInputFiles(inputFiles []string) ([]*Schema, error) {

schemas := make([]*Schema, len(inputFiles))
for i, file := range inputFiles {
b, err := ioutil.ReadFile(file)
Expand Down
11 changes: 0 additions & 11 deletions refresolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ func (r *RefResolver) GetPath(schema *Schema) string {

func (r *RefResolver) GetSchemaByReference(schema *Schema) (*Schema, error) {
docId := schema.GetRoot().ID()

if url, err := url.Parse(docId); err != nil {
return nil, err
} else {
Expand All @@ -79,9 +78,7 @@ func (r *RefResolver) GetSchemaByReference(schema *Schema) (*Schema, error) {
}

func (r *RefResolver) mapPaths(schema *Schema) error {

rootURI := &url.URL{}

id := schema.ID()
if id == "" {
if err := r.InsertURI("#", schema); err != nil {
Expand All @@ -103,15 +100,12 @@ func (r *RefResolver) mapPaths(schema *Schema) error {
return err
}
}

r.updateURIs(schema, *rootURI, false, false)

return nil
}

// create a map of base URIs
func (r *RefResolver) updateURIs(schema *Schema, baseURI url.URL, checkCurrentId bool, ignoreFragments bool) error {

// already done for root, and if schema sets a new base URI
if checkCurrentId {
id := schema.ID()
Expand Down Expand Up @@ -141,7 +135,6 @@ func (r *RefResolver) updateURIs(schema *Schema, baseURI url.URL, checkCurrentId
}
}
}

for k, subSchema := range schema.Definitions {
newBaseURI := baseURI
newBaseURI.Fragment += "/definitions/" + k
Expand All @@ -150,7 +143,6 @@ func (r *RefResolver) updateURIs(schema *Schema, baseURI url.URL, checkCurrentId
}
r.updateURIs(subSchema, newBaseURI, true, ignoreFragments)
}

for k, subSchema := range schema.Properties {
newBaseURI := baseURI
newBaseURI.Fragment += "/properties/" + k
Expand All @@ -159,19 +151,16 @@ func (r *RefResolver) updateURIs(schema *Schema, baseURI url.URL, checkCurrentId
}
r.updateURIs(subSchema, newBaseURI, true, ignoreFragments)
}

if schema.AdditionalProperties != nil {
newBaseURI := baseURI
newBaseURI.Fragment += "/additionalProperties"
r.updateURIs((*Schema)(schema.AdditionalProperties), newBaseURI, true, ignoreFragments)
}

if schema.Items != nil {
newBaseURI := baseURI
newBaseURI.Fragment += "/items"
r.updateURIs(schema.Items, newBaseURI, true, ignoreFragments)
}

return nil
}

Expand Down