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

Nested structs in type_gen should not be anonymous structs

Open Cidan opened this issue 2 years ago • 4 comments

see: https://github.com/typesense/typesense-go/blob/4d2cad02695cd09c26543af066a1219de1522b2f/typesense/api/types_gen.go#L153

Nested structs should not be anonymous structs, as this makes it so the caller needs to define the struct manually in order to pass it in as an argument to the function.

Cidan avatar Dec 20 '23 21:12 Cidan

We use openapi code generator to generates these types from an API spec. Unfortunately, we are restricted by that.

kishorenc avatar Dec 21 '23 13:12 kishorenc

Fortunately, you are not restricted as this is an option in oapi-codegen, which you use. You must update the schema to add x-go-type-name to the affected fields, which thankfully aren't that many at all.

I need to stress here that currently, the client is incredibly cumbersome to use without this change and will make adoption very difficult. I'm not sure what the authoritative source for the openapi spec is though.

Cidan avatar Dec 21 '23 17:12 Cidan

Fortunately, you are not restricted as this is an option in oapi-codegen, which you use. You must update the schema to add x-go-type-name to the affected fields, which thankfully aren't that many at all.

I need to stress here that currently, the client is incredibly cumbersome to use without this change and will make adoption very difficult. I'm not sure what the authoritative source for the openapi spec is though.

Up! Please, it would be a welcome implementation. Go as you know is a stong typed language, having anonymous nested structs greatly lowers the dev experience.

luigibarbato avatar Jan 23 '24 14:01 luigibarbato

The api spec is maintained here: https://github.com/typesense/typesense-api-spec/blob/master/openapi.yml

Happy to accept a PR for this change.

kishorenc avatar Jan 23 '24 15:01 kishorenc