File tree 6 files changed +124
-0
lines changed
6 files changed +124
-0
lines changed Original file line number Diff line number Diff line change
1
+ /apib2go
2
+ /cover.out
3
+ /tags
4
+ * .sw ?
Original file line number Diff line number Diff line change
1
+ SHELL := /bin/sh
2
+ EXE := apib2go
3
+ SRC := $(wildcard * .go)
4
+ COVER := cover.out
5
+
6
+ .DEFAULT_GOAL := all
7
+
8
+ .PHONY : all
9
+ all : $(EXE )
10
+
11
+ # Build the exe.
12
+ $(EXE ) : $(COVER )
13
+ go build -v
14
+
15
+ # Run vet, test, and display test coverage by function.
16
+ $(COVER ) : $(SRC )
17
+ go vet -v
18
+ go test -v -covermode=count -coverprofile=$(COVER )
19
+ go tool cover -func=$(COVER )
20
+
21
+ # Runs the html based coverage tool.
22
+ .PHONY : cov
23
+ cov : $(COVER )
24
+ go tool cover -html=$(COVER )
25
+
26
+ # Clean up the project files.
27
+ .PHONY : clean
28
+ clean :
29
+ go clean -v
30
+ $(RM ) -f $(COVER )
Original file line number Diff line number Diff line change
1
+ # apib2go
2
+
3
+ https://apiblueprint.org/documentation/mson/specification.html
4
+
5
+ Core Principles
6
+
7
+ - Optional is represented by pointer.
8
+ - Required is represented by an instance. \*
9
+ - Numbers are represented as strings to avoid issues with precision.
10
+ - ${X}.apib becomes the package name (e.g. products.apib generates products/generated.go with a package name "products").
11
+
12
+ \* I'm not really a fan of required. It limits schema evolution (protobuf3 dropped it entirely) so it'll be the last thing I'll focus on.
13
+
14
+ ## Type Mapping
15
+
16
+ | MSON | Go | Notes |
17
+ | :=====: | :===========: | :=================================: |
18
+ | boolean | \* bool | |
19
+ | string | \* string | |
20
+ | number | \* string | allow user to decide how to convert |
21
+ | array | pointer slice | |
22
+ | enum | \* string | |
23
+ | object | \* Object | |
24
+
25
+ ## Example
26
+
27
+ MSON
28
+
29
+ ```
30
+ ## Data Structures
31
+
32
+ ### Dimension
33
+ + radius (number)
34
+ + length (number)
35
+
36
+ ### Produce
37
+
38
+ + colour (string) - What colour is it?
39
+ + dimesions (Dimension)
40
+ + fruit (boolean) - Is it fruit?
41
+ ```
42
+
43
+ Go
44
+ ```
45
+ import (
46
+ "github.com/nfisher/apib2go/apib"
47
+ . "github.com/nfisher/apib2go/primitives"
48
+ )
49
+
50
+ type Dimensions struct {
51
+ Radius Number
52
+ Length Number
53
+ }
54
+
55
+ type Produce struct {
56
+ Colour String
57
+ Dimensions *Dimensions
58
+ Fruit Boolean
59
+ Name String
60
+ }
61
+
62
+ // Usage:
63
+
64
+ dim := &Dimension {
65
+ Radius: apib.Int(3),
66
+ Length: apib.Decimal("18.56"),
67
+ }
68
+
69
+ p := &Produce {
70
+ Colour: apib.String("yellow"),
71
+ Dimensions: dim,
72
+ Fruit: apib.Boolean(true),
73
+ Name: apib.String("banana"),
74
+ }
75
+ ```
Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import "fmt"
4
+
5
+ func main () {
6
+ fmt .Println ("apib2go" )
7
+ }
Original file line number Diff line number Diff line change
1
+ package main
Original file line number Diff line number Diff line change
1
+ package main_test
2
+
3
+ import "testing"
4
+
5
+ func Test_failure (t * testing.T ) {
6
+ t .Fatal ("Write a test..." )
7
+ }
You can’t perform that action at this time.
0 commit comments