func()

in mmv1/openapi_generate/parser.go [80:127]


func (parser Parser) WriteYaml(filePath string) {
	log.Printf("Reading from file path %s", filePath)

	ctx := context.Background()
	loader := &openapi3.Loader{Context: ctx, IsExternalRefsAllowed: true}
	doc, _ := loader.LoadFromFile(filePath)
	_ = doc.Validate(ctx)

	header, err := os.ReadFile("openapi_generate/header.txt")
	if err != nil {
		log.Fatalf("error reading header %v", err)
	}

	resourcePaths := findResources(doc)
	productPath := buildProduct(filePath, parser.Output, doc, header)

	// Disables line wrap for long strings
	yaml.FutureLineWrap()
	log.Printf("Generated product %+v/product.yaml", productPath)
	for _, pathArray := range resourcePaths {
		resource := buildResource(filePath, pathArray[0], pathArray[1], doc)

		// marshal method
		resourceOutPathMarshal := filepath.Join(productPath, fmt.Sprintf("%s.yaml", resource.Name))
		bytes, err := yaml.Marshal(resource)
		if err != nil {
			log.Fatalf("error marshalling yaml %v: %v", resourceOutPathMarshal, err)
		}

		f, err := os.Create(resourceOutPathMarshal)
		if err != nil {
			log.Fatalf("error creating resource file %v", err)
		}
		_, err = f.Write(header)
		if err != nil {
			log.Fatalf("error writing resource file header %v", err)
		}
		_, err = f.Write(bytes)
		if err != nil {
			log.Fatalf("error writing resource file %v", err)
		}
		err = f.Close()
		if err != nil {
			log.Fatalf("error closing resource file %v", err)
		}
		log.Printf("Generated resource %s", resourceOutPathMarshal)
	}
}