go-zero icon indicating copy to clipboard operation
go-zero copied to clipboard

Docs and comments are not retained when using goctl to generate code from api file

Open nicklaros opened this issue 3 years ago • 6 comments

Describe the bug The doc here says that it retain the original mark of //, /*, */. But when I generate code using go-ctl, docs and comments are removed (except inline comments) image

To Reproduce Steps to reproduce the behavior, if applicable:

  1. test.api file

     syntax = "v1"
    
     info (
         title: "test service"
         desc: "service to test bug"
         author: ""
         email: ""
     )
    
     type PingReq {
         // State where ping request come from.
         From string `json:"from"` // eg: ip address, origin host
     }
    
     type PingResp {
         // Ack message.
         Message string `json:"message"`
     }
    
     service test-api {
         @handler HandlePing
         post /ping(PingReq) returns(PingResp)
     }
    
  2. Generate code using goctl

    goctl api go -api test.api
    
  3. The generated types.go file, see that docs and comments are gone with the exception of inline comments

     // Code generated by goctl. DO NOT EDIT.
     package types
    
     type PingReq struct {
         From string `json:"from"` // eg: ip address, origin host
     }
    
     type PingResp struct {
         Message string `json:"message"`
     }
    

Expected behavior All docs and comments from api files were retained in produced types.go

Environments:

  • OS: WSL Ubuntu
  • go-zero version v1.4.0
  • goctl version 1.4.0 linux/amd64

nicklaros avatar Aug 30 '22 00:08 nicklaros

Comments and definitions can be brought into the generated code. example:

 type PingResp {
     Message string `json:"message"`  // Ack message.
 }

MarkJoyMa avatar Aug 31 '22 03:08 MarkJoyMa

Yes I aware that inline comment is retained.

But what if I need to add multiline comments? I think it also need to be retained in the generated code because if I need to add complete documentation for a field, most likely it will be multiline comments

nicklaros avatar Aug 31 '22 09:08 nicklaros

 type PingResp {
     // ACK message
     // second line
     Message string `json:"message"`
 }

Not working?

kevwan avatar Sep 12 '22 11:09 kevwan

It's not working. It will be removed on generated types.go file

nicklaros avatar Sep 12 '22 11:09 nicklaros

@MarkJoyMa @anqiansong PTAL.

kevwan avatar Sep 12 '22 11:09 kevwan

 type PingResp {
     // ACK message
     // second line
     Message string `json:"message"`
 }

Not working?

also not working for goctl-swagger. Only inline comments are maintained

a0v0 avatar Sep 13 '22 15:09 a0v0

hi team, any update on this?

nicklaros avatar Sep 27 '22 04:09 nicklaros

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Mar 15 '24 01:03 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Jun 18 '24 01:06 github-actions[bot]