Giter VIP home page Giter VIP logo

caddy-json-schema's Introduction

caddy-json-schema

JSON schema generator for Caddy v2.

The generated schema can be integrated with editors for intellisense and better experience with configuration and plugin development.

Demonstration

Installation

The generated schema is for the caddy binary. i.e. all modules in the binary will be include in the schema.

xcaddy build v2.4.1 \
    --with github.com/abiosoft/caddy-json-schema \
    # any other module you want to include in the generated schema

Usage

Run caddy help json-schema to view help.

usage:
  caddy json-schema [--output <file>] [--indent <int>] [--vscode] [--no-cache]

flags:
  -indent int
        Number of spaces to indent the generated JSON with (default 2)
  -no-cache
        Discard local cache and fetch latest API docs
  -output string
        The file to write the generated schema (default "./caddy_schema.json")
  -vscode
        Generate VSCode configuration

Editors

Visual Studio Code

caddy json-schema --vscode generates Visual Studio Code configuration in the current directory.

Open the directory in Visual Studio Code and it should just work. Ensure the config filename is of the format *caddy*.[json|yaml].

Note that you need vscode-yaml plugin to get similar experience for YAML files.

Vim/NeoVim

There are multiple Vim/NeoVim plugins with language server and JSON schema support.

Below is a config for coc-json and coc-yaml. The path to schema file is relative to the config file being edited.

{
  "json.schemas": [
    {
      "fileMatch": ["*caddy*.json"],
      "url": "./caddy_schema.json"
    }
  ],
  "yaml.schemas": {
    ".vscode/caddy_schema.json": ["*caddy*.yaml", "*caddy*.yml"]
  }
}

Features

Modules Intellisense Documentation
Standard Supported Supported
Third Party Supported Supported (if plugin is registered on caddyserver.com)

License

Apache 2

caddy-json-schema's People

Contributors

abiosoft avatar fedorg avatar ghostwheel42 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

caddy-json-schema's Issues

Incorrect 'array' type for `caddy.logging.encoders.filter` `fields` key

caddy.logging.encoders.filter's field key should take (according to the docs and practice) an object of field names to filters. However, when using the schema generated by this plugin it says fields should take an array and thus gives an error.

Caddy version v2.4.3

Caddy full donwload URL with plugins.

Example correct logging section which gives a type error (for common_log) in vscode:

logging:
  logs:
    default:
      exclude:
        - http.log.access.stephie
    stephie:
      writer:
        filename: /srv/popple/log/access.log
        output: file
      encoder:
        fields:
          common_log:
            filter: delete
        format: filter
        wrap:
          format: json
          level_key: severity
          message_key: message
          time_key: timestampSeconds
      level: DEBUG
      include:
        - http.log.access.stephie

Errors with Caddy 2.2.1

I'm compiling Caddy 2.2.1 with xcaddy using Go 1.14.4 on Ubuntu 20.04.1 LTS

xcaddy build \
    --with github.com/abiosoft/caddy-json-schema \
    --with github.com/caddy-dns/cloudflare

Caddy builds and runs fine, executing caddy json-schema --vscode gives me this message

panic: reflect: call of reflect.Value.Type on zero Value
 
goroutine 1 [running]:
reflect.Value.Type(0x0, 0x0, 0x0, 0xc0006d7130, 0xc00073ee78)
        reflect/value.go:1872 +0x183
github.com/abiosoft/caddy-json-schema.(*Interface).populate(0xc0008750e0, 0x0, 0x0)
        github.com/abiosoft/[email protected]/interface.go:143 +0xef
github.com/abiosoft/caddy-json-schema.(*Interface).populate(0xc000875050, 0x148df40, 0xc0005c5860)
        github.com/abiosoft/[email protected]/interface.go:132 +0x38e
github.com/abiosoft/caddy-json-schema.(*Interface).populateStruct(0xc000874e10, 0x1a7a5a0, 0x15fbd00)
        github.com/abiosoft/[email protected]/interface.go:186 +0xd4a
github.com/abiosoft/caddy-json-schema.(*Interface).populate(0xc000874e10, 0x15fbd00, 0xc0005305c0)
        github.com/abiosoft/[email protected]/interface.go:120 +0x2ac
github.com/abiosoft/caddy-json-schema.(*Interface).populate(0xc000874d80, 0x1488a80, 0xc0005c5840)
        github.com/abiosoft/[email protected]/interface.go:132 +0x38e
github.com/abiosoft/caddy-json-schema.(*Interface).populateStruct(0xc00073fc88, 0x1a7a5a0, 0x1634e60)
        github.com/abiosoft/[email protected]/interface.go:186 +0xd4a
github.com/abiosoft/caddy-json-schema.(*Interface).populate(0xc00073fc88, 0x1634e60, 0xc0004142a0)
        github.com/abiosoft/[email protected]/interface.go:120 +0x2ac
