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

When using an IDE or Maven to generate code, you may encounter a serialization error with the string "application/json; charset\u003dutf-8". This issue occurs because the \u003d sequence is not properly escaped, causing errors when generating code for other languages using open-generator. #232

Closed
inernoro opened this issue Apr 15, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@inernoro
Copy link

inernoro commented Apr 15, 2022

Your Environment

  • smart-doc version: 2.4.2
  • plugin version (e.g. smart-doc-maven-plugin or smart-doc-gradle-plugin): small:openapi
  • build tool version(maven or gradle): mvn 3.5.2 and java 1.8.0_41
  • spring version: 2.6.3
  • operating system: Windows 11
  • idea version: 2021.3.3
  • I also have swagger installed, but I don't think it's related to this issue. I have checked the decoding of HTML in your previous issues, and it seems to be caused by Gson. I have searched through the entire site and issues before deciding to submit this one.
  • One thing to note is that I have set -Dxxx utf-8, which didn't work.

Expected Behavior

The \u003d should be converted to =

Current Behavior

The "requestBody" section contains "\u003d" in the generated openapi.

{
  "requestBody": {
    "content": {
      "application/json; charset\u003dutf-8": {
        "schema": {
          "$ref": "#/components/schemas/_sirius_application_interface_relationrequest"
        },

Steps to Reproduce

  1. Use either IDE or Maven to generate the code, and you will see "\u003d" in the paths.

Context

This issue causes the openapi code generator to throw errors.

Other Notes

1. I added utf8 in the mvn configuration.

2. smart-doc.json (local, no privacy concerns)

{
  "outPath": "api",
  "serverUrl": "http://192.168.5.36:7878",
  "isStrict": false,
  "projectName": "sirius",
  "appToken": "1d577ec5d60648afb65daadb8718eea9",
  "openUrl": "http://192.168.5.166:7700/api",
  "debugEnvName": "测试环境",
  "replace": true,
  "debugEnvUrl": "http://192.168.5.36:7878",
  "responseBodyAdvice": {
    "className": "com.miduonet.sirius.classlibrary.basiccomponents.ResultData"
  }
}

pom.xml configuration

<plugin>
  <groupId>com.github.shalousun</groupId>
  <artifactId>smart-doc-maven-plugin</artifactId>
  <version>2.4.2</version>
  <configuration>
    <!--Specify the configuration file used to generate the document, the configuration file is placed in its own project-->
    <configFile>./src/main/resources/smart-doc.json</configFile>
    <!--Specify the project name-->
    <projectName>Test</projectName>
    <includes>
      <include>com.alibaba:fastjson</include>
    </includes>
  </configuration>
  <executions>
    <execution>
      <!--If you do not need to start smart-doc when compiling, comment out the phase-->
      <phase>compile</phase>
      <goals>
        <!--smart-doc provides goals such as html, openapi, markdown, etc., which can be configured as needed-->
      </goals>
    </execution>
  </executions>
</plugin>

Issue

This issue causes the openapi generator to produce errors when generating code.

java -jar openapi-generator-cli.jar generate -g go -i http://192.168.5.36:8080/openapi.json -o D:\code\temp
@inernoro inernoro added the bug Something isn't working label Apr 15, 2022
@shalousun shalousun changed the title 使用ide或mvn生成都会产生"application/json; charset\u003dutf-8" 中间会包含 \u003d 序列化错误的代码,导致open-generator生成其他语言直接报错 When using an IDE or Maven to generate code, you may encounter a serialization error with the string "application/json; charset\u003dutf-8". This issue occurs because the \u003d sequence is not properly escaped, causing errors when generating code for other languages using open-generator. Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant