swagger-api / swagger-api/swagger-ui

Swagger UI - Bug in rendering models for static inner class

Open
#8,600 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
29k
Forks
9.3k
Avg merge
2d 23h
Merged PRs (30d)
25

Description

Q&A (please complete the following information)
  • OS: - macOS
  • Browser: chrome
  • Version: Version 112.0.5615.121 (Official Build) (arm64)
  • Method of installation:
  • Swagger-UI version: 3.0.0
  • Swagger/OpenAPI version: 2.1.7
Describe the bug you're encountering

I have a dummy Spring controller as follows. Also, defined API request parameters in the trailing section.

For some reason, the swagger UI renders format of SampleInputFirstAto even for createPerson2 : /person/second endpoint instead of rendering SampleInputSecondAto.

Technically, it seems to me like a bug. Is there any configuration that I can do to fix the swagger model rendering?

@RestController
@RequestMapping("/v1/experimental/test")
@RequiredArgsConstructor
@Slf4j
public class ExperimentalTestController {
    @PostMapping("/person/first")
    public void createPerson(@RequestBody SampleInputFirstAto inputFirstAto) {
        log.info("Received first person {}", inputFirstAto.toString());
    }

    @PostMapping("/person/second")
    public void createPerson2(@RequestBody SampleInputSecondAto inputSecondAtoAto) {
        log.info("Received second person {}", inputSecondAtoAto.toString());
    }
}

Model classes as follows


public class SampleInputFirstAto {

    private Person person;

    public Person getPerson() {
        return person;
    }

    public void setPerson(Person person) {
        this.person = person;
    }

    public static final class Person {
        String name;
        int age;
        String street;
        String city;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getAge() {
            return age;
        }

        public void setAge(int age) {
            this.age = age;
        }

        public String getStreet() {
            return street;
        }

        public void setStreet(String street) {
            this.street = street;
        }

        public String getCity() {
            return city;
        }

        public void setCity(String city) {
            this.city = city;
        }
    }
}


public class SampleInputSecondAto {

    private Person person;


    public Person getPerson() {
        return person;
    }

    public void setPerson(Person person) {
        this.person = person;
    }

    public static final class Person {
        String name;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }
}

To reproduce...

Steps to reproduce the behavior:
Use above code snippets into a spring boot application

Expected behavior
Screenshots
image image
Additional context or thoughts

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 model rendering with the provided Spring controller and compare the schemas shown for /person/first and /person/second. Trace the Swagger UI rendering path to determine why the static inner Person classes are treated as the same model, then verify that each endpoint displays its distinct request model.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, javascript, spring
Domain
api, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.