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

Generating uncompilable code when response code >= 512 #1893

Closed
apuigsech opened this issue Mar 1, 2019 · 5 comments · Fixed by #1980
Closed

Generating uncompilable code when response code >= 512 #1893

apuigsech opened this issue Mar 1, 2019 · 5 comments · Fixed by #1980
Assignees

Comments

@apuigsech
Copy link

Problem statement

If response code is 512 or higher the generated code is not valid and do not compile.

This is the error;

$ go build cmd/hello-world-app-server/main.go
# test/api/restapi/operations
restapi/operations/hello.go:29:16: unknown field 'Context' in struct literal of type Hello
restapi/operations/hello.go:29:30: unknown field 'Handler' in struct literal of type Hello
restapi/operations/hello_responses.go:21:6: Hello redeclared in this block
	previous declaration at restapi/operations/hello.go:37:6
restapi/operations/hello_responses.go:25:6: NewHello redeclared in this block
	previous declaration at restapi/operations/hello.go:28:63
restapi/operations/hello_world_app_api.go:244:30: cannot use NewHello(o.context, o.HelloHandler) (type *Hello) as type http.Handler in assignment:
	*Hello does not implement http.Handler (missing ServeHTTP method)
restapi/operations/hello_world_app_api.go:244:40: too many arguments in call to NewHello
	have (*middleware.Context, HelloHandler)
	want ()

Swagger specification

swagger: "2.0"
info:
  version: "0.0.1"
  title: Hello World App
paths:
  /hello:
    get:
      operationId: hello
      responses:
        "512":
          description: Success

Steps to reproduce

$ swagger generate server
(...)
$ go build cmd/hello-world-app-server/main.go

Environment

swagger version: dev (github.com/go-swagger/go-swagger/cmd/swagger)
go version: 1.11.5
OS: OSX

@fredbi
Copy link
Contributor

fredbi commented Mar 2, 2019

Such value is not a valid http status code which is required by swagger

@casualjim
Copy link
Member

actually the status codes are not an exhaustive list, the numbers that are not well-known just don't have a default message. I got sidetracked with work, but this is definitely a piece of missing functionality because we should be able to deal with this.

@fredbi fredbi added the bug label Mar 5, 2019
@apuigsech
Copy link
Author

There are some Unofficial Status code that are up to 512; https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#5xx_Server_errors

For instance the ones used by Cloudflare; https://support.cloudflare.com/hc/en-us/sections/200820298-Error-Pages

I would recommend to do not limit that value to strict specifications.

@fredbi
Copy link
Contributor

fredbi commented Mar 6, 2019

Yeah, @casualjim is right. Bug acknowledged

@gregmarr
Copy link
Contributor

gregmarr commented Mar 6, 2019

The HTTP specification just says that it's a 3 digit number that starts with 1, 2, 3, 4, or 5. Thus, the valid range is 100 to 599.

https://tools.ietf.org/html/rfc7231 section 6

@fredbi fredbi self-assigned this Jun 21, 2019
fredbi added a commit to fredbi/go-swagger that referenced this issue Jun 23, 2019
* fixes go-swagger#1893
* codegen (client and server) now supports codes other than the well-known ones published by go-openapi/runtime

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
fredbi added a commit that referenced this issue Jun 23, 2019
* fixes #1893
* codegen (client and server) now supports codes other than the well-known ones published by go-openapi/runtime

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
djgilcrease pushed a commit to djgilcrease/go-swagger that referenced this issue Jun 26, 2019
* fixes go-swagger#1893
* codegen (client and server) now supports codes other than the well-known ones published by go-openapi/runtime

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Signed-off-by: Dj Gilcrease <d.gilcrease@f5.com>
fredbi pushed a commit that referenced this issue Jun 27, 2019
* do not force set the api logger to log.Printf

the logger already defaults so do not force set it in `SetAPI` since that would overwrite one I set in the API before calling `SetAPI`

Signed-off-by: Dj Gilcrease <d.gilcrease@f5.com>

* Add CodeTriage badge to go-swagger/go-swagger

Adds a badge showing the number of people helping this repo on CodeTriage.

