Skip to content

Commit

Permalink
Merge remote-tracking branch 'Sadzeih/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
denouche committed Sep 3, 2020
2 parents 957d656 + c5e352d commit edbc423
Show file tree
Hide file tree
Showing 9 changed files with 476 additions and 397 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: go

go:
- "1.13"
- "1.14"

script:
- go test -v -race ./...
8 changes: 8 additions & 0 deletions cmd/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ var mergeCmd = &cobra.Command{
logrus.WithField("schema", k).Info("Adding Schema")
}

registeredServers := make(map[string]bool)
for _, server := range spec.Servers {
if _, found := registeredServers[server.URL]; found {
continue
}
main.Servers = append(main.Servers, server)
registeredServers[server.URL] = true
}
}

d, err := yaml.Marshal(&main)
Expand Down
4 changes: 3 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var (
outputPath string
inputPath string
parseVendors []string
vendorsPath string
)

// RootCmd represents the root command
Expand All @@ -24,7 +25,7 @@ var RootCmd = &cobra.Command{
Long: `Parse comments in code to generate an OpenAPI documentation`,
Run: func(cmd *cobra.Command, args []string) {
spec := docparser.NewOpenAPI()
spec.Parse(inputPath, parseVendors)
spec.Parse(inputPath, parseVendors, vendorsPath)
d, err := yaml.Marshal(&spec)
if err != nil {
log.Fatalf("error: %v", err)
Expand All @@ -46,4 +47,5 @@ func init() {
RootCmd.Flags().StringVar(&outputPath, "output", "openapi.yaml", "The output file")
RootCmd.Flags().StringVar(&inputPath, "path", ".", "The Folder to parse")
RootCmd.Flags().StringArrayVar(&parseVendors, "parse-vendors", []string{}, "Give the vendor to parse")
RootCmd.Flags().StringVar(&vendorsPath, "vendors-path", "vendor", "Give the vendor path")
}
10 changes: 10 additions & 0 deletions docparser/datatest/otherpackage/data.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package otherpackage

// @openapi:schema:WeirdCustomName
type Data struct {
SomeString string `json:"some_string"`
}

// CustomString
// @openapi:schema
type CustomString string
78 changes: 55 additions & 23 deletions docparser/datatest/user.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package cmd

import (
"encoding/json"
"time"

"gopkg.in/mgo.v2/bson"

"github.com/alexjomin/openapi-parser/docparser/datatest/otherpackage"
)

// GetUser returns a user corresponding to specified id
Expand Down Expand Up @@ -31,16 +34,26 @@ import (
// type: string
// parameters:
// - in: path
// name: deviceId
// schema:
// type: integer
// enum: [3, 4]
// required: true
// description: Numeric ID of the user to get
// name: deviceId
// schema:
// type: integer
// enum: [3, 4]
// required: true
// description: Numeric ID of the user to get
// security:
// - petstore_auth:
// - write:pets
// - read:pets
// servers:
// - url: "https://{environment}.hello.com"
// description: "what up"
// variables:
// environment:
// default: api # Production server
// enum:
// - api # Production server
// - api.dev # Development server
// - api.staging # Staging server
func GetUser() {}

// PostFoo returns a user corresponding to specified id
Expand Down Expand Up @@ -70,26 +83,41 @@ func PostFoo() {}
// @openapi:schema
type MapStringString map[string]string

// @openapi:schema
type WeirdInt int

// Pet struct
// @openapi:schema
type Pet struct {
ID bson.ObjectId `json:"id"`
String string `json:"string,omitempty" validate:"required"`
Int int `json:"int,omitempty"`
PointerOfString *string `json:"pointerOfString"`
SliceOfString []string `json:"sliceofString"`
SliceOfInt []int `json:"sliceofInt"`
SliceOfSliceOfFloat [][]float64 `json:"sliceofSliceofFloat"`
Struct Foo `json:"struct"`
SliceOfStruct []Foo `json:"sliceOfStruct"`
PointerOfStruct *Foo `json:"pointerOfStruct"`
Time time.Time `json:"time"`
PointerOfTime *time.Time `json:"pointerOfTime"`
EnumTest string `json:"enumTest" validate:"enum=UNKNOWN MALE FEMALE"`
StrData map[string]string `json:"strData"`
Children map[string]Pet `json:"children"`
IntData map[string]int `json:"IntData"`
ByteData []byte `json:"ByteData"`
ID bson.ObjectId `json:"id"`
String string `json:"string,omitempty" validate:"required"`
Int int `json:"int,omitempty"`
PointerOfString *string `json:"pointerOfString"`
SliceOfString []string `json:"sliceofString"`
SliceOfInt []int `json:"sliceofInt"`
SliceOfSliceOfFloat [][]float64 `json:"sliceofSliceofFloat"`
Struct Foo `json:"struct"`
SliceOfStruct []Foo `json:"sliceOfStruct"`
PointerOfStruct *Foo `json:"pointerOfStruct"`
Time time.Time `json:"time"`
PointerOfTime *time.Time `json:"pointerOfTime"`
EnumTest string `json:"enumTest" validate:"enum=UNKNOWN MALE FEMALE"`
StrData map[string]string `json:"strData"`
Children map[string]Pet `json:"children"`
IntData map[string]int `json:"IntData"`
ByteData []byte `json:"ByteData"`
JSONData json.RawMessage `json:"json_data"`
CustomString otherpackage.CustomString `json:"custom_string"`
Test Test `json:"test"`
}

// Dog struct
// @openapi:schema
type Dog struct {
Pet
otherpackage.Data

Name string `json:"name"`
}

// Foo struct
Expand All @@ -108,6 +136,10 @@ type Foo2 struct {
// @openapi:schema
type Signals []Foo

// Test struct
// @openapi:schema
type Test int

// @openapi:info
// version: 0.0.1
// title: Some cool title
Expand Down
Loading

0 comments on commit edbc423

Please sign in to comment.