-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
data-api: implement the methods to read in the new JSON api definitio…
…ns (#3151) * implement functions to load and parse the data definitions in json * change resourceManager to a map of service to service details and load details into resourceManager * hook up services flag * clean up code and add some comments * further clean up * use defer to close the file when loading json, remove CaseInsensitive from ConstantDetails and lower case compare the definition types when loading files * remove CaseInsensitive when mapping ConstantDetails * fix file name and remove IsCaseInsensitive field * address review comments * rename resourceManager variable to services
- Loading branch information
Showing
15 changed files
with
564 additions
and
270 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package repositories | ||
|
||
// NOTE: this is a copy of models from the package `dataapigeneratorjson` which is in the `importer-rest-api-specs` tool | ||
// these have been duplicated to ease development and will be removed once `dataapigeneratorjson` has been split out | ||
|
||
type Constant struct { | ||
Name string `json:"Name"` | ||
Type string `json:"Type"` | ||
Values []Value `json:"Values"` | ||
} | ||
|
||
type Value struct { | ||
Key string `json:"Key"` | ||
Value string `json:"Value"` | ||
Description *string `json:"Description,omitempty"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package repositories | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
"strings" | ||
) | ||
|
||
func listSubDirectories(path string) (*[]string, error) { | ||
directories := make([]string, 0) | ||
|
||
contents, err := os.ReadDir(path) | ||
if err != nil { | ||
return nil, fmt.Errorf("retrieving list of sub directories under %q: %+v", path, err) | ||
} | ||
|
||
for _, c := range contents { | ||
if c.IsDir() { | ||
directories = append(directories, c.Name()) | ||
} | ||
} | ||
|
||
return &directories, nil | ||
} | ||
|
||
func loadJson(path string) (*[]byte, error) { | ||
contents, err := os.Open(path) | ||
if err != nil { | ||
return nil, fmt.Errorf("loading %q", path) | ||
} | ||
|
||
defer contents.Close() | ||
|
||
byteValue, err := io.ReadAll(contents) | ||
if err != nil { | ||
return nil, fmt.Errorf("reading contents of %q", path) | ||
} | ||
|
||
return &byteValue, nil | ||
} | ||
|
||
// getDefinitionInfo transforms the file names in the api definitions directory into a definition type and a name e.g. | ||
// Model-KeyVaultProperties.json -> type = Model and name = KeyVaultProperties | ||
func getDefinitionInfo(fileName string) (string, string, error) { | ||
if !strings.HasSuffix(fileName, ".json") { | ||
return "", "", fmt.Errorf("file %q has an extensions not supported by the data api", fileName) | ||
} | ||
splitName := strings.Split(fileName, "-") | ||
|
||
definitionType := splitName[0] | ||
definitionName := strings.Split(splitName[1], ".")[0] | ||
|
||
return definitionType, definitionName, nil | ||
|
||
} |
Oops, something went wrong.