typesense / typesense-go

Go client for Typesense: https://github.com/typesense/typesense
Apache License 2.0
208 stars 55 forks source link

Nested structs in type_gen should not be anonymous structs #154

Open Cidan opened 8 months ago

Cidan commented 8 months ago

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.

kishorenc commented 8 months ago

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

Cidan commented 8 months ago

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.

luigibarbato commented 7 months ago

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.

kishorenc commented 7 months ago

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.