Skip to content

Commit cc6b723

Browse files
authored
Merge pull request #2 from HamiTrip/develop
Code cleaning and lint acceptable...
2 parents e37fb09 + 89284df commit cc6b723

File tree

6 files changed

+40
-14
lines changed

6 files changed

+40
-14
lines changed

builder.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
package json2schema
22

3+
/*
4+
TypeNeededSchema is one of builder methods
5+
*/
36
type TypeNeededSchema interface {
4-
Type(string) NameNeededSchema
7+
Type(string) nameNeededSchema
58
}
69

7-
type NameNeededSchema interface {
10+
type nameNeededSchema interface {
811
Name(string) SchemaFactory
912
}
1013

14+
/*
15+
Kind will run builder and set kind
16+
*/
1117
func Kind(kind string) TypeNeededSchema {
1218
var schemaFactory = new(schemaFactory)
1319
schemaFactory.Kind = kind
1420
return schemaFactory
1521
}
1622

17-
func (schemaFactory *schemaFactory) Type(t string) NameNeededSchema {
23+
func (schemaFactory *schemaFactory) Type(t string) nameNeededSchema {
1824
schemaFactory.schema.Type = t
1925
return schemaFactory
2026
}

consts.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package json2schema
22

3+
/*
4+
Json to schema constants
5+
*/
36
const (
47
TypeArray = "array"
58
TypeObject = "object"

factory.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import (
66
"fmt"
77
)
88

9+
/*
10+
SchemaFactory is factory
11+
*/
912
type SchemaFactory interface {
1013
Make() Schema
1114
}
@@ -43,7 +46,7 @@ func (schemaFactory *schemaFactory) Make() Schema {
4346
rSchema.FieldByName("Kind").Set(reflect.ValueOf(schemaFactory.Kind))
4447
rSchema.FieldByName("Type").Set(reflect.ValueOf(schemaFactory.schema.Type))
4548
rSchema.FieldByName("Name").Set(reflect.ValueOf(schemaFactory.schema.Name))
46-
rSchema.FieldByName("Validations").Set(reflect.ValueOf([]string{}))//"required"
49+
rSchema.FieldByName("Validations").Set(reflect.ValueOf([]string{"required"}))//"required"
4750

4851
var enTitle = strings.Replace(schemaFactory.schema.Name, "_" , " " , -1)
4952
enTitle = strings.Title(enTitle)

j2s.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package json2schema
33
//TODO:: Make it interactive!! Ask Titles and validations per each field!!!
44
// ->Of course it only can used in cmd mode in this case!!
55

6-
6+
/*
7+
MakeSchema is base starter method
8+
*/
79
func MakeSchema(jsonData interface{}) Schema {
810
//panic(fmt.Sprintf("Excepted types was 'map[string]interface{}' and '[]interface{}' got: %T", jsonData))
911
var root = hub(VarRoot, jsonData)

schema.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,37 @@ import (
44
"encoding/json"
55
)
66

7+
/*
8+
Schema interface
9+
*/
710
type Schema interface {
811
ToMap() map[string]interface{}
912
}
1013

1114
type schema struct {
12-
Attributes basicAttributes `json:"attributes"`
15+
Attributes basicAttributes `json:"attributes"`
1316
Validations `json:"validations"`
14-
Kind string `json:"kind"`
15-
Name string `json:"name"`
16-
Type string `json:"type"`
17+
Kind string `json:"kind"`
18+
Name string `json:"name"`
19+
Type string `json:"type"`
1720
}
1821

1922
type basicAttributes struct {
20-
Title struct {
21-
language
22-
} `json:"title"`
23+
Title struct {
24+
language
25+
} `json:"title"`
2326
Placeholder struct {
24-
language
25-
} `json:"placeholder"`
27+
language
28+
} `json:"placeholder"`
2629
}
2730

2831
type language struct {
2932
En string `json:"en"`
3033
}
3134

35+
/*
36+
Validations is list of validator conditions
37+
*/
3238
type Validations []string
3339

3440
func (schema schema) ToMap() map[string]interface{} {

types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ type field struct {
88
schema
99
}
1010

11+
/*
12+
ArrayGroupSchema is interface of array group schemas
13+
*/
1114
type ArrayGroupSchema interface {
1215
SetChildrenSchema(Schema) ArrayGroupSchema
1316
}
@@ -22,6 +25,9 @@ func (arrayGroupSchema arrayGroupSchema) SetChildrenSchema(schema Schema) ArrayG
2225
return arrayGroupSchema
2326
}
2427

28+
/*
29+
ObjectGroupSchema is interface of object group schemas
30+
*/
2531
type ObjectGroupSchema interface {
2632
AppendChild(...Schema) ObjectGroupSchema
2733
}

0 commit comments

Comments
 (0)