Skip to content

Commit ea29ed4

Browse files
authored
Fix code gen (#212)
* Code gen now handles no descriptions on enums * Codegen ignore unused interfaces * Changes comment
1 parent 8996c3d commit ea29ed4

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

openapi-gen/main.go

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ import { buildFetchOptions } from './utils';
3232
import { encode } from 'js-base64';
3333
3434
{{- range $classname, $definition := .Definitions}}
35+
{{- if or (eq $classname "protobufAny") (eq $classname "rpcStatus") }}
36+
{{- continue -}}
37+
{{- end -}}
3538
{{- if isRefToEnum $classname }}
3639
3740
/**
@@ -44,8 +47,7 @@ export enum {{ $classname | title }}
4447
{{ $enum }} = {{ $idx }},
4548
{{- end }}
4649
}
47-
{{- else }}
48-
50+
{{- else }}
4951
/** {{$definition.Description}} */
5052
export interface {{$classname | title}} {
5153
{{- range $key, $property := $definition.Properties}}
@@ -118,11 +120,11 @@ export class {{ .Namespace }}Api {
118120
{{- if eq $parameter.In "path" -}}
119121
{{ $parameter.Type }},
120122
{{- else if eq $parameter.In "body" -}}
121-
{{- if eq $parameter.Schema.Type "string" -}}
122-
{{ $parameter.Schema.Type }},
123-
{{- else -}}
124-
{{ $parameter.Schema.Ref | cleanRef }},
125-
{{- end }}
123+
{{if $parameter.Schema.Ref}}
124+
{{ $parameter.Schema.Ref | cleanRef }},
125+
{{else}}
126+
unknown,
127+
{{- end}}
126128
{{- else if eq $parameter.Type "array" -}}
127129
Array<{{$parameter.Items.Type}}>,
128130
{{- else if eq $parameter.Type "object" -}}
@@ -289,20 +291,21 @@ func enumSummary(def Definition) string {
289291
}
290292

291293
func enumDescriptions(def Definition) (output []string) {
294+
if def.Description == "" {
295+
return make([]string, len(def.Enum))
296+
}
292297

293298
split := strings.Split(def.Description, "\n")
294299

295-
if len(split) <= 0 {
296-
panic("No newlines in enum description found.")
300+
if def.Title != "" {
301+
return split
297302
}
298303

299-
if def.Title != "" {
304+
// handle no description cases
305+
if len(split) <= 2 {
300306
return split
301307
}
302308

303-
// quirk of swagger generation: if enum doesn't have a title
304-
// then the title can be found as the first entry in the split description.
305-
// so ignore for individual enum descriptions.
306309
return split[2:]
307310
}
308311

0 commit comments

Comments
 (0)