Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/setup-go@v4
with:
go-version: "1.18"
cache: false

- name: Check out code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: "go.mod"

- name: Lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v6
with:
version: v1.55
version: v1.62
30 changes: 20 additions & 10 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
name: Test Go
on: [push, pull_request]
on:
push:
tags:
- v*
branches:
- main
pull_request:
jobs:
lint-test-build:
name: Lint, Test
test:
name: Test
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v1
uses: actions/setup-go@v4
with:
go-version: "1.18"
id: go

- name: Check out code
uses: actions/checkout@v2
go-version-file: "go.mod"

- name: Install Dependencies
env:
GOPROXY: https://proxy.golang.org,direct
run: go mod download

- name: Test
run: go test -tags unit -race ./...
run: go test -race -coverprofile=coverage.out -covermode=atomic ./...

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
21 changes: 10 additions & 11 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
run:
tests: true
max-same-issues: 50
skip-dirs:
- resources
- old
skip-files:
- cmd/protopkg/main.go

output:
print-issued-lines: false
Expand All @@ -19,13 +14,12 @@ linters:
- unconvert
- goimports
- unused
- vetshadow
- govet
- nakedret
- errcheck
- revive
- ineffassign
- goconst
- vet
- unparam
- gofmt

Expand All @@ -45,14 +39,19 @@ linters-settings:
- ifElseChain
gofmt:
rewrite-rules:
- pattern: 'interface{}'
replacement: 'any'
- pattern: 'a[b:len(a)]'
replacement: 'a[b:]'
- pattern: "interface{}"
replacement: "any"
- pattern: "a[b:len(a)]"
replacement: "a[b:]"

issues:
max-per-linter: 0
max-same: 0
exclude-dirs:
- resources
- old
exclude-files:
- cmd/protopkg/main.go
exclude-use-default: false
exclude:
# Captured by errcheck.
Expand Down
105 changes: 102 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,108 @@
# Go JSON Schema Reflection

## My Fork Changes:
* Commit `c7e4988` support manual require:
```go
package main

import (
"fmt"
"reflect"

"github.com/funte/jsonschema"
)

type Base struct {
BA int `json:"ba" jsonschema:"required"`
BB string `json:"bb" jsonschema:"required"`
}

type Child struct {
*Base

CA bool `json:"ca" jsonschema:"required"`
}

func main() {
// Enable pretty marshal.
jsonschema.MarshalWithIndent = true
jsonschema.MarshalIndent = " "

r := jsonschema.Reflector{}
r.ExpandedStruct = true
r.RequiredFromJSONSchemaTags = true

// Test Reflector.Require.
r.Require = func(f reflect.StructField) bool {
return f.Name == "CA"
}
if s, err := r.Reflect(Child{}).MarshalJSON(); err != nil {
fmt.Println("failed to marshal Child json schema, err=", err)
} else {
// Output should only quired "ca".
fmt.Println(string(s))
}
}


```
* Commit `bfefafd` support manual ignore:
```go
package main

import (
"fmt"
"reflect"

"github.com/funte/jsonschema"
)

type Base struct {
BA int `json:"ba" jsonschema:"required"`
BB string `json:"bb" jsonschema:"required"`
}

type Child struct {
*Base

CA bool `json:"ca" jsonschema:"required"`
}

func main() {
// Enable pretty marshal.
jsonschema.MarshalWithIndent = true
jsonschema.MarshalIndent = " "

r := jsonschema.Reflector{}
r.ExpandedStruct = true
r.RequiredFromJSONSchemaTags = true

// Test Reflector.Ignore.
r.Ignore = func(f reflect.StructField) bool {
return f.Name != "CA"
}
if s, err := r.Reflect(Child{}).MarshalJSON(); err != nil {
fmt.Println("failed to marshal Child json schema, err=", err)
} else {
// Output should only has field "ca".
fmt.Println(string(s))
}
}

```
* Commit `7f1f647` support pretty marshal:
```go
jsonschema.MarshalWithIndent = true
jsonschema.MarshalIndent = " "
```

## introduction

[![Lint](https://github.com/invopop/jsonschema/actions/workflows/lint.yaml/badge.svg)](https://github.com/invopop/jsonschema/actions/workflows/lint.yaml)
[![Test Go](https://github.com/invopop/jsonschema/actions/workflows/test.yaml/badge.svg)](https://github.com/invopop/jsonschema/actions/workflows/test.yaml)
[![Go Report Card](https://goreportcard.com/badge/github.com/invopop/jsonschema)](https://goreportcard.com/report/github.com/invopop/jsonschema)
[![GoDoc](https://godoc.org/github.com/invopop/jsonschema?status.svg)](https://godoc.org/github.com/invopop/jsonschema)
[![codecov](https://codecov.io/gh/invopop/jsonschema/graph/badge.svg?token=JMEB8W8GNZ)](https://codecov.io/gh/invopop/jsonschema)
![Latest Tag](https://img.shields.io/github/v/tag/invopop/jsonschema)

This package can be used to generate [JSON Schemas](http://json-schema.org/latest/json-schema-validation.html) from Go types through reflection.
Expand Down Expand Up @@ -52,10 +151,10 @@ jsonschema.Reflect(&TestUser{})
```json
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://github.com/invopop/jsonschema_test/sample-user",
"$ref": "#/$defs/SampleUser",
"$id": "https://github.com/invopop/jsonschema_test/test-user",
"$ref": "#/$defs/TestUser",
"$defs": {
"SampleUser": {
"TestUser": {
"oneOf": [
{
"required": ["birth_date"],
Expand Down
93 changes: 0 additions & 93 deletions comment_extractor.go

This file was deleted.

Loading