Closed nightmarlin-dojo closed 4 months ago
Hi, thank you for raising this issue, I'll try to took into it soon for a proper solution, in meanwhile the workaround is to declare desired schema with type mapping:
https://github.com/swaggest/rest/blob/v0.2.61/_examples/advanced-generic-openapi31/router.go#L84-L89
// Create custom schema mapping for 3rd party type.
uuidDef := jsonschema.Schema{}
uuidDef.AddType(jsonschema.String)
uuidDef.WithFormat("uuid")
uuidDef.WithExamples("248df4b7-aa70-47b8-a036-33ac447e668d")
jsr.AddTypeMapping(uuid.UUID{}, uuidDef)
thanks a lot, both for looking into it and the workaround!
Describe the bug
Types that implement
encoding.TextMarshaler
are being rendered with a type set that has the union of the base type andstring
, instead of just string.To Reproduce
produces:
Expected behavior
As
uuid.UUID
and*uuid.UUID
implementencoding.TextMarshaler
, I would expect the set of types generated to be only["string", "null"]
Additional context
from
encoding/json
:we recently upgraded from
v0.3.41
tov0.3.62
, and it includes this change. schemas such as*"github.com/google/uuid".UUID
went fromto
even though they're always going to be rendered as strings thanks to the behaviour of
"encoding/json".Marshal
&encoding.TextMarshaler
This was the behaviour until #72, where it was changed to allow for subsequent processing of additional interceptors. A side-effect of this change seems to have been that the base type (
[]byte
-> "array of numbers") is included in the union, instead of being replaced.Would there be any way to make it so if the type implements
encoding.TextEncoder
its base type is set tostring
(and onlystring
), while still allowing for additional interceptors as requested in #72?