in mmv1/openapi_generate/parser.go [149:202]
func buildProduct(filePath, output string, root *openapi3.T, header []byte) string {
version := root.Info.Version
server := root.Servers[0].URL
productName := strings.Split(filepath.Base(filePath), "_")[0]
productPath := filepath.Join(output, productName)
if err := os.MkdirAll(productPath, os.ModePerm); err != nil {
log.Fatalf("error creating product output directory %v: %v", productPath, err)
}
apiProduct := &api.Product{}
apiVersion := &product.Version{}
apiVersion.BaseUrl = fmt.Sprintf("%s/%s/", server, version)
// TODO(slevenick) figure out how to tell the API version
apiVersion.Name = "ga"
apiProduct.Versions = []*product.Version{apiVersion}
// Standard titling is "Service Name API"
displayName := strings.Replace(root.Info.Title, " API", "", 1)
apiProduct.Name = strings.ReplaceAll(displayName, " ", "")
apiProduct.DisplayName = displayName
//Scopes should be added soon to OpenAPI, until then use global scope
apiProduct.Scopes = []string{"https://www.googleapis.com/auth/cloud-platform"}
productOutPathMarshal := filepath.Join(output, fmt.Sprintf("/%s/product.yaml", productName))
// Default yaml marshaller
bytes, err := yaml.Marshal(apiProduct)
if err != nil {
log.Fatalf("error marshalling yaml %v: %v", productOutPathMarshal, err)
}
f, err := os.Create(productOutPathMarshal)
if err != nil {
log.Fatalf("error creating product file %v", err)
}
_, err = f.Write(header)
if err != nil {
log.Fatalf("error writing product file header %v", err)
}
_, err = f.Write(bytes)
if err != nil {
log.Fatalf("error writing product file %v", err)
}
err = f.Close()
if err != nil {
log.Fatalf("error closing product file %v", err)
}
return productPath
}