github.com/abiosoft/caddy-json-schema.(*Interface).populate(0xc00073fc88, 0x15a28c0, 0xc000115bc0)
        github.com/abiosoft/[email protected]/interface.go:124 +0x14e
github.com/abiosoft/caddy-json-schema.generateSchema(0x0, 0x0)
        github.com/abiosoft/[email protected]/schema_util.go:51 +0x159
github.com/abiosoft/caddy-json-schema.run(0xc000115a40, 0xc00003a1a0, 0x1, 0x1)
        github.com/abiosoft/[email protected]/command.go:67 +0x3d
github.com/caddyserver/caddy/v2/cmd.Main()
        github.com/caddyserver/caddy/[email protected]/cmd/main.go:85 +0x239
main.main()
        caddy/main.go:13 +0x20

smallstep/cli too many errors

GO111MODULE=off go get -u -v github.com/abiosoft/caddy-json-schema

github.com/smallstep/cli/usage
# github.com/smallstep/cli/usage
golang/src/github.com/smallstep/cli/usage/help.go:28:18: cannot use cli.StringFlag literal (type cli.StringFlag) as type cli.Flag in slice literal:
	cli.StringFlag does not implement cli.Flag (Apply method has pointer receiver)
golang/src/github.com/smallstep/cli/usage/help.go:32:18: cannot use cli.StringFlag literal (type cli.StringFlag) as type cli.Flag in slice literal:
	cli.StringFlag does not implement cli.Flag (Apply method has pointer receiver)
golang/src/github.com/smallstep/cli/usage/help.go:36:18: cannot use cli.StringFlag literal (type cli.StringFlag) as type cli.Flag in slice literal:
	cli.StringFlag does not implement cli.Flag (Apply method has pointer receiver)
golang/src/github.com/smallstep/cli/usage/help.go:40:16: cannot use cli.BoolFlag literal (type cli.BoolFlag) as type cli.Flag in slice literal:
	cli.BoolFlag does not implement cli.Flag (Apply method has pointer receiver)
golang/src/github.com/smallstep/cli/usage/help.go:44:16: cannot use cli.BoolFlag literal (type cli.BoolFlag) as type cli.Flag in slice literal:
	cli.BoolFlag does not implement cli.Flag (Apply method has pointer receiver)
golang/src/github.com/smallstep/cli/usage/help.go:68:14: invalid argument args (type cli.Args) for len
golang/src/github.com/smallstep/cli/usage/help.go:73:28: cannot slice args (type cli.Args)
golang/src/github.com/smallstep/cli/usage/help.go:76:13: cannot use cmd (type *cli.Command) as type cli.Command in assignment
golang/src/github.com/smallstep/cli/usage/help.go:85:71: cannot use args (type cli.Args) as type []string in argument to strings.Join
golang/src/github.com/smallstep/cli/usage/help.go:86:79: cannot slice args (type cli.Args)
golang/src/github.com/smallstep/cli/usage/help.go:86:79: too many errors

unexpected end of JSON input

Hey,

go: 1.17.2
caddy: 2.4.5

$ xcaddy build v2.4.5 --with github.com/abiosoft/caddy-json-schema
$ ./caddy json-schema -no-cache
json-schema discarding cache for root config.
json-schema fetching https://caddyserver.com/api/docs/config/ ...
json-schema 
json-schema discarding cache for apps/exec.
json-schema fetching https://caddyserver.com/api/docs/config/apps/exec ...
json-schema 
json-schema discarding cache for apps/supervisor.
json-schema fetching https://caddyserver.com/api/docs/config/apps/supervisor ...
json-schema 
json-schema discarding cache for apps/http.
json-schema fetching https://caddyserver.com/api/docs/config/apps/http ...
json-schema 
json-schema discarding cache for apps/pki.
json-schema fetching https://caddyserver.com/api/docs/config/apps/pki ...
json-schema 
json-schema discarding cache for apps/tls.
json-schema fetching https://caddyserver.com/api/docs/config/apps/tls ...
json-schema 
json-schema discarding cache for apps/auth.
json-schema fetching https://caddyserver.com/api/docs/config/apps/auth ...
json-schema 
json-schema: unexpected end of JSON input

The url https://caddyserver.com/api/docs/config/apps/auth response is empty with 502 error code.

Might not be a good idea to use the web server from caddy itself, it's an external services which can always change.
Like in my case it looks like auth is gone?

Now also breaks with caddy 2.0.0

Running the instructed commands

xcaddy build v2.0.0 \
    --with github.com/abiosoft/caddy-json-schema

./caddy json-schema -vscode

results in a panic

panic: qtls.ClientSessionState not compatible with tls.ClientSessionState

goroutine 1 [running]:
github.com/lucas-clemente/quic-go/internal/handshake.init.2()
	github.com/lucas-clemente/[email protected]/internal/handshake/unsafe.go:26 +0x205

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.