Skip to content

Commit

Permalink
Merge pull request #28 from yahoo/add_finalname
Browse files Browse the repository at this point in the history
add finalName setting in parsec-swagger
  • Loading branch information
chinkong83 authored Mar 29, 2017
2 parents 9551078 + f7b59a6 commit 027709c
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions cmd/rdl-gen-parsec-swagger/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func main() {
flag.String("s", "", "RDL source file")
genParsecErrorString := flag.String("e", "true", "Generate Parsec Error classes")
scheme := flag.String("c", "", "Scheme")
finalName := flag.String("f", "", "FinalName of jar package, will be a part of path in basePath")
flag.Parse()

genParsecError, err:= strconv.ParseBool(*genParsecErrorString)
Expand All @@ -39,7 +40,7 @@ func main() {
var schema rdl.Schema
err = json.Unmarshal(data, &schema)
if err == nil {
ExportToSwagger(&schema, *pOutdir, genParsecError, *scheme)
ExportToSwagger(&schema, *pOutdir, genParsecError, *scheme, *finalName)
os.Exit(0)
}
}
Expand All @@ -56,8 +57,8 @@ func checkErr(err error) {

// ExportToSwagger exports the RDL schema to Swagger 2.0 format,
// and serves it up on the specified server endpoint is provided, or outputs to stdout otherwise.
func ExportToSwagger(schema *rdl.Schema, outdir string, genParsecError bool, swaggerScheme string) error {
swaggerData, err := swagger(schema, genParsecError, swaggerScheme)
func ExportToSwagger(schema *rdl.Schema, outdir string, genParsecError bool, swaggerScheme string, finalName string) error {
swaggerData, err := swagger(schema, genParsecError, swaggerScheme, finalName)
if err != nil {
return err
}
Expand Down Expand Up @@ -104,7 +105,7 @@ func ExportToSwagger(schema *rdl.Schema, outdir string, genParsecError bool, swa
return http.ListenAndServe(outdir, nil)
}

func swagger(schema *rdl.Schema, genParsecError bool, swaggerScheme string) (*SwaggerDoc, error) {
func swagger(schema *rdl.Schema, genParsecError bool, swaggerScheme string, finalName string) (*SwaggerDoc, error) {
reg := rdl.NewTypeRegistry(schema)
swag := new(SwaggerDoc)
swag.Swagger = "2.0"
Expand All @@ -116,6 +117,14 @@ func swagger(schema *rdl.Schema, genParsecError bool, swaggerScheme string) (*Sw
swag.Schemes = append(swag.Schemes, swaggerScheme)
}

if finalName != "" {
if string([]rune(finalName)[0]) != "/" {
swag.BasePath = "/" + finalName
} else {
swag.BasePath = finalName
}
}

swag.BasePath += utils.JavaGenerationRootPath(schema)

title := "API"
Expand Down

0 comments on commit 027709c

Please sign in to comment.