Skip to content

Swagger info consumes: "application/json" setting doesn't take effect in generated output #4861

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

Open
fanqie opened this issue May 15, 2025 · 2 comments
Assignees
Labels
area/goctl Categorizes issue or PR as related to goctl.

Comments

@fanqie
Copy link

fanqie commented May 15, 2025

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior, if applicable:

  1. The code is

    info (
     consumes: "application/json"
     produces: "application/json"

)


2. The error is
生成结果为:
consumes: "application/x-www-form-urlencoded" 

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Environments (please complete the following information):**
- OS: [e.g. Linux]
- go-zero version [e.g. 1.2.1]
- goctl version [e.g. 1.2.1, optional]

**More description**
Add any other context about the problem here.
@kevwan kevwan changed the title swagger 指定info consumes: "application/json" 后生成结果不生效 Swagger info consumes: "application/json" setting doesn't take effect in generated output May 15, 2025
@singhJasvinder101
Copy link

Can you please share some more information to reproduce the same error. In my case it is perfectly fine

info (
	version:     "1.0"
	consumes:    "application/json"
	produces:    "application/json"
	description: "API for testing"
)

type Request {
	Name string `json:"name"`
}

type Response {
	Message string `json:"message"`
}

service TestService {
	@handler TestHandler
	post /test (Request) returns (Response)
}

Output

➜  test curl -i -X POST http://localhost:8888/test \
  -H "Content-Type: application/json" \
  -d '{"name": "hello"}'

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Traceparent: 00-63d653c0005a3e98bc8f5df9fd23790d-185b30d0d427cf2f-00
Date: Sat, 17 May 2025 17:50:33 GMT
Content-Length: 26

{"message":"Hello, hello"}%     

@kesonan
Copy link
Collaborator

kesonan commented May 18, 2025

@fanqie Thanks for your contribution, as you noted, the consumes and produces does not work now, all of the consumes generate from the structure tag in request body, and all of the produces are fixed value application/json,now you can ignore it and I'll support it in the future.

@kevwan kevwan added the area/goctl Categorizes issue or PR as related to goctl. label May 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/goctl Categorizes issue or PR as related to goctl.
Projects
None yet
Development

No branches or pull requests

4 participants