Forum Discussion

prpuritan's avatar
New Contributor
3 years ago

Use the Codegen Go generator to produce a go module

The usage documentation and guides for have an option for the swagger-codegen:

  • --additional-properties=GoSubmodule=true

But it does not generate a go module!

Any ideas - is this a bug?

3 Replies

  • Hi prpuritan 


    Could you share the full command you're using? And if possible, could you try the same command with the petstore example, to see if that fails too.

    • prpuritan's avatar
      New Contributor
      I'm using this to generate the go code for an API spec - the expected
      output includes a go.mod file in the output directory.


      PAUL ROSHAM // Systems Engineer | Pure Storage, Inc.
      *Level 18, 567 Collins Street Melbourne, VIC 3000, Australia*
      +61 411 198 989 <+61-411-198989> |
      • prpuritan's avatar
        New Contributor

        hi - not sure if you saw the attachment. I put the petstore API spec into petstore.json and used the following text in a Makefile. This depends on having Docker desktop (and Xcode on my MacBook) installed.



        GOMOD_GENERATOR = swaggerapi/swagger-codegen-cli generate -l go
        SPEC_GENERATOR = swaggerapi/swagger-codegen-cli generate -l openapi --additional-properties=outputFile

        all: petstore

        petstore: petstore/go.mod petstore.json

        @curl > petstore.json

        # Use a containerized Go Makefile and Dockerfile
        # docker run --rm -v "$(PWD)/$(@D)":/usr/local/go/src/client golang:1.16 go build client

        %/go.mod: %.json
        docker run --rm -v "$(PWD):/src" -w /src $(GOMOD_GENERATOR) \
        -i $< -o $(@D) \
        --additional-properties=generateInterfaces=true \
        --additional-properties=GoSubmodule=true \
        --additional-properties=packageName=$(@D) \