Skip to content

Commit

Permalink
Add multiline descriptions support for Dart client
Browse files Browse the repository at this point in the history
  • Loading branch information
sas1024 committed Nov 8, 2023
1 parent 24ac781 commit 50b9215
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
6 changes: 3 additions & 3 deletions dart/dart_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (m Method) ParamsClass() string {

type Parameter struct {
Name string
Description string
Description []string
Type string
BaseType string
ReturnType string
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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),
Expand Down
12 changes: 6 additions & 6 deletions dart/dart_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }};
Expand All @@ -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 }};
Expand Down
2 changes: 1 addition & 1 deletion dart/testdata/client.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
13 changes: 12 additions & 1 deletion gen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"golang.org/x/text/language"
)

const version = "2.4.2"
const version = "2.4.3"

const DefinitionsPrefix = "#/definitions/"

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 50b9215

Please sign in to comment.