Search code examples
gomodulecode-generationopenapi-generator

How do you specify the module path when using go for openapi generator?


When generating a go module with

openapi-generator-cli generate \
    --input-spec ../spec/myapi.yml \
    --generator-name go \
    --output ./generated/go \
    --package-name myapi \
    --global-property models,supportingFiles

the genrated go.mod file specifies the module as

module github.com/GIT_USER_ID/GIT_REPO_ID

go 1.18

require (
)

How does one override the github.com/GIT_USER_ID/GIT_REPO_ID to be something like: github.com/myrepo/somedir/myapi?

I've checked the OpenAPI Generator docs and the Go Generator docs and neither seem to indicate how to do so.

Does anyone have any ideas?


Solution

  • Of course as soon as I post I do one more search and find the answer here stating one can use the flags --git-user-id and --git-repo-id.

    openapi-generator-cli generate \
        --input-spec ../spec/myapi.yml \
        --generator-name go \
        --output ./generated/go \
        --package-name myapi \
        --git-user-id myuser \
        --git-repo-id myrepo/somedir/myapi/generated/go \    
        --global-property models,supportingFiles
    

    which results in a mod.go file of:

    module github.com/myuser/myrepo/somedir/myapi/generated/go
    
    go 1.18
    
    require (
    )