google / google/jsonschema-go

Support self-referential structures

Open
#46 4 comments 13 reactions 0 assignees View on GitHub
bug
Dominant language
Go
Stars
478
Forks
37
PR merge metrics
No merged PRs in 30d

Description

**Describe the bug**
When attempting to generate a jsonschema using a struct that references itself([jsonschema.Schema](https://github.com/google/jsonschema-go/blob/ad34a931e77508dc3d8c9a8abc92ec089001c7cf/jsonschema/schema.go#L42) for example), an error is returned: `cycle detected for type jsonschema.Schema`. This error is coming from [jsonschema/infer.go
](https://github.com/google/jsonschema-go/blob/ad34a931e77508dc3d8c9a8abc92ec089001c7cf/jsonschema/infer.go#L124)

**To Reproduce**
Steps to reproduce the behavior:
1. Generate a jsonschema using jsonschema.Schema or any other struct that references itself.

**Expected behavior**
Generate a ref instead of erroring

**Logs**
`cycle detected for type jsonschema.Schema`

**Additional context**
For reference, my use case is accepting a json schema as input to an MCP tool.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.