Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #1463
Closed
Open
Issue created Nov 16, 2018 by Administrator@rootContributor

ApiUtil class does not support UTF-8 response by default.

Created by: FutureGadget

Description

ApiUtil class does not support UTF-8 response by default.

openapi-generator version

3.3.0

OpenAPI declaration file content or url
Command line used for generation

openapi-generator generate -i {filename} -g spring

Steps to reproduce
  1. write a spec including utf-8 chars in the response example

  2. generate spiring code using the command openapi-generator generate -i {filename} -g spring

  3. Run the spinrg application and test the API generated by the openapi-generator by requesting through swagger-ui web page.

  4. The response will be 500 error, and you will get the Caused by: java.io.CharConversionException: Not an ISO 8859-1 character: [거] ( "거" is the utf-8 character(Korean) that caused this problem )

Related issues/PRs
Suggest a fix/enhancement

The generated code in the ApiUtil.java should be modified as follows: Before:

public static void setExampleResponse(NativeWebRequest req, String contentType, String example) {
        try {
            req.getNativeResponse(HttpServletResponse.class).addHeader("Content-Type", contentType);
            req.getNativeResponse(HttpServletResponse.class).getOutputStream().print(example);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

After:

public static void setExampleResponse(NativeWebRequest req, String contentType, String example) {
        try {
            req.getNativeResponse(HttpServletResponse.class).addHeader("Content-Type", contentType);
            req.getNativeResponse(HttpServletResponse.class).getWriter().print(example);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
Assignee
Assign to
Time tracking