validate_examples

package
v0.0.0-...-d770839 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 14, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindExamples

func FindExamples(jsonObject map[string]interface{}, cb func(Example, error))

Find all examples and their respective schemas. Unfortunately, `jsonpath` seems not to implement JsonPath filters on recursive traversal queries. This introduces an layer of complexity related to the dynamic traversal of the JSON nodes. The function can be simplified if you'll find a lib that implements queries like: $..[?(@.examples)] <- find all nodes that have the examples property Or if you find any library that has a decent implementation of JSON Walker Related: https://github.com/PaesslerAG/jsonpath/issues/24

func GetObjectFromFile

func GetObjectFromFile(filePath string) (map[string]interface{}, error)

Read JSON object from a file and Unmarshal it as a generic map.

func GetReferenceLoader

func GetReferenceLoader(refPath string) (*gojsonschema.JSONLoader, error)

`gojsonschema` doesn't handle reference paths that point to specific fields like: file://aaa/bbb.json#definitions/example/something It will return the root object of that JSON file, completely ignoring the part after # As a workaround, this function loads that file, calls a JsonPath query to get the referenced object. Also, gojsonschema is not able to resolve schema references if a JSON object is not saved on disk. *Side effects* If arefPath contains the link to an object, it will generate a file on your file system. Related: https://github.com/xeipuuv/gojsonschema/issues/262

func ScanForExamples

func ScanForExamples(rootPath string) []error

func ScanJSONFiles

func ScanJSONFiles(mainPath string, scanFunction func(string))

Generator to retrieve contents of next json files and pass them to a scan function.

func TranslateReferenceToJSONPath

func TranslateReferenceToJSONPath(refPath string) string

Translate a OpenAPI reference path ($ref) to a JsonPath query in a dialect accepted by the `jsonpath` lib. e.g. /definitions/request -> $.definitions.request /definitions/request/200 -> $.definitions.request["200"] `jsonpath` throws an error if you try to access fields like this: `$.definitions.request.200` Related: https://github.com/PaesslerAG/jsonpath/issues/23

Types

type Example

type Example struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL