swagger-api / swagger-api/swagger-codegen

Not getting defined properties when using additional properties

Open
#9,665 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

Hi
I have created apis using swagger openapi: 3.0.0
inside the response of one api i have object like this

      title: meta
      type: object
      required: 
        - sessionId
      properties:
        partialMessage:
          type: string
          example: Change operator to
        sessionId:
          $ref: '#/components/schemas/sesssionId'
      additionalProperties:
        type: string

Now when generating code it is Just creating MetaObject class extending HashMap like this

package code.niki.HelperLibs.actiontemplate.model;

import java.util.HashMap;
import java.util.Objects;

/**
 * MetaObject
 */
public class MetaObject extends HashMap<String, String> {

  @Override
  public boolean equals(java.lang.Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    return true;
  }

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

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("class MetaObject {\n");
    sb.append("    ").append(toIndentedString(super.toString())).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(java.lang.Object o) {
    if (o == null) {
      return "null";
    }
    return o.toString().replace("\n", "\n    ");
  }

  public MetaObject setSessionId(String sessionId){
    this.put("sessionId", sessionId);
    return this;
  }
  public MetaObject setPartialMessage(String partialMessage){
    this.put("partialMessage", partialMessage);
    return this;
  }
  public MetaObject setPromocode(String promocode){
    this.put("promocode", promocode);
    return this;
  }
  public MetaObject setContent(String content){
    this.put("content", content);
    return this;
  }
  public MetaObject setGetUrl(String getUrl){
    this.put("getUrl", getUrl);
    return this;
  }
  public MetaObject setOrderDetail(String orderDetail){
    this.put("orderDetail", orderDetail);
    return this;
  }
}

instead i am expecting something like setter and getter like below getting for existing properties which is defined

public MetaObject setSessionId(String sessionId){
    this.put("sessionId", sessionId);
    return this;
  }

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 issue with the OpenAPI schema and generated Java MetaObject shown in the report, then inspect the Java model-generation templates or entry points responsible for additionalProperties. Done means the generated class retains map behavior while also exposing accessors for the explicitly defined properties, including sessionId and partialMessage.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
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.