swagger-api / swagger-api/swagger-codegen

[JAVA SPRING] error: constant string too long

Open
#9,055 0 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

The swagger-codegen generates for spring server an interface where there is a too long string constant based on the swagger definition.

...
default ResponseEntity<List<Customer>> customerFind(@ApiParam(value = "") @Valid @RequestParam(value = "relatedPartyId", required = false) String relatedPartyId,@ApiParam(value = "") @Valid @RequestParam(value = "relatedPartyRole", required = false) String relatedPartyRole,@ApiParam(value = "") @Valid @RequestParam(value = "fields", required = false) String fields,@ApiParam(value = "") @Valid @RequestParam(value = "query", required = false) String query,@ApiParam(value = "Defines page") @Valid @RequestParam(value = "page", required = false) BigDecimal page,@ApiParam(value = "Limits the number of results for paging") @Valid @RequestParam(value = "size", required = false) BigDecimal size,@ApiParam(value = "Entity ordering") @Valid @RequestParam(value = "sort", required = false) String sort) {
        if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) {
            if (getAcceptHeader().get().contains("application/json")) {
                try {
                    return new ResponseEntity<>(getObjectMapper().get().readValue("[ {  \"characteristics\" : [ .................... too long string constant

It ends with compilation error:

...\build\generated-sources\swagger\src\main\java\sk\telekom\oneapp\hal\api\CustomersApi.java:71: error: constant string too long
                    return new ResponseEntity<>(getObjectMapper().get().readValue("[ {  \"charact
Swagger-codegen version

2.4.0

Swagger declaration file content or url

https://gist.github.com/drej1/418d1dfa7924471a664fcd4e6fb6b3d2

Command line used for generation

used created gradle task using swagger-codegen with:

config.setLang("spring")
config.setAdditionalProperties([
    "modelPackage"     : modelPackage,
    "apiPackage"       : apiPackage,
    "java8"            : true,
    "serializableModel": true,
    "interfaceOnly"    : true
])
Steps to reproduce
  1. generate spring API server interfaces for yaml with a really complex type definition
Suggest a fix/enhancement

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the generation using the Gradle configuration and Swagger declaration linked in the issue, then inspect the Spring generator path that produces generated-sources/swagger/.../CustomersApi.java. Confirm the generated Java fails with a constant-string-too-long error, and consider the issue done when the same complex definition generates Spring interfaces that compile successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
api, backend, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.