Skip to content
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

Go language support JSON Schema binary data to byte array type #2650

Open
ryan0x44 opened this issue Sep 9, 2024 · 0 comments
Open

Go language support JSON Schema binary data to byte array type #2650

ryan0x44 opened this issue Sep 9, 2024 · 0 comments

Comments

@ryan0x44
Copy link

ryan0x44 commented Sep 9, 2024

Context (Input, Language)

If you have binary data (e.g. TypeScript ArrayBuffer) and you want to store it in a JSON document, the recommended JSON Schema is:

{
	"type": "string",
	"contentEncoding": "base64",
	"contentMediaType": "application/octet-stream"
}

(this is per https://json-schema.org/understanding-json-schema/reference/non_json_data )

In Go, using the above JSON Schema with quicktype currently generates code using the string type, where []byte is actually correct because json Marshal/Unmarshal will correctly base64 encode/decode the payload into the byte array (where as string will leave the base64 string as-is).

Description

I'm trying to interop between a TypeScript component and a Go component, however there is no way to get Go generated code to use a byte array type []byte where I need it.

Current Behaviour / Output

Current Go type is string

Proposed Behaviour / Output

Desired Go type is []byte

Solution

Solution would be for JSON Schema fields which have a string type, to check if contentEncoding and contentMediaType is defined as above, and then use the []byte type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant