Description
The code generated by the go-server generator fails to compile if the API does not contain any endpoints with a path parameter or a request body. This is happening because the imports declared in the generated Go file are fixed:
import (
"encoding/json" // <-------------- Only used when the API contains a request body
"net/http"
"strings"
"github.com/gorilla/mux" // <----- Only used when the API contains Path parameters "/path/{param1}"
)
openapi-generator version
5.0.1
OpenAPI declaration file content or url
This simple spec generates code that fails to compile:
openapi: 3.0.0
info:
description: This is a sample server.
license:
name: Apache-2.0
url: https://www.apache.org/licenses/LICENSE-2.0.html
title: OpenAPI
version: 1.0.0
externalDocs:
description: Find out more about this
url: http://test.eu
servers:
- url: http://test.eu/
paths:
/simpleGet:
get:
operationId: simpleGet
responses:
"200":
description: Ok
Generation Details
openapi-generator-cli generate -i spec.yml -g go-server -o out
Steps to reproduce
- Generate a simple api using
go-server generator (command above).
- Try to compile the generated code using
go build out/go/*.go.
- You will get the following error:
# command-line-arguments
out/go/api_default.go:13:2: imported and not used: "encoding/json"
out/go/api_default.go:17:2: imported and not used: "github.com/gorilla/mux"
Description
The code generated by the
go-servergenerator fails to compile if the API does not contain any endpoints with a path parameter or a request body. This is happening because the imports declared in the generated Go file are fixed:openapi-generator version
5.0.1
OpenAPI declaration file content or url
This simple spec generates code that fails to compile:
Generation Details
openapi-generator-cli generate -i spec.yml -g go-server -o outSteps to reproduce
go-servergenerator (command above).go build out/go/*.go.