[![Open Source Helpers](https://www.codetriage.com/go-swagger/go-swagger/badges/users.svg)](https://www.codetriage.com/go-swagger/go-swagger)

## What is CodeTriage?

CodeTriage is an Open Source app that is designed to make contributing to Open Source projects easier. It works by sending subscribers a few open issues in their inbox. If subscribers get busy, there is an algorithm that backs off issue load so they do not get overwhelmed

[Read more about the CodeTriage project](https://www.codetriage.com/what).

## Why am I getting this PR?

Your project was picked by the human, @schneems. They selected it from the projects submitted to https://www.codetriage.com and hand edited the PR. How did your project get added to [CodeTriage](https://www.codetriage.com/what)? Roughly over 3 years ago, [tamarabartlett](https://github.com/tamarabartlett) added this project to CodeTriage in order to start contributing. Since then, 13 people have subscribed to help this repo.

## What does adding a badge accomplish?

Adding a badge invites people to help contribute to your project. It also lets developers know that others are invested in the longterm success and maintainability of the project.

You can see an example of a CodeTriage badge on these popular OSS READMEs:

- [![Email clients like GMAIL do not render SVG images](https://www.codetriage.com/rails/rails/badges/users.svg)](https://www.codetriage.com/rails/rails) https://github.com/rails/rails
- [![Email clients like GMAIL do not render SVG images](https://www.codetriage.com/crystal-lang/crystal/badges/users.svg)](https://www.codetriage.com/crystal-lang/crystal) https://github.com/crystal-lang/crystal

## Have a question or comment?

While I am a bot, this PR was manually reviewed and monitored by a human - @schneems. My job is writing commit messages and handling PR logistics.

If you have any questions, you can reply back to this PR and they will be answered by @schneems. If you do not want a badge right now, no worries, close the PR, you will not hear from me again.

Thanks for making your project Open Source! Any feedback is greatly appreciated.

Signed-off-by: Dj Gilcrease <d.gilcrease@f5.com>

* Fix basic auth for stratoscale template

Use the correct signature for the basic authentication interface.
This caused the compilation to fail. Fixes #1765

Signed-off-by: Joakim Soderberg <joakim.soderberg@gmail.com>
Signed-off-by: Dj Gilcrease <d.gilcrease@f5.com>

* Multiple tags operations: deduce package from first tag

as for only-one-tag operations, instead of default "operations" as when no
tags are available.

Signed-off-by: Maxime Soulé <btik-git@scoubidou.com>
Signed-off-by: Dj Gilcrease <d.gilcrease@f5.com>

* keep spec order on nested objects

Signed-off-by: kofler <efi.kofler@flir.com>
Signed-off-by: Dj Gilcrease <d.gilcrease@f5.com>

* chore(ci): set codecov patch expectation to a fixed level, exclude bindata.go from coverage

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Signed-off-by: Dj Gilcrease <d.gilcrease@f5.com>

* chore(ack): acknowledges fix for #1490 (client w/ body as interface{})

fixes #1490

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Signed-off-by: Dj Gilcrease <d.gilcrease@f5.com>

* chore(ack): acknowledges fix for #973 (client w/ param UUID)

* fixes #973

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Signed-off-by: Dj Gilcrease <d.gilcrease@f5.com>

* 151 add a diff sub command (#1961)

* x-go-type: if no imports are specified, assume that the referred type is inside the same package

Signed-off-by: Emil Nikolov <emil.e.nikolov@gmail.com>
Signed-off-by: Jason Wraxall <>
Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>

* support keep spec properties order

Signed-off-by: Efi-Kofler <efi.kofler@tectonic.network>
Signed-off-by: Jason Wraxall <>
Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>

* Added diff sub command

Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>
Signed-off-by: Jason Wraxall <>
Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>

* Refactored location node code. Detected reponse and param header changes

Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>
Signed-off-by: Jason Wraxall <>
Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>

* Updated test fixtures

Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>
Signed-off-by: Jason Wraxall <>
Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>

* Removed redundant method and fixed default/required on response headers

Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>
Signed-off-by: Jason Wraxall <>
Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>

* urlbuilder template fixed to support query params named 'append' (#1949)

fixes #1948

Update urlbuilder_test.go to support added query name mangling.

Update bindata.go

Signed-off-by: Jim Turnquist <jim@boonlogic.com>
Signed-off-by: Jason Wraxall <>
Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>

* Refactored type names and removed some dead code

Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>
Signed-off-by: Jason Wraxall <>
Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>

* Refactored analyser and diff code in prep for ignore processing

Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>
Signed-off-by: Jason Wraxall <>
Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>

* Added ability to igore selected diffs

Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>
Signed-off-by: Jason Wraxall <>
Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>

* Added ability to ignore deprecated operations

Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>
Signed-off-by: Jason Wraxall <>
Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>

* Added docs

Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>
Signed-off-by: Jason Wraxall <>
Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>

* Fixed typo compatabilty -> compatibilty

Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>
Signed-off-by: Jason Wraxall <>
Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>

* Fixed typo and scopelint issue

Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>
Signed-off-by: Jason Wraxall <>
Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>

* scan: proper parse for numeric elements (future validation pass).

Signed-off-by: Dzmitry.Harupa <dzmitry.harupa@1pt.com>
Signed-off-by: Jason Wraxall <>
Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>

* fix test

Signed-off-by: Dzmitry.Harupa <dzmitry.harupa@1pt.com>

fix building

Signed-off-by: Dzmitry.Harupa <dzmitry.harupa@1pt.com>

review: goconst

Signed-off-by: d7561985 <d7561985@gmail.com>

update

Signed-off-by: d7561985 <d7561985@gmail.com>

test fix

Signed-off-by: d7561985 <d7561985@gmail.com>

test fix

Signed-off-by: d7561985 <d7561985@gmail.com>

add const for linter

Signed-off-by: d7561985 <d7561985@gmail.com>
Signed-off-by: Jason Wraxall <>
Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>

* Added gocrest in various spots

Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>
Signed-off-by: Jason Wraxall <>
Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>

* Updating vendor folder and adding coverage.txt to gitignore

Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>
Signed-off-by: Jason Wraxall <>
Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>

* Lower-cased error - lint warning

Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>
Signed-off-by: Jason Wraxall <>
Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>

* Updated go.mod

Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>
Signed-off-by: Jason Wraxall <>
Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>

* Added files nuked by rogue gitignore

Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>
Signed-off-by: Jason Wraxall <>
Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>

* Added files lost due to bad gitignore

Signed-off-by: Jason Wraxall <>
Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>

* Updated readme

Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>
Signed-off-by: Jason Wraxall <>
Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>

* Updated README

Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>
Signed-off-by: Jason Wraxall <>
Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>

* Adding lost code and new tests

Signed-off-by: Jason Wraxall <>
Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>

* Updated ignore diff test

Signed-off-by: Jason Wraxall <>
Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>

* Circle CI closed some issues

Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>

* Updated lint settings as recommended by reviewer

Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>

* Updated capitalisation of global

Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>

* ran go gmt as asked

Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>

* fixed loop scope issue

Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>

* fixed more formatting

Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>

* fixed yet more formatting

Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>

* ran goimports

Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>

* nuked spurious warning from dupl

Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>

* Removed dead code and added an array diff test

Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>

* Resolved code suggestion

Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>

* Cleaning code

Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>

* moved test code into diff package to improve coverage report

Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>

* fixed lint suggestion

Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>

* Added kitchensink to diff fictures to improve coverage and fixed the bugs the new test cases detected ;-)

Signed-off-by: Jason Wraxall <wjase@yahoo.com.au>

* Improving formatting and coverage at the same time

Signed-off-by: Jason Wraxall <jwraxall@tyro.com>

* Fixed cicd issues

Signed-off-by: Jason Wraxall <jwraxall@tyro.com>

* Added test for map diff

Signed-off-by: Jason Wraxall <jwraxall@tyro.com>

* Removed dead code

Signed-off-by: Jason Wraxall <jwraxall@tyro.com>

* Added empty arg error test

Signed-off-by: Jason Wraxall <jwraxall@tyro.com>

* Added test cases to get above 80% coverage

Signed-off-by: Jason Wraxall <jwraxall@tyro.com>

* Added extra test permutations to boost coverage

Signed-off-by: Jason Wraxall <jwraxall@tyro.com>
Signed-off-by: Dj Gilcrease <d.gilcrease@f5.com>

* chore(ack): acknowledges fix for #1020 (client w/ param File)

fixes #1020

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Signed-off-by: Dj Gilcrease <d.gilcrease@f5.com>

* Acknowlegde #1339 was fixed (generated client w/ binary param)

Fixes #1339

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Signed-off-by: Dj Gilcrease <d.gilcrease@f5.com>

* fixes #1878 (conflicting output options in CLI)

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Signed-off-by: Dj Gilcrease <d.gilcrease@f5.com>

* doc: updated CLI usage, including the newly added diff command

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Signed-off-by: Dj Gilcrease <d.gilcrease@f5.com>

* Added support for non-standard http codes (#1980)

* fixes #1893
* codegen (client and server) now supports codes other than the well-known ones published by go-openapi/runtime

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Signed-off-by: Dj Gilcrease <d.gilcrease@f5.com>

* fix(server): generates server to enable http/2

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Signed-off-by: Dj Gilcrease <d.gilcrease@f5.com>

* Generated client: handles unexpected successful responses and returns default response with error rather than panicking (#1978)

Fixes #1518

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Signed-off-by: Dj Gilcrease <d.gilcrease@f5.com>

* Honour JSON ,string directive of ptr field when generating spec

Signed-off-by: wych42 <wych101010@gmail.com>
Signed-off-by: Dj Gilcrease <d.gilcrease@f5.com>

* do not force set the api logger to log.Printf

the logger already defaults so do not force set it in `SetAPI` since that would overwrite one I set in the API before calling `SetAPI`

Signed-off-by: Dj Gilcrease <d.gilcrease@f5.com>

* Regenerate bindata

Signed-off-by: Dj Gilcrease <d.gilcrease@f5.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants