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

missing import: model not compiling #255

Closed
baracoder opened this issue Feb 4, 2016 · 6 comments
Closed

missing import: model not compiling #255

baracoder opened this issue Feb 4, 2016 · 6 comments

Comments

@baracoder
Copy link

Hello,

I have generated code from a spec.
While compiling i get an error

go install ./cmd/ini-goapi-server                                                                                   :(
# ini-goapi/models
models/file.go:34: undefined: strfmt
models/hit.go:26: undefined: strfmt
models/member.go:18: undefined: strfmt

Example model file content:

package models

// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command

/*File File file

swagger:model File
*/
type File struct {

    /* text content of the file, if availible
     */
    Content *string `json:"content,omitempty"`

    /* DownloadLink download link
     */
    DownloadLink *string `json:"downloadLink,omitempty"`

    /* Mime mime
     */
    Mime *string `json:"mime,omitempty"`

    /* Name name
     */
    Name *string `json:"name,omitempty"`

    /* size in bytes
     */
    Size *string `json:"size,omitempty"`
}

// Validate validates this file
func (m *File) Validate(formats strfmt.Registry) error {
    return nil
}

go version go1.4.2 linux/amd64

@casualjim casualjim added the bug label Feb 4, 2016
@casualjim casualjim added this to the Complete functionality milestone Feb 4, 2016
@casualjim
Copy link
Member

Would it be possible for you to try with go1.5?

swagger uses GO15VENDOREXPERIMENT and I think it might not be able to find strfmt which is why it's not

@rynbrd
Copy link

rynbrd commented Feb 21, 2016

I'm having the same issue with the static 0.3.0 binary. The generated files which have this error simply doesn't have an import statement for strfmt.

@casualjim
Copy link
Member

I'll publish new binaries tonight but you do need go-swagger in your GOPATH for this to work out.

@rynbrd
Copy link

rynbrd commented Feb 22, 2016

Meaning you should go get go-swagger prior to calling swagger generate?

How is it that this affects swagger's ability to generate the correct import statement? Other models are generated with the correct imports.

casualjim added a commit that referenced this issue Feb 22, 2016
@casualjim
Copy link
Member

@bluedragonx go-swagger makes use of goimports to reformat and get the imports for the generated files. Part of that is optimizing the imports and to discover them properly it wants for them to be in the $GOPATH so goimports can discover them.

Anyway for strfmt in particular I've aliased them now which will hopefully keep them

@rynbrd
Copy link

rynbrd commented Feb 22, 2016

Thanks, I appreciate the explanation!

@casualjim casualjim reopened this Feb 25, 2016
pieter-lazzaro added a commit to pieter-lazzaro/go-swagger that referenced this issue Mar 2, 2016
# By Ivan Porto Carrero (45) and others
# Via Ivan Porto Carrero (23) and EaseWay Hu (1)
* 'master' of https://github.com/go-swagger/go-swagger: (49 commits)
  fix missing httpkit import in models
  fix linting error on samples
  fixes go-swagger#330 package for client is client package
  update bindata.go
  update vendored depedencies
  contributes to go-swagger#96 introduce net/context
  allow streaming bodies (io.ReadCloser for binary string format)
  use shared api error in clients
  fixes go-swagger#325 less overlap for enum names
  optionally scan for models
  fixes go-swagger#319 detect if map property is base type
  fixes go-swagger#322 reinstate --skip-* arguments
  Add tar, gzip support
  update vendor for goimports
  fixes go-swagger#255 more, make a full path for goimports
  fixes go-swagger#215 ensure file names don't end with _test
  also recognize application/octet-stream in generator
  update changelog
  add missing {{ end }}
  adds a ResponderFunc helper
  ...

Conflicts:
	cmd/swagger/commands/generate/server.go
	generator/shared.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants