diff --git a/openrpc/templates/template.go b/openrpc/templates/template.go index 7b49130e8e8065e4d5f757eb4a569c3f4ad6f427..88db1958dc330dfdbe784e452debeaaa20e616fb 100644 --- a/openrpc/templates/template.go +++ b/openrpc/templates/template.go @@ -1,53 +1,6 @@ -package templates -const TEMPLATE=`// Code generated by go-openrpc. DO NOT EDIT. +package templates -package {{ .Package }} +import _ "embed" -{{define "schemaType" -}} - {{if not (eq .Ref "") -}} - {{camelCase (refName .Ref)}} - {{- else if or - (not (eq (len .Properties) 0)) - (not (eq (len .OneOf) 0)) - (not (eq (len .AnyOf) 0)) - (not (eq (len .AllOf) 0)) - -}} - struct { - {{range $name, $property := .Properties -}} - {{camelCase $name}} {{template "schemaType" $property}} `+"`"+`json:"{{$name}}"`+"`"+` - {{end -}} - {{range $idx, $property := .OneOf -}} - Option{{$idx}} {{template "schemaType" $property}} - {{end -}} - {{range $idx, $property := .AnyOf -}} - Option{{$idx}} {{template "schemaType" $property}} - {{end -}} - {{range $idx, $property := .AllOf -}} - Field{{$idx}} {{template "schemaType" $property}} - {{end -}} - } - {{- else if eq .Type "array" -}} - []{{template "schemaType" (index .Items 0)}} - {{- else if not (eq (len .Enum) 0) -}} - string - {{- else -}} - {{goType .Type}} - {{- end}} -{{- end -}} - -type GoOpenRPCService interface { - {{range .Methods -}} - // {{.Summary}} - {{camelCase .Name}}( - {{range .Params -}} - {{camelCase .Name}} {{template "schemaType" .Schema}}, - {{end -}} - ) ({{camelCase .Result.Name}} {{template "schemaType" .Result.Schema}}) - {{end -}} -} - -{{- range $name, $component := .Components.Schemas }} - type {{camelCase $name}} {{template "schemaType" $component}} -{{- end }} - -` +//go:embed types.gotmpl +var TEMPLATE string