Skip to content

Instantly share code, notes, and snippets.

@jmgilman
Created July 12, 2024 23:09
Show Gist options
  • Save jmgilman/ef8ef3a1a9f95bd3580d5b6cd940c716 to your computer and use it in GitHub Desktop.
Save jmgilman/ef8ef3a1a9f95bd3580d5b6cd940c716 to your computer and use it in GitHub Desktop.
Generating Go struct from a CUE schema
package gen
//go:generate cue export -f --out openapi --outfile schema.json schema.cue
//go:generate oapi-codegen -config oapi-codegen.yml schema.json
package: gen
output: schema.gen.go
generate:
models: true
output-options:
skip-prune: true
#Schema: {
field1: string
field2: number
field3: bool
}
// Package gen provides primitives to interact with the openapi HTTP API.
//
// Code generated by github.com/deepmap/oapi-codegen version (devel) DO NOT EDIT.
package gen
// Schema defines model for Schema.
type Schema struct {
Field1 string `json:"field1"`
Field2 float32 `json:"field2"`
Field3 bool `json:"field3"`
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment