diff --git a/_examples/Makefile b/_examples/Makefile index 787faec..cb32559 100644 --- a/_examples/Makefile +++ b/_examples/Makefile @@ -36,5 +36,5 @@ diff: git diff --color --ignore-all-space --ignore-blank-lines --exit-code . swagger: - @echo "Swagger UI is available at http://localhost:8088" + @echo "\nSwagger UI is available at http://localhost:8088\n" docker run -p 8088:8080 -v $$(pwd):/docs -e SWAGGER_JSON=/docs/openapi.gen.yaml swaggerapi/swagger-ui:v5.31.0 diff --git a/_examples/openapi.gen.yaml b/_examples/openapi.gen.yaml index 7e30cbb..36d3559 100644 --- a/_examples/openapi.gen.yaml +++ b/_examples/openapi.gen.yaml @@ -523,8 +523,6 @@ components: type: object ExampleService_GetAllOptional_Request: type: object - ExampleService_StreamUserNotifications_Request: - type: object ExampleService_Ping_Response: type: object ExampleService_GetUser_Response: @@ -897,7 +895,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/ExampleService_StreamUserNotifications_Request' + type: object responses: '200': description: OK diff --git a/main.go.tmpl b/main.go.tmpl index a9c99a2..cdcaf26 100644 --- a/main.go.tmpl +++ b/main.go.tmpl @@ -106,7 +106,7 @@ components: {{- end -}} {{- range $_, $service := $services}} {{- range $i, $method := $service.Methods}} - {{- $isSuccinctInput := and $method.Succinct (eq (len $method.Inputs) 1) -}} + {{- $isSuccinctInput := $method.Succinct -}} {{- if not $isSuccinctInput }} {{$service.Name}}_{{$method.Name}}_Request: type: object @@ -120,7 +120,7 @@ components: {{- end -}} {{- end -}} {{- range $_, $method := .Methods}} - {{- $isSuccinctOutput := and $method.Succinct (eq (len $method.Outputs) 1) -}} + {{- $isSuccinctOutput := $method.Succinct -}} {{- if not $isSuccinctOutput }} {{$service.Name}}_{{$method.Name}}_Response: type: object @@ -138,8 +138,8 @@ components: paths: {{- range $_, $service := .Services -}} {{- range $_, $method := .Methods}} - {{- $isSuccinctInput := and $method.Succinct (eq (len $method.Inputs) 1) -}} - {{- $isSuccinctOutput := and $method.Succinct (eq (len $method.Outputs) 1) -}} + {{- $isSuccinctInput := $method.Succinct -}} + {{- $isSuccinctOutput := $method.Succinct -}} {{- $deprecated := index $method.Annotations "deprecated" }} /rpc/{{$service.Name}}/{{$method.Name}}: post: @@ -170,8 +170,10 @@ paths: content: application/json: schema: - {{- if $isSuccinctInput }} + {{- if and $isSuccinctInput (eq (len $method.Inputs) 1) }} {{ template "fieldType" dict "Type" (index $method.Inputs 0).Type "TypeMap" $typeMap "Indent" " " }} + {{- else if $isSuccinctInput }} + type: object {{- else }} $ref: '#/components/schemas/{{$service.Name}}_{{$method.Name}}_Request' {{- end }} @@ -182,16 +184,20 @@ paths: {{- if eq $method.StreamOutput false }} application/json: schema: - {{- if $isSuccinctOutput }} + {{- if and $isSuccinctOutput (eq (len $method.Outputs) 1) }} {{ template "fieldType" dict "Type" (index $method.Outputs 0).Type "TypeMap" $typeMap "Indent" " " }} + {{- else if $isSuccinctOutput }} + type: object {{- else }} $ref: '#/components/schemas/{{$service.Name}}_{{$method.Name}}_Response' {{- end }} {{- else }} application/x-ndjson: schema: - {{- if $isSuccinctOutput }} + {{- if and $isSuccinctOutput (eq (len $method.Outputs) 1) }} {{ template "fieldType" dict "Type" (index $method.Outputs 0).Type "TypeMap" $typeMap "Indent" " " }} + {{- else if $isSuccinctOutput }} + type: object {{- else }} $ref: '#/components/schemas/{{$service.Name}}_{{$method.Name}}_Response' {{- end }}