-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
SmallRye OpenAPI outputs Chinese garbled characters in Json #44569
Comments
/cc @EricWittmann (openapi), @Ladicek (smallrye), @MikeEdgar (openapi), @jmartisk (smallrye), @phillip-kruger (openapi,smallrye), @radcortez (smallrye) |
Can you have a look at the |
@MorganMaohong There is no problem in my environment. |
Thank you for your reply. Can you provide me with a template project with smallrye-openApi extension so that I can test it in my local environment? Thank you very much! |
@MorganMaohong Here is a simple. |
@gsmet @yuhaibohotmail |
@gsmet This extension is very useful. I think it would be perfect if these configurations could be exposed and modified through configuration files. |
Which extension are you referring to @MorganMaohong ? |
@geoand In this extension, when I use the
|
But it sounds like it's an issue with your environment, no? |
@geoand Sorry, it is indeed my environment problem. The extension obtains the system encoding format. I would like to suggest a way to provide a configuration file to avoid this problem. It would be better if the extension uses utf-8 encoding by default. |
Let's see what @MikeEdgar thinks about that |
Thank you so much |
@MorganMaohong , I'm curious if you run |
@MikeEdgar,Thank you for reminding me. I think I understand why this happens. I checked the file in your way. The default UTF-8 encoding format in vs code is normal. When it is switched to Chinese GBK encoding format, it shows the same garbled characters as the /q/openapi interface. I downloaded the file in the dev interface and found that there was no suffix. After adding the suffix YAML or JSON, it was displayed as garbled characters. I guess that when the IO stream is written without setting the encoding format or the file without the suffix, the system default encoding format will be used. My computer is in the Chinese operating system environment, so it is GBK encoding format. So when I switched to Unicode encoding format, Chinese garbled characters will not appear.
quarkus-generated-openapi-doc.JSON
These are my speculations, please forgive me if there are any mistakes. |
The response will use UTF-8 in the Content-type regardless of how the OpenAPI doc is requested (suffix or not, Line 59 in 8df922d
|
@MikeEdgar,I switched the Windows language setting back to the Chinese environment, and then used curl and postman to do a test, but garbled characters still appeared. If I switched to unicode, no garbled characters would appear no matter what method I used. using curlUsing PostmanWindows Unicode beta testing feature |
@MorganMaohong does it happen with other endpoints in the application or just the OpenAPI response? For example, if you create a simple REST endpoint that returnes a |
@MikeEdgar According to what you said, I created a test REST request and it was normal. In addition, I used various REST tools to test and it was also normal. |
@MorganMaohong here's one more thing to try to understand where the problem is occurring. Create a |
@MikeEdgar I set up to load the static Then |
And just to confirm, you did that using the Chinese Windows environment, correct? |
@MikeEdgar Yes, I'm sure, I checked, |
@MorganMaohong , since some of the characters do appear to be displaying properly, can you let me know in particular which character(s) are having the issue? Or, are some characters being turned into other (valid) Chinese characters, in addition to those being shown as invalid? E.g., in your earlier example you had this in your "before" file: "tags" : [ {
"name" : "测试",
"description" : "这是一个简单的测试"
} ], And in the "after" file: tags:
- name: 娴嬭瘯
description: 杩欐槸涓�涓畝鍗曠殑娴嬭瘯 Should these have been the same? Even the tag name is a different length. |
@MikeEdgar All Chinese characters will have conversion errors, because Chinese characters usually occupy multiple characters in the encoding standard.
They are different, and I can't even read the converted Chinese characters. |
@MikeEdgar I suddenly had an idea and used Japanese as the system language, where Tag and description have the same meaning as Chinese, "Test" and "This is a simple test", and the encoding format error also occurred.
|
@MorganMaohong have you tried using |
I have the same question after upgrading the Quarkus version from 3.13.2 to 3.17.3. |
Can't solve this problem. |
Hello, We are in JDK17, the default charset under windows for us is windows-1252. The problem no longer exists with a JDK higher than 17. Note that the default charset has been forced to UTF-8 since JDK18. It's a workaround for us. On inspection of the code, the problem occurred with version 4.X.X of smallerye-open-api. Class: io.smallrye.openapi.api.SmallRyeOpenAPI InputStream is transformed into InputStreamReader without specifying charset. It therefore inherits Charset.defaultcharset. In version 3.X.X, JSON/YAML was delivered via an InputStream. A fix could be to force the charset to UTF-8 and allow overloading via the properties file. FYI, we can't force default charset via JVM parameters either. |
@decha-n nice detective work. It certainly looks like something we need to fix in SmallRye OpenAPI. Would you be willing to create a small PR, given you did all the work? If not I can do it. Project is here: https://github.com/smallrye/smallrye-open-api/ . |
From what I can see, we would need to fix it in a few other areas too: (at least the one in |
What I'm not sure of though is if we should enforce UTF-8 or if we need a config there. @MikeEdgar would know better. |
I suggested forcing it to UTF-8 because I understand that this is already the case for properties files. This would be sufficient for French accented characters. It is not potentially sufficient for Asian characters. The most flexible solution would be to make the charset parameterizable |
I would recommend to do a first iteration using UTF-8 that we can easily backport. And then we could improve on it. But I will let @MikeEdgar chime in as he's the expert. |
I agree with using UTF-8 to start and enhancing later if necessary. Let me know if you'll be opening a PR @decha-n, otherwise I will do it. It looks like just two locations of non-test code need the encoding added ( |
I've only just seen your comment @MikeEdgar . I also see that the PR is already done . Thanks for the quick analysis and implementation of this fix. |
No problem, and thanks go to you for the analysis 👍 |
Description
I downloaded a template project from the official website, added the SmallRey OpenAPI extension, added the @tag annotation to the Rest class, and used Chinese. When I accessed /q/openapi, the response was in garbled format. I guessed that the project was in UTF-8 format. Finally, I tried all the places where I could set the encoding format to UTF-8, but it still didn't match the Chinese display.
Implementation ideas
If you have any implementation ideas, they can go here, however please note that all design change proposals should be posted to the Quarkus developer mailing list (or the corresponding Google Group; see the decisions process document for more information. However, it is normal for the REST request response result to be displayed in Chinese.
Implementation ideas
No response
The text was updated successfully, but these errors were encountered: