Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on Mac OS X When Generating Spec #1560

Open
nathanwilk7 opened this issue May 29, 2018 · 5 comments
Open

Error on Mac OS X When Generating Spec #1560

nathanwilk7 opened this issue May 29, 2018 · 5 comments
Labels
generate spec Related to spec generation from code

Comments

@nathanwilk7
Copy link
Contributor

Problem statement

When I run swagger generate spec -o ./swagger.json in https://github.com/go-swagger/go-swagger/tree/master/examples/tutorials/custom-server/cmd/greeter, I get the error below

In file included from /usr/local/go/src/crypto/x509/root_cgo_darwin.go:16:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h:43:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CFBase.h:72:
/usr/local/include/Block.h:16:3: error: Never include this file directly. Use <lzma.h> instead.
#       error Never include this file directly. Use <lzma.h> instead.
        ^
1 error generated.
cgo failed: [go tool cgo -objdir /var/folders/df/d15mpgyn17q745h93x50t_ssnsm4pk/T/crypto_x509_C566504259 -- -I /var/folders/df/d15mpgyn17q745h93x50t_ssnsm4pk/T/crypto_x509_C566504259 -mmacosx-version-min=10.6 -D__MAC_OS_X_VERSION_MAX_ALLOWED=1080 root_cgo_darwin.go]: exit status 1
/usr/local/go/src/crypto/x509/cert_pool.go:38:9: undeclared name: loadSystemRoots
/usr/local/go/src/crypto/x509/root.go:21:32: undeclared name: loadSystemRoots
/Users/nate.wilkinson/projects/testing/test-swagger/go-swagger/examples/tutorials/custom-server/cmd/greeter/main.go:8:2: could not import github.com/go-openapi/loads (cannot find package "github.com/go-openapi/loads" in any of:
	/usr/local/go/src/github.com/go-openapi/loads (from $GOROOT)
	/Users/nate.wilkinson/go/src/github.com/go-openapi/loads (from $GOPATH))
/Users/nate.wilkinson/projects/testing/test-swagger/go-swagger/examples/tutorials/custom-server/cmd/greeter/main.go:9:2: could not import github.com/go-openapi/runtime/middleware (cannot find package "github.com/go-openapi/runtime/middleware" in any of:
	/usr/local/go/src/github.com/go-openapi/runtime/middleware (from $GOROOT)
	/Users/nate.wilkinson/go/src/github.com/go-openapi/runtime/middleware (from $GOPATH))
/Users/nate.wilkinson/projects/testing/test-swagger/go-swagger/examples/tutorials/custom-server/cmd/greeter/main.go:10:2: could not import github.com/go-openapi/swag (cannot find package "github.com/go-openapi/swag" in any of:
	/usr/local/go/src/github.com/go-openapi/swag (from $GOROOT)
	/Users/nate.wilkinson/go/src/github.com/go-openapi/swag (from $GOPATH))
/Users/nate.wilkinson/projects/testing/test-swagger/go-swagger/examples/tutorials/custom-server/cmd/greeter/main.go:38:3: cannot convert (func(params operations.GetGreetingParams) middleware.Responder literal) (value of type func(params github.com/go-swagger/go-swagger/examples/tutorials/custom-server/gen/restapi/operations.GetGreetingParams) invalid type) to github.com/go-swagger/go-swagger/examples/tutorials/custom-server/gen/restapi/operations.GetGreetingHandlerFunc
couldn't load packages due to errors: crypto/x509, .

Steps to reproduce

git clone https://github.com/go-swagger/go-swagger.git
cd go-swagger/examples/tutorials/custom-server/cmd/greeter
swagger generate spec -o ./swagger.json

Environment

swagger version
version: 0.14.0
commit: 25e637c
go version: 1.8.1 darwin/amd64
OS: macOS 10.13.4

@fredbi fredbi added the generate spec Related to spec generation from code label May 29, 2018
@amitsaurav
Copy link

@nathanwilk7 Am getting the same error. Were you able to find a resolution? Thanks!

@joemcmahon
Copy link

joemcmahon commented Jul 30, 2018

From the go 1.10 release notes:

Cgo now translates some C types that would normally map to a pointer type in Go, to a uintptr instead. These types include the CFTypeRef hierarchy in Darwin's CoreFoundation framework and the jobject hierarchy in Java's JNI interface.

These types must be uintptr on the Go side because they would otherwise confuse the Go garbage collector; they are sometimes not really pointers but data structures encoded in a pointer-sized integer. Pointers to Go memory must not be stored in these uintptr values.

Because of this change, values of the affected types need to be zero-initialized with the constant 0 instead of the constant nil. Go 1.10 provides gofix modules to help with that rewrite:

go tool fix -r cftype <pkg>
go tool fix -r jni <pkg>

github.com/google/certificate-transparency-go has fixed this themselves by forking x509 and adding support for both versions of the nil ref. This is a possible option but this really should be fixed in the core library instead.

https://github.com/google/certificate-transparency-go/pull/155/files

@joemcmahon
Copy link

joemcmahon commented Jul 31, 2018

I was able to get the HEAD of go-swagger to run successfully as follows:

brew uninstall --force go-swagger
mkdir ~/go-tools
cd ~/go-tools
export GOPATH=~/go-tools
go get github.com/go-swagger/go-swagger
cd src/github.com/go-swagger/go-swagger
go build cmd/swagger/swagger.go

The swagger binary created this way was successful in parsing and validating our Swagger specs with
swagger generate spec -o swagger.json; swagger validate swagger.json. If this works for you, then I suppose we can close this issue.

@bigodines
Copy link

bigodines commented Aug 8, 2018

It worked for me. I was having issues with math.Round and compiling from HEAD fixed it.

@shrimpliu
Copy link

shrimpliu commented Jan 17, 2019

just run

CGO_ENABLED=0 swagger generate spec

it worked for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
generate spec Related to spec generation from code
Projects
None yet
Development

No branches or pull requests

6 participants