Teamwork/kommentaar

$object only work for subpackages

Closed this issue · 8 comments

When adding $response object, it errors and the error suggests it is trying to look for the object in a subpackage.

I got the following error

github.com/teamwork/desk/api/v2/tickets/create.go: could not parse response 201 params: could not find github.com/teamwork/desk/models.TicketAndThreadsJSON in github.com/teamwork/desk/api/v2/tickets

This should work; what does the comment look like?

I tried multiple variations but I think it can't get more explicit than this.

// Response 201 (application/json):
//   $object: github.com/teamwork/desk/models.TicketAndThreadsJSON

Oh, you need to use a space between the package name and type name:

//   $object: github.com/teamwork/desk/models TicketAndThreadsJSON

There's a TODO in the code somewhere to improve that. Just models.TicketAndThreadsJSON should work if the file imports that package.

Also, the (application/json) is kind of redundant btw; it gets added as a default if you didn't add an explicit content-type. It's just for the handful of endpoints that we have that don't have JSON.

Which all new endpoints should be json (maybe some archive endpoints)

I think we will still have a few rare exceptions like the contact form, the "mark as read"-pixel, and maybe file uploads.

Conforming it to your correction actually cause a panic. But a regular struct works, which I think is most important feature.

This is panic trace if it is useful

❯ kommentaar ./api/v2/tickets                        
panic: runtime error: index out of range             

goroutine 1 [running]:    
github.com/teamwork/kommentaar/docparse.getReference(0xc420016f00, 0x1b, 0xc420012a94, 0x27, 0xc420189a80, 0x2, 0x2, 0xc420022a50, 0x7f55b38f5000)
        /home/abiola/go/src/github.com/teamwork/kommentaar/docparse/docparse.go:492 +0xf29                
github.com/teamwork/kommentaar/docparse.parseParams(0xc420022960, 0x3f, 0xc420012a94, 0x27, 0xc9, 0x0, 0x0)
        /home/abiola/go/src/github.com/teamwork/kommentaar/docparse/docparse.go:362 +0x846                
github.com/teamwork/kommentaar/docparse.Parse(0xc420020205, 0xc2, 0xc420012a94, 0x27, 0x0, 0x0, 0x0)      
        /home/abiola/go/src/github.com/teamwork/kommentaar/docparse/docparse.go:210 +0x622                
github.com/teamwork/kommentaar/docparse.FindComments(0xc42000c070, 0x1, 0x1, 0x7a4a20, 0x0, 0x0)          
        /home/abiola/go/src/github.com/teamwork/kommentaar/docparse/find.go:37 +0x139                     
main.main()               
        /home/abiola/go/src/github.com/teamwork/kommentaar/main.go:51 +0x267                    

But this works.

// POST /v2/tickets
// Create new ticket.
//
// Response 201 (application/json):
//   $object: createTicketResponse
//
// Response 400 (application/json):
//   undocumented
//
// Response 403 (application/json):
//   undocumented

type createTicketResponse struct {
    Ticket models.TicketAndThreadsJSON `json:"ticket"`
}

I changed the syntax:

// Find a type by name. It can either be in the current path ("SomeStruct"), a
// package path with a type (e.g. "github.com/foo/bar.SomeStruct"), or something
// from an imported package (e.g. "models.SomeStruct").

So you can now use models.TicketAndThreadsJSON if the file imports that, or use the full package path if it doesn't: github.com/teamwork/desk/models.TicketAndThreadsJSON.