Code Monkey home page Code Monkey logo

Comments (13)

fehguy avatar fehguy commented on May 8, 2024

Looks lik your array doesn't specify the type of object in it. If made a string, you'll get a valid spec:

  "models": {
    "Author": {
      "id": "Author",
      "properties": {
        "name": {
          "type": "string"
        },
        "email": {
          "type": "string"
        },
        "age": {
          "type": "int"
        },
        "books": {
          "type": "Array",
          "items":{
            "type":"string"
          }
        }
      }
    }
  }

Will fix the validation step so you get a proper error.

from swagger-codegen.

fehguy avatar fehguy commented on May 8, 2024

OK pushed a fix to do a null check on the item if it's an array. I found three other issues in your model, namely:

  • the DELETE method must return void
  • the PUT method must return void
  • the POST method is returning an Array[Author] not Array

The entire authors.json file is here:

{
  "apiVersion": "1",
  "swaggerVersion": "1.1",
  "basePath": "http://localhost/restler3.dev/raw/swagger",
  "apis": [
    {
      "path": "/authors.{format}/{id}",
      "description": "API to list, modify Authors of the Restler",
      "operations": [
        {
          "httpMethod": "GET",
          "nickname": "authorsid",
          "responseClass": "Author",
          "parameters": [
            {
              "name": "id",
              "description": "Author ID . ",
              "paramType": "path",
              "required": true,
              "allowMultiple": false,
              "dataType": "string"
            }
          ],
          "summary": "Get Author for the specified Author ID",
          "notes": "Passing a valid author id, will result in getting details (name, email, author id) of the specific Author.",
          "errorResponses": [
            {
              "reason": "one or more of required fields missing",
              "code": 417
            },
            {
              "reason": "Author not found",
              "code": 404
            }
          ]
        }
      ]
    },
    {
      "path": "/authors.{format}",
      "description": "API to list, modify Authors of the Restler",
      "operations": [
        {
          "httpMethod": "POST",
          "nickname": "authors",
          "responseClass": "Array[Author]",
          "parameters": [
            {
              "name": "request_data",
              "description": "",
              "paramType": "path",
              "required": true,
              "allowMultiple": false,
              "dataType": "string"
            }
          ],
          "summary": "Create new Author",
          "notes": "",
          "errorResponses": [
            {
              "reason": "one or more of required fields missing",
              "code": 417
            }
          ]
        }
      ]
    },
    {
      "path": "/authors.{format}/{id}",
      "description": "API to list, modify Authors of the Restler",
      "operations": [
        {
          "httpMethod": "PUT",
          "nickname": "authorsid",
          "responseClass": "void",
          "parameters": [
            {
              "name": "id",
              "description": "Author ID . ",
              "paramType": "path",
              "required": true,
              "allowMultiple": false,
              "dataType": "string"
            },
            {
              "name": "request_data",
              "description": "",
              "paramType": "path",
              "required": true,
              "allowMultiple": false,
              "dataType": "string"
            }
          ],
          "summary": "Update Author information",
          "notes": "",
          "errorResponses": [

          ]
        }
      ]
    },
    {
      "path": "/authors.{format}/something/{id}",
      "description": "API to list, modify Authors of the Restler",
      "operations": [
        {
          "httpMethod": "DELETE",
          "nickname": "authorssomethingid",
          "responseClass": "void",
          "parameters": [
            {
              "name": "id",
              "description": "Author ID . ",
              "paramType": "path",
              "required": true,
              "allowMultiple": false,
              "dataType": "string"
            }
          ],
          "summary": "Delete Author by ID",
          "notes": "",
          "errorResponses": [

          ]
        }
      ]
    }
  ],
  "resourcePath": "/authors",
  "models": {
    "Author": {
      "id": "Author",
      "properties": {
        "name": {
          "type": "string"
        },
        "email": {
          "type": "string"
        },
        "age": {
          "type": "int"
        },
        "books": {
          "items":{
            "type":"string"
          },
          "type": "Array"
        }
      }
    }
  }
}

Thanks!

from swagger-codegen.

 avatar commented on May 8, 2024

Thanks, I have fixed them all and I'm able to run the tests with zero issues

from swagger-codegen.

fehguy avatar fehguy commented on May 8, 2024

sweet!

from swagger-codegen.

venkata-denali avatar venkata-denali commented on May 8, 2024

