Files
libopenapi/index/rolodex_ref_extractor.go
quobix 3bf830c2b3 Another round of cleaning.
Signed-off-by: quobix <dave@quobix.com>
2023-10-21 18:41:53 -04:00

56 lines
891 B
Go

// Copyright 2023 Princess B33f Heavy Industries / Dave Shanley
// SPDX-License-Identifier: MIT
package index
import (
"fmt"
"strings"
)
type RefType int
const (
Local RefType = iota
File
HTTP
)
type ExtractedRef struct {
Location string
Type RefType
}
func (r *ExtractedRef) GetFile() string {
switch r.Type {
case File, HTTP:
location := strings.Split(r.Location, "#/")
return location[0]
default:
return r.Location
}
}
func (r *ExtractedRef) GetReference() string {
switch r.Type {
case File, HTTP:
location := strings.Split(r.Location, "#/")
return fmt.Sprintf("#/%s", location[1])
default:
return r.Location
}
}
func ExtractFileType(ref string) FileExtension {
if strings.HasSuffix(ref, ".yaml") {
return YAML
}
if strings.HasSuffix(ref, ".yml") {
return YAML
}
if strings.HasSuffix(ref, ".json") {
return JSON
}
return UNSUPPORTED
}