MediaBrowser / Emby

Emby Server is a personal media server with apps on just about every device.
https://emby.media
GNU General Public License v2.0
3.99k stars 792 forks source link

Go API Client: Invalid Go package name, contains hyphens #3837

Open Noah-Huppert opened 1 month ago

Noah-Huppert commented 1 month ago

The auto-generated Go API client has the package embyclient-rest-go in every source file. This is not a valid Go package name. An alternative valid package name would be embyclient_rest_go or embyclient if we want to follow best practices for package naming

LukePulverenti commented 1 month ago

@softworkz

Noah-Huppert commented 1 month ago

I found a few other issues with the Golang API. It seems like there were some duplicate struct names as well. Here is the openapi-generator config I used to successfully create a compilable version of the Golang API:

generatorName: go
inputSpec: # <your emby openapi.json>
outputDir: ./embyclient/
packageName: embyclient

# Required for Golang imports to work
gitHost: github.com
gitUserId: # <your git username>
gitRepoId: # <your git repo>

validateSpec: False
modelNamePrefix: Model

# Go generator
isGoSubmodule: True
withGoMod: False
structPrefix: True
enumClassPrefix: True

I then had to run this find and replace on the output files due to a bug where the openapi-generator seems to add the modelNamePrefix twice when referring to model structs:

sed -i 's/ModelModel/Model/g' embyclient/*.go
softworkz commented 4 weeks ago

I fixed the package name. Can you please check whether it's working now?

Publish.zip

Noah-Huppert commented 3 weeks ago

I fixed the package name. Can you please check whether it's working now?

Publish.zip

Sure thing. I'll give it a test when I have a moment free.