Hi, I have a problem with model schema. It is not able to display the type for embedded class. For suppose, In one response body class I have is user defined class and it has List like objects. In swagger model schema it presents it as Array[any]. Is there is way specify the exact type.

from swagger-codegen.

fehguy avatar fehguy commented on May 8, 2024

Can you share the class itself that you're trying to represent? What version of codegen? Is it java or scala code?

from swagger-codegen.

venkata-denali avatar venkata-denali commented on May 8, 2024

I am using code generation for java. This is my pojo class.

@XmlRootElement(name="SubscriptionDetails")
public class SubscriptionDetails implements Serializable{

public static enum PROTOCOL {SMS,EMAIL,FAX};



private UserDetails subscriber;

private List<SubscriptionCriteria> subscriptionCriterias;

private TimingDetails alertTimings;

private Boolean active;

private List<PROTOCOL> protocols = new ArrayList<SubscriptionDetails.PROTOCOL>();

private List<NotificationPreference> notificationPreferences;



/**
 * @param alertTypeId the alertTypeId to set
 */
public void setAlertTypeId(Integer alertTypeId) {
    this.alertTypeId = alertTypeId;

}

/**
 * @return the alertTypeId
 */
public Integer getAlertTypeId() {
    return alertTypeId;
}


/**
 * @param subscriptionId the subscriptionId to set
 */
public void setSubscriptionId(Integer subscriptionId) {
    this.subscriptionId = subscriptionId;

}

/**
 * @return the subscriptionId
 */
public Integer getSubscriptionId() {
    return subscriptionId;
}

/**
 * @param active the active to set
 */
public void setActive(Boolean active) {
    this.active = active;

}

/**
 * @return the active
 */
public Boolean getActive() {
    return active;
}

/**
 * @param protocols the protocols to set
 */
public void setProtocols(List<PROTOCOL> protocols) {
    this.protocols = protocols;

}

/**
 * @return the protocols
 */
public List<PROTOCOL> getProtocols() {
    return protocols;
}

/**
 * @param alertTimings the alertTimings to set
 */
public void setAlertTimings(TimingDetails alertTimings) {
    this.alertTimings = alertTimings;
}

/**
 * @return the alertTimings
 */
public TimingDetails getAlertTimings() {
    return alertTimings;
}



/**
 * @return the notificationPreferences
 */
public List<NotificationPreference> getNotificationPreferences() {
    return notificationPreferences;
}

/**
 * @param notificationPreferences the notificationPreferences to set
 */
public void setNotificationPreferences(
        List<NotificationPreference> notificationPreferences) {
    this.notificationPreferences = notificationPreferences;
}



/**
 * @param criteria the criteria to set
 */
public void setCriteria(String criteria) {
    this.criteria = criteria;
}

/**
 * @return the criteria
 */
public String getCriteria() {
    return criteria;
}

/**
 * @param emailIds the emailIds to set
 */
public void setEmailIds(String emailIds) {
    this.emailIds = emailIds;
}

/**
 * @return the emailIds
 */
public String getEmailIds() {
    return emailIds;
}

/**
 * @param mobileNos the mobileNos to set
 */
public void setMobileNos(String mobileNos) {
    this.mobileNos = mobileNos;
}

/**
 * @return the mobileNos
 */
public String getMobileNos() {
    return mobileNos;
}

/**
 * @param alertType the alertType to set
 */
public void setAlertType(String alertType) {
    this.alertType = alertType;
}

/**
 * @return the alertType
 */
public String getAlertType() {
    return alertType;
}

/**
 * @param createdDate the createdDate to set
 */
public void setCreatedDate(Date createdDate) {
    this.createdDate = createdDate;
}

/**
 * @return the createdDate
 */
public Date getCreatedDate() {
    return createdDate;
}

/**
 * @param updatedDate the updatedDate to set
 */
public void setUpdatedDate(Date updatedDate) {
    this.updatedDate = updatedDate;
}

/**
 * @return the updatedDate
 */
public Date getUpdatedDate() {
    return updatedDate;
}

/**
 * @return the protocolTypes
 */
public String getProtocolTypes() {
    return protocolTypes;
}

/**
 * @param protocolTypes the protocolTypes to set
 */
public void setProtocolTypes(String protocolTypes) {
    this.protocolTypes = protocolTypes;
}

/**
 * @param subscriptionCriterias the subscriptionCriterias to set
 */
public void setSubscriptionCriterias(List<SubscriptionCriteria> subscriptionCriterias) {
    this.subscriptionCriterias = subscriptionCriterias;
}

/**
 * @return the subscriptionCriterias
 */
public List<SubscriptionCriteria> getSubscriptionCriterias() {
    return subscriptionCriterias;
}

/**
 * @param subscriber the subscriber to set
 */
public void setSubscriber(UserDetails subscriber) {
    this.subscriber = subscriber;
}

/**
 * @return the subscriber
 */
public UserDetails getSubscriber() {
    return subscriber;
}

}

