schmp

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2024 License: MIT Imports: 9 Imported by: 0

README

schmp

GoDoc Build Status

schmp is a schema comparision tool, which allows you to compare schemas of data in JSON, YAML and TOML format. It is available as both a CLI, or a library which can be imported in your project.

This only compares the types of your data members, and ignores the values.

For objects or dictionaries, it traverses nested objects, as long as the type of that specific key is same in all the data samples provided.

NOTE: This package is currently considered stable and no further changes are intended. I am only waiting on some feedback before a v1.0.0 release.

Why?

Most projects use config files which store configuration settings which are different for different environments. As new features are added, need for more global configuration settings arise, which then need to be updated across all environments on release.

The motivation to develop schmp arose as a requirement in our release process, to autoverify whether our config structure matches, in schema, not values, to our development or example config file.

Installing as CLI

If you are not using Go:

  • Download the release from the Releases page and download the latest release archive for your OS and architecture.
  • Extract the archive, and move the extracted file to your PATH (optional, use complete path to file if skipping this step)

If you are using Go:

$ go install github.com/ayushg3112/schmp/cmd/schmp@latest
Usage
$ schmp --help
Usage of schmp:
  -f, --file stringArray      Files to compare. Use this flag multiple times, once for each file.
  -m, --mode string           input file format.  Allowed values: json, yaml, toml (default "json")
      --out-file --out-type   Output file. Only used if --out-type is not stdout
  -o, --out-type string       Output format. Allowed values: stdout, json (default "stdout")

Example:

$ schmp -f path/to/first/file.json -f path/to/second/file.json --out-type stdout --mode json

Installing as a library

$ go get -u github.com/ayushg3112/schmp

Usage Example:

import (
  "github.com/ayushg3112/schmp"
  "strings"
  "fmt"
)

func main() {
  reader1 := strings.NewReader(`{ "a": 1, "b": "2", "c": { "d": {"e" : 3}, "f": 4}}`)
  reader2 := strings.NewReader(`{ "b": "5", "c": { "d": "6", "f": 7}, "g": null}`)
  result, err := schmp.Compare(schmp.ProcessingOptions{
    Mode: "json",
    Sources: []io.Reader{
      reader1,
      reader2,
    },
  })
  if err != nil {
    panic(err)
  }
  fmt.Printf("%+v", result)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ComparisonOutput

type ComparisonOutput struct {
	Diff map[string][]string
}

ComparisonOutput is the output from the Compare function. `Diff` holds the actual result of the comparison. The key in the `Diff` map represents the key at which a different type was found across all the `Sources`, and the values represent the types in the `Sources`. The values are index matched to the `Sources` provided in `ProcessingOptions`

func Compare

func Compare(options ProcessingOptions) (ComparisonOutput, error)

Compare reads data from from the provided `options.Sources`, decodes them according to the provided `options.Mode` and recursively compares properties of the decoded results.

type ProcessingOptions

type ProcessingOptions struct {
	Mode    string
	Sources []io.Reader
}

ProcessingOptions is the input provided to the `Compare` function to control how it processes input. Mode defines the format your data is in. `Sources` are your data sources.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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