swagger-api / swagger-api/swagger-codegen

Incorrect schema gen for nested objects

Open
#10,574 0 comments 0 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

SpringDoc 1.5
Swagger-core 2.1.5
swagger-ui version to 3.36.2

Top level object my rest API returns:

@Schema(name="PersonB")
public class PersonBDto {

	@Schema(example="Emil Eifrem")
	private String name;
	@Schema(example="1978")
	private Integer born;
	private List<MovieBDto> movies;

MovieBDto:

	@Schema(example="The Matrix")
	private String title;
	@Schema(example="Welcome to the Real World")
	private String tagline;
	@Schema(example="1999")
	private Integer yearReleased;
	@Schema(example="[ \"Emil\" ]")
	private List<String> roles;

Generated Json for PersonB:

      "PersonB": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "example": "Emil Eifrem"
          },
          "born": {
            "type": "integer",
            "format": "int32",
            "example": 1978
          },
          "movies": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/MovieB" }
          }
        }

Generated json for MovieB:

      "MovieB": {
        "type": "object",
        "properties": {
          "title": {
            "type": "string",
            "example": "The Matrix"
          },
          "tagline": {
            "type": "string",
            "example": "Welcome to the Real World"
          },
          "yearReleased": {
            "type": "integer",
            "format": "int32",
            "example": 1999
          }
        }

As you can see, it completely left out roles in MovieB. I can fake it on the sample response by adding a @Schema on PersonB an embedding json, but that still won't add it back into the schema. I have a MovieA and PersonA of a slightly different structure, and it works in there, just not in this particular layout.

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 schema generation with the supplied PersonBDto and MovieBDto classes using SpringDoc 1.5 and swagger-core 2.1.5, then trace how the nested movies collection is converted into the MovieB schema. Done means the generated MovieB schema includes the roles array and its example rather than omitting the property.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.