-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
if we have same struct name, then we will got the same $ref
#42
Comments
As a workaround, you can use this r := new(jsonschema.Reflector)
r.Namer = func(t reflect.Type) string {
name := t.Name()
switch name {
case "Config", /* any other conflicting structs */ "...":
return filepath.Base(t.PkgPath()) + "." + name
}
return name
} |
The example just shows how to reproduce this bug. The workaround here is not a workaround because it solves this issue case by case. I think we can add the package name as the prefix of the ref. And this would be a better workaround. BTW, I've already done it, refer to https://github.com/megaease/easeprobe/blob/8a29940850fe335fe91fd085835c039bd6c745a1/conf/conf.go#L154-L170 And I hope this issue would be addressed officially. |
I'm honestly not sure there is a good solution here with the current implementation. It'd require support for namespaces, and determining those namespaces from package names could be complex (it's not something I've looked at, so not entirely sure.) I'll leave this one open in case anyone would like to propose a solution in a PR. I good approach could be to add a |
Assuming we have two different packages
HTTP
andTCP
, and they all have aConfig
structure.then, we have a struct involving these two packages
then we will have the same
$ref = #/$defs/Config
forhttp
andtcp
in JSON Schema, but actually, thehttp.Config
is quite different withtcp.Config
, this causes the incorrect the JSON schema file.So, is there a way we can define the
$ref
name to make sure they are using different$defs
.The text was updated successfully, but these errors were encountered: