Documentation ¶
Overview ¶
TODO: add dereferencing functionality
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractSchemaWithJSONPath ¶
ExtractSchemaWithJSONPath retrieves a part of a given spec based on a JSON Path query.
Parameters:
- spec: The data structure (usually from a parsed JSON document) from which a part needs to be extracted.
- query: The JSON Path query string used to specify the part of the spec to extract.
Returns:
- The extracted data based on the provided JSON Path query.
- An error if the JSON Path query is invalid, if there's no match, or if there are other issues during extraction.
Important considerations:
- The function uses the 'github.com/oliveagle/jsonpath' library to perform the extraction. Familiarity with its syntax and constraints is recommended.
- The given spec should preferably be a map or slice. Providing simple data types might result in unexpected behaviors.
- If the query does not match any part of the spec, an error indicating "unknown key" will be returned.
func LoadAsyncAPISpec ¶
LoadAsyncAPISpec loads and parses an AsyncAPI specification from the given spec.
Parameters:
- spec: the AsyncAPI specification, in JSON format.
Returns:
- A generic interface{} representing the parsed AsyncAPI specification.
- An error if there are issues reading the file or parsing the contained JSON.
Important considerations:
- The function expects the file at the provided path to contain a valid JSON representation of an AsyncAPI spec.
- The returned interface{} is typically a map[string]interface{} for JSON objects or a slice for JSON arrays. Type assertion might be necessary based on the structure of your AsyncAPI spec.
- Errors might arise from file access issues (e.g., file not found, permission issues) or JSON parsing issues (e.g., malformed JSON, unexpected data types).
- Ensure that the provided path is either an absolute path or relative to the current working directory of the executable.
func LoadAsyncAPISpecFromFile ¶
LoadAsyncAPISpecFromFile loads and parses an AsyncAPI specification from a given file path.
Parameters:
- path: The path to the file containing the AsyncAPI specification, in JSON format.
Returns:
- A generic interface{} representing the parsed AsyncAPI specification.
- An error if there are issues reading the file or parsing the contained JSON.
Important considerations:
- The function expects the file at the provided path to contain a valid JSON representation of an AsyncAPI spec.
- The returned interface{} is typically a map[string]interface{} for JSON objects or a slice for JSON arrays. Type assertion might be necessary based on the structure of your AsyncAPI spec.
- Errors might arise from file access issues (e.g., file not found, permission issues) or JSON parsing issues (e.g., malformed JSON, unexpected data types).
- Ensure that the provided path is either an absolute path or relative to the current working directory of the executable.
func ValidateJSONAgainstSchema ¶
func ValidateJSONAgainstSchema(jsonData interface{}, schema interface{}) error
ValidateJSONAgainstSchema checks if the provided JSON data adheres to a given schema.
Parameters:
- jsonData: The data (usually a map or slice from parsed JSON) that needs validation against the schema.
- schema: The schema (typically in JSON format) to which jsonData should adhere.
Returns:
- nil if the jsonData matches the schema without any issues.
- An error detailing the mismatch or any other issues encountered during validation.
Important considerations:
- The function uses the 'github.com/xeipuuv/gojsonschema' library for JSON schema validation. It supports the JSON Schema Draft 4, 6, and 7 specifications.
- Both the jsonData and schema parameters should preferably be of type map[string]interface{} or appropriate Go types representing JSON structures.
- If the validation fails, the function prints each validation error to the standard output.
- It's recommended to handle and process the returned error appropriately in your application. If validation fails, the error will have the message "json is not valid".
- Ensure that the provided schema is a valid JSON schema; otherwise, the function might return unexpected errors.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.