func trimSourceName(pathWithExtension string) string {
	fileNameWithExtension := filepath.Base(pathWithExtension)
	if extInd := strings.IndexByte(fileNameWithExtension, '.'); extInd != -1 {
		return fileNameWithExtension[:extInd]
	}
	return pathWithExtension
}
leaves base file name without any extenstions
package incompatibility
import (
	"errors"
	"fmt"
	"log"
	"path/filepath"
	"strings"
	openapiv3 "github.com/google/gnostic/openapiv3"
	plugins "github.com/google/gnostic/plugins"
	"google.golang.org/protobuf/proto"
	"google.golang.org/protobuf/reflect/protoreflect"
	"github.com/google/gnostic-grpc/search"
	"github.com/google/gnostic-grpc/utils"
)
type Report int
const (
	BaseIncompatibility_Report = iota
	FileDescriptive_Report
)
func GnosticIncompatibiltyScanning(env *plugins.Environment, reportType Report) {
	for _, model := range env.Request.Models {
		if model.TypeUrl != "openapi.v3.Document" {
			continue
		}
		openAPIdocument := &openapiv3.Document{}
		err := proto.Unmarshal(model.Value, openAPIdocument)
		env.RespondAndExitIfError(err)
		createdFile, reportErr := createAndFormatReport(openAPIdocument, env.Request.SourceName, reportType)
		env.RespondAndExitIfError(reportErr)
		env.Response.Files = append(env.Response.Files, createdFile)
	}
}
func createAndFormatReport(doc *openapiv3.Document, filePath string, reportType Report) (*plugins.File, error) {
	report := ScanIncompatibilities(doc, filePath)
	switch reportType {
	case BaseIncompatibility_Report:
		return writeProtobufMessage(report, filePath)
	case FileDescriptive_Report:
		return writeProtobufMessage(detailReport(report), filePath)
	}
	return nil, errors.New("unable to format report type")
}
func writeProtobufMessage(m protoreflect.ProtoMessage, filePath string) (*plugins.File, error) {
	reportBytes, err := utils.ProtoTextBytes(m)
	createdFile := &plugins.File{
		Name: trimSourceName(filePath) + "_compatibility.pb",
		Data: reportBytes,
	}
	return createdFile, err
}
func detailReport(incompatibilityReport *IncompatibilityReport) *FileDescriptiveReport {
	var descReport *FileDescriptiveReport
	var incompatibilities []*IncompatibilityDescription
	fileNode, parseErr := search.MakeNode(incompatibilityReport.ReportIdentifier)
	if parseErr != nil {
		log.Printf("FATAL: unable to parse file at %s with error %s", incompatibilityReport.ReportIdentifier, parseErr)
		return nil
	}
	for _, baseincomp := range incompatibilityReport.Incompatibilities {
		line, col, searchErr := search.FindKey(fileNode.Content[0], baseincomp.TokenPath...)
		if searchErr != nil {
			log.Printf("Warning: Unable to find incompatibilty %s", searchErr.Error())
		}
		lastTokenInPath := baseincomp.TokenPath[len(baseincomp.TokenPath)-1]
		incompatibilities = append(incompatibilities,
			newIncompatibilityDescription(line, col, baseincomp.Classification, lastTokenInPath))
	}
	descReport = newDescriptiveReport(incompatibilityReport.ReportIdentifier, incompatibilities)
	return descReport
}