The web service class is

@OverRide
@put
@path("/subscriptions")
@consumes({"application/json","application/xml"})
@produces({"application/json","application/xml"})
@ApiOperation(value = "Updates an existing subscription", notes = "Updates the subscription details")
@ApiErrors(value = { @ApiError(code = 400, reason = "Subscription details are required") })
public Response updateSubscription(@ApiParam(value = "SubscriptionDetails that needs to be fetched", required = true) SubscriptionDetails subscription) throws DataRequiredException{
//Code
}

from swagger-codegen.

venkata-denali avatar venkata-denali commented on May 8, 2024

This is model schema was generated by swagger ui

SubscriptionDetails
class SubscriptionDetails(alertTypeId: int, criteria: string, updatedDate: Date, emailIds: string, protocols: Array[any], alertType: string, subscriptionId: int, subscriptionCriterias: Array[any], mobileNos: string, active: boolean, alertTimings: TimingDetails, notificationPreferences: Array[any], subscriber: UserDetails, createdDate: Date, protocolTypes: string)

Please note Array[any] notation for list typed property.

from swagger-codegen.

fehguy avatar fehguy commented on May 8, 2024

Can you confirm you're using swagger 1.2.4?

from swagger-codegen.

venkata-denali avatar venkata-denali commented on May 8, 2024

The maven repository for latest swagger-core_2.9.1 is 1.2.3.

This my dependency set

com.wordnik swagger-core_2.9.1 1.2.3 com.wordnik swagger-jaxrs_2.9.1 1.2.3
<dependency>
 <groupId>org.reflections</groupId>
 <artifactId>reflections</artifactId>
 <version>0.9.8</version>
<dependency>
 <groupId>org.scala-lang</groupId>
 <artifactId>scala-library</artifactId>
 <version>2.9.1-1</version>
org.scalatest scalatest_2.9.1 1.6.1 test org.slf4j log4j-over-slf4j 1.6.3 runtime org.slf4j jcl-over-slf4j 1.6.3 org.slf4j jul-to-slf4j 1.6.3 ch.qos.logback logback-classic 1.0.9 runtime

from swagger-codegen.

venkata-denali avatar venkata-denali commented on May 8, 2024

But 1.2.4 is not available

from swagger-codegen.

fehguy avatar fehguy commented on May 8, 2024

Hi, there are a number of models missing from your sample, and not all the class variables are there, so without reproducing all of it, it's impossible to test.

I just ensured 1.2.4 was pushed to maven central, so if you can try that again shortly, or try 1.2.4-SNAPSHOT (in sonatype oss snapshots) I'd like to see if the issue is fixed with some model recursion fixes from that version.

from swagger-codegen.

venkata-denali avatar venkata-denali commented on May 8, 2024

This is one of missing models. Please remove all the other models from pojo. And consider this only.

@XmlRootElement(name="SubscriptionCriteria")
public class SubscriptionCriteria {

private String paramName;
private String paramValue;
private String paramDisplayValue;
/**
 * @param paramName the paramName to set
 */
public void setParamName(String paramName) {
    this.paramName = paramName;
}
/**
 * @return the paramName
 */
public String getParamName() {
    return paramName;
}
/**
 * @param paramValue the paramValue to set
 */
public void setParamValue(String paramValue) {
    this.paramValue = paramValue;
}
/**
 * @return the paramValue
 */
public String getParamValue() {
    return paramValue;
}
/**
 * @param paramDisplayValue the paramDisplayValue to set
 */
public void setParamDisplayValue(String paramDisplayValue) {
    this.paramDisplayValue = paramDisplayValue;
}
/**
 * @return the paramDisplayValue
 */
public String getParamDisplayValue() {
    return paramDisplayValue;
}

}

Thanks , 1.2.4-SNAPSHOT is look like not available. I am getting jar not available error in pom. I will wait for 1.2.4 and will see if this issue is fixed. Thank you very much.

from swagger-codegen.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.