From 50b9215fb86f77c38c048fbb6d02462a75116a15 Mon Sep 17 00:00:00 2001 From: Alexander Korelskiy Date: Wed, 8 Nov 2023 11:45:24 +0300 Subject: [PATCH] Add multiline descriptions support for Dart client --- dart/dart_client.go | 6 +++--- dart/dart_template.go | 12 ++++++------ dart/testdata/client.dart | 2 +- gen/gen.go | 13 ++++++++++++- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/dart/dart_client.go b/dart/dart_client.go index f9cf2bc..e21f48b 100644 --- a/dart/dart_client.go +++ b/dart/dart_client.go @@ -48,7 +48,7 @@ func (m Method) ParamsClass() string { type Parameter struct { Name string - Description string + Description []string Type string BaseType string ReturnType string @@ -209,7 +209,7 @@ func (g *Generator) propertiesToParams(list smd.PropertyList) []Parameter { p := Parameter{ Name: prop.Name, Optional: prop.Optional, - Description: prop.Description, + Description: gen.StringToSlice(prop.Description, "\n"), } pType := dartType(prop.Type) @@ -257,7 +257,7 @@ func (g *Generator) prepareParameters(in []smd.JSONSchema) []Parameter { func (g *Generator) prepareParameter(in smd.JSONSchema) Parameter { out := Parameter{ Name: in.Name, - Description: in.Description, + Description: gen.StringToSlice(in.Description, "\n"), BaseType: dartType(in.Type), Optional: in.Optional, Properties: g.propertiesToParams(in.Properties), diff --git a/dart/dart_template.go b/dart/dart_template.go index 0bc4a48..49356f7 100644 --- a/dart/dart_template.go +++ b/dart/dart_template.go @@ -7,14 +7,14 @@ import 'package:smd_annotations/annotations.dart'; part '{{ .Part }}.g.dart'; {{ range .Models }} -{{- if .Description }} -/// {{ .Description }} +{{- range .Description }} +/// {{ . }} {{- end }} @JsonSerializable() class {{ .Type }} { {{- range .Properties }} - {{- if .Description }} - /// {{ .Description }} + {{- range .Description }} + /// {{ . }} {{- end }} @JsonKey(name: '{{ .Name }}') final {{ .Type }}{{ if .Optional }}?{{ end }} {{ .Name }}; @@ -41,8 +41,8 @@ class {{ .Type }} { @JsonSerializable() class {{ title $namespaceName }}{{ .ParamsClass }} { {{- range .Parameters }} - {{- if .Description }} - /// {{ .Description }} + {{- range .Description }} + /// {{ . }} {{- end }} @JsonKey(name: '{{ .Name }}') final {{ .Type }}{{ if .Optional }}?{{ end }} {{ .Name }}; diff --git a/dart/testdata/client.dart b/dart/testdata/client.dart index a120243..f9d1500 100755 --- a/dart/testdata/client.dart +++ b/dart/testdata/client.dart @@ -1,4 +1,4 @@ -/// Code generated from jsonrpc schema by rpcgen v2.4.sdsd2; DO NOT EDIT. +/// Code generated from jsonrpc schema by rpcgen v2.4.3; DO NOT EDIT. import 'package:json_annotation/json_annotation.dart'; import 'package:smd_annotations/annotations.dart'; diff --git a/gen/gen.go b/gen/gen.go index 371c8f8..b37becc 100644 --- a/gen/gen.go +++ b/gen/gen.go @@ -10,7 +10,7 @@ import ( "golang.org/x/text/language" ) -const version = "2.4.2" +const version = "2.4.3" const DefinitionsPrefix = "#/definitions/" @@ -57,6 +57,17 @@ func GetMethodName(methodName string) string { return arr[1] } +func StringToSlice(in, separator string) []string { + s := strings.Split(in, separator) + var out []string + for _, str := range s { + if str != "" { + out = append(out, str) + } + } + return out +} + var TemplateFuncs = template.FuncMap{ "notLast": func(index int, len int) bool { return index+1 != len