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

[BUG] [JAVA] allOf object class created, but not used for adding to collection. (started with 7.10.0) #20323

Open
6 tasks
sturose opened this issue Dec 13, 2024 · 0 comments

Comments

@sturose
Copy link

sturose commented Dec 13, 2024

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

addItem can use wrong class in the call of allOf.

openapi-generator version

7.10.0, regression from 7.9.0

OpenAPI declaration file content or url
openapi: "3.0.0"
info:
  version: 1.0.0
  title: Swagger Petstore
  license:
    name: MIT
servers:
  - url: http://petstore.swagger.io/v1
paths:
  /pets:
    get:
      summary: List all pets
      operationId: listPets
      tags:
        - pets
      parameters:
        - name: limit
          in: query
          description: How many items to return at one time (max 100)
          required: false
          schema:
            type: integer
            format: int32
      responses:
        200:
          description: An paged array of pets
          headers:
            x-next:
              description: A link to the next page of responses
              schema:
                type: string
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/PetCollections"
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
    post:
      summary: Create a pet
      operationId: createPets
      tags:
        - pets
      responses:
        201:
          description: Null response
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
  /pets/{petId}:
    get:
      summary: Info for a specific pet
      operationId: showPetById
      tags:
        - pets
      parameters:
        - name: petId
          in: path
          required: true
          description: The id of the pet to retrieve
          schema:
            type: string
      responses:
        200:
          description: Expected response to a valid request
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Pet"
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
components:
  schemas:
    Pet:
      type: object
      required:
        - id
        - name
      properties:
        id:
          type: integer
          format: int64
        name:
          type: string
        tag:
          type: string
    HappyPet:
      allOf:
        - $ref: '#/components/schemas/Pet'
      description: |- 
        A Happy Pet.  It has all the same things as a regular Pet.
        Why is this an object instead of just a Pet?  Well, there's reasons.  Probably bad ones.  But reasons.

    Pets:
      type: array
      items:
        $ref: "#/components/schemas/Pet"
    HappyPets:
      type: array
      items:
        $ref: "#/components/schemas/HappyPet"

    PetCollections:
      type: object
      properties:
        happyPets:
          $ref: "#/components/schemas/HappyPets"

    Error:
      required:
        - code
        - message
      properties:
        code:
          type: integer
          format: int32
        message:
          type: string
Generation Details
package com.ehi.rental.booking.reservation.api.model;

import java.net.URI;
import java.util.Objects;
import com.ehi.rental.booking.reservation.api.model.PetDto;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonTypeName;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.io.Serializable;
import java.time.OffsetDateTime;
import jakarta.validation.Valid;
import jakarta.validation.constraints.*;


import java.util.*;
import jakarta.annotation.Generated;

/**
 * PetCollectionsDto
 */

@JsonTypeName("PetCollections")
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2024-12-13T15:33:07.204092900-06:00[America/Chicago]", comments = "Generator version: 7.10.0")
public class PetCollections implements Serializable {

  private static final long serialVersionUID = 1L;

  @Valid
  private List<HappyPetDto> happyPets;

  public PetCollectionsDto happyPets(List<HappyPetDto> happyPets) {
    this.happyPets = happyPets;
    return this;
  }

  public PetCollectionsDto addHappyPetsItem(PetDto happyPetsItem) {
    if (this.happyPets == null) {
      this.happyPets = new ArrayList<>();
    }
    this.happyPets.add(happyPetsItem);
    return this;
  }

  /**
   * Get happyPets
   * @return happyPets
   */
  @Valid 
  @JsonProperty("happyPets")
  public List<HappyPetDto> getHappyPets() {
    return happyPets;
  }

  public void setHappyPets(List<HappyPetDto> happyPets) {
    this.happyPets = happyPets;
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    PetCollectionsDto petCollections = (PetCollectionsDto) o;
    return Objects.equals(this.happyPets, petCollections.happyPets);
  }

  @Override
  public int hashCode() {
    return Objects.hash(happyPets);
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("class PetCollectionsDto {\n");
    sb.append("    happyPets: ").append(toIndentedString(happyPets)).append("\n");
    sb.append("}");
    return sb.toString();
  }

  /**
   * Convert the given object to string with each line indented by 4 spaces
   * (except the first line).
   */
  private String toIndentedString(Object o) {
    if (o == null) {
      return "null";
    }
    return o.toString().replace("\n", "\n    ");
  }
}

addHappyPetsItem takes in the wrong class as a parameter. (PetDto instead of HappyPetDto)

Steps to reproduce
Related issues/PRs
Suggest a fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant