Search code examples
swagger-codegenswaggerhub

Create hashmap using swaggerhub


My requirement is to create a dynamic set of fields so that they can be contained in a hashmap for further process of restful request. As suggested in link :

  MyBean:
    type: object
    additionalProperties: true

The code that is generated is equals, hashCode & toString methods which are not populated with any type of fields.

public class MyBean {

  @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();
  }


  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("class MyBean {\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    ");
  }

Will the dynamic input will be contained ? How can i create a hashmap for this purpose ?


Solution

  • I fixed it using :

    MyBean:
        type: object
        additionalProperties:
          type: object
    

    which is HashMap<String, Object> extended by my class. Found reference at link.