Merge pull request #206 from xoom/issue/modelsFromStatus

Issue/models from status - utilize the responseModel, if present
This commit is contained in:
Tony Tam 2014-06-16 17:03:17 -07:00
commit acff8229b3
13 changed files with 78 additions and 8 deletions

View File

@ -1,7 +1,6 @@
#!/bin/sh
SCRIPT="$0"
SCALA_RUNNER_VERSION=$(scala ./bin/Version.scala)
while [ -h "$SCRIPT" ] ; do
ls=`ls -ld "$SCRIPT"`
@ -19,6 +18,7 @@ if [ ! -d "${APP_DIR}" ]; then
fi
cd $APP_DIR
SCALA_RUNNER_VERSION=$(scala ./bin/Version.scala)
# if you've executed sbt assembly previously it will use that instead.
@ -26,7 +26,7 @@ export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/
ags="$@ samples/client/petstore/android-java/AndroidJavaPetstoreCodegen.scala http://petstore.swagger.wordnik.com/api/api-docs special-key"
if [ -f $APP_DIR/target/scala-$SCALA_RUNNER_VERSION/swagger-codegen.jar ]; then
scala -cp target/scala-$SCALA_RUNNER_VERSION/swagger-codegen.jar $ags
scala -cp $APP_DIR/target/scala-$SCALA_RUNNER_VERSION/swagger-codegen.jar $ags
else
echo "Please set scalaVersion := \"$SCALA_RUNNER_VERSION\" in build.sbt and run ./sbt assembly"
fi

View File

@ -1,7 +1,6 @@
#!/bin/sh
SCRIPT="$0"
SCALA_RUNNER_VERSION=$(scala ./bin/Version.scala)
while [ -h "$SCRIPT" ] ; do
ls=`ls -ld "$SCRIPT"`
@ -19,6 +18,7 @@ if [ ! -d "${APP_DIR}" ]; then
fi
cd $APP_DIR
SCALA_RUNNER_VERSION=$(scala ./bin/Version.scala)
# if you've executed sbt assembly previously it will use that instead.
@ -26,7 +26,7 @@ export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/
ags="$@ samples/client/petstore/java/JavaPetstoreCodegen.scala http://petstore.swagger.wordnik.com/api/api-docs special-key"
if [ -f $APP_DIR/target/scala-$SCALA_RUNNER_VERSION/swagger-codegen.jar ]; then
scala -cp target/scala-$SCALA_RUNNER_VERSION/swagger-codegen.jar $ags
scala -cp $APP_DIR/target/scala-$SCALA_RUNNER_VERSION/swagger-codegen.jar $ags
else
echo "Please set scalaVersion := \"$SCALA_RUNNER_VERSION\" in build.sbt and run ./sbt assembly"
fi

View File

@ -26,6 +26,8 @@ public class PetApi {
return basePath;
}
//error info- code: 400 reason: "Invalid ID supplied" model: <none>
//error info- code: 404 reason: "Pet not found" model: <none>
public Pet getPetById (Long petId) throws ApiException {
// verify required params are set
if(petId == null ) {
@ -57,6 +59,7 @@ public class PetApi {
}
}
}
//error info- code: 400 reason: "Invalid pet value" model: <none>
public void deletePet (String petId) throws ApiException {
// verify required params are set
if(petId == null ) {
@ -88,6 +91,7 @@ public class PetApi {
}
}
}
//error info- code: 400 reason: "Invalid tag value" model: <none>
public List<Pet> partialUpdate (String petId, Pet body) throws ApiException {
// verify required params are set
if(petId == null || body == null ) {
@ -119,6 +123,7 @@ public class PetApi {
}
}
}
//error info- code: 405 reason: "Invalid input" model: <none>
public void updatePetWithForm (String petId, String name, String status) throws ApiException {
// verify required params are set
if(petId == null ) {
@ -177,6 +182,7 @@ public class PetApi {
}
}
}
//error info- code: 405 reason: "Invalid input" model: <none>
public void addPet (Pet body) throws ApiException {
// verify required params are set
if(body == null ) {
@ -208,6 +214,9 @@ public class PetApi {
}
}
}
//error info- code: 400 reason: "Invalid ID supplied" model: <none>
//error info- code: 404 reason: "Pet not found" model: <none>
//error info- code: 405 reason: "Validation exception" model: <none>
public void updatePet (Pet body) throws ApiException {
// verify required params are set
if(body == null ) {
@ -239,6 +248,7 @@ public class PetApi {
}
}
}
//error info- code: 400 reason: "Invalid status value" model: <none>
public List<Pet> findPetsByStatus (String status) throws ApiException {
// verify required params are set
if(status == null ) {
@ -272,6 +282,7 @@ public class PetApi {
}
}
}
//error info- code: 400 reason: "Invalid tag value" model: <none>
public List<Pet> findPetsByTags (String tags) throws ApiException {
// verify required params are set
if(tags == null ) {

View File

@ -26,6 +26,8 @@ public class StoreApi {
return basePath;
}
//error info- code: 400 reason: "Invalid ID supplied" model: <none>
//error info- code: 404 reason: "Order not found" model: <none>
public Order getOrderById (String orderId) throws ApiException {
// verify required params are set
if(orderId == null ) {
@ -57,6 +59,8 @@ public class StoreApi {
}
}
}
//error info- code: 400 reason: "Invalid ID supplied" model: <none>
//error info- code: 404 reason: "Order not found" model: <none>
public void deleteOrder (String orderId) throws ApiException {
// verify required params are set
if(orderId == null ) {
@ -88,6 +92,7 @@ public class StoreApi {
}
}
}
//error info- code: 400 reason: "Invalid order" model: <none>
public void placeOrder (Order body) throws ApiException {
// verify required params are set
if(body == null ) {

View File

@ -26,6 +26,8 @@ public class UserApi {
return basePath;
}
//error info- code: 400 reason: "Invalid username supplied" model: <none>
//error info- code: 404 reason: "User not found" model: <none>
public void updateUser (String username, User body) throws ApiException {
// verify required params are set
if(username == null || body == null ) {
@ -57,6 +59,8 @@ public class UserApi {
}
}
}
//error info- code: 400 reason: "Invalid username supplied" model: <none>
//error info- code: 404 reason: "User not found" model: <none>
public void deleteUser (String username) throws ApiException {
// verify required params are set
if(username == null ) {
@ -88,6 +92,8 @@ public class UserApi {
}
}
}
//error info- code: 400 reason: "Invalid username supplied" model: <none>
//error info- code: 404 reason: "User not found" model: <none>
public User getUserByName (String username) throws ApiException {
// verify required params are set
if(username == null ) {
@ -119,6 +125,7 @@ public class UserApi {
}
}
}
//error info- code: 400 reason: "Invalid username and password combination" model: <none>
public String loginUser (String username, String password) throws ApiException {
// verify required params are set
if(username == null || password == null ) {

View File

@ -23,6 +23,8 @@ public class PetApi {
return basePath;
}
//error info- code: 400 reason: "Invalid ID supplied" model: <none>
//error info- code: 404 reason: "Pet not found" model: <none>
public Pet getPetById (Long petId) throws ApiException {
// verify required params are set
if(petId == null ) {
@ -58,6 +60,7 @@ public class PetApi {
}
}
}
//error info- code: 400 reason: "Invalid pet value" model: <none>
public void deletePet (String petId) throws ApiException {
// verify required params are set
if(petId == null ) {
@ -93,6 +96,7 @@ public class PetApi {
}
}
}
//error info- code: 400 reason: "Invalid tag value" model: <none>
public List<Pet> partialUpdate (String petId, Pet body) throws ApiException {
// verify required params are set
if(petId == null || body == null ) {
@ -128,6 +132,7 @@ public class PetApi {
}
}
}
//error info- code: 405 reason: "Invalid input" model: <none>
public void updatePetWithForm (String petId, String name, String status) throws ApiException {
// verify required params are set
if(petId == null ) {
@ -197,6 +202,7 @@ public class PetApi {
}
}
}
//error info- code: 405 reason: "Invalid input" model: <none>
public void addPet (Pet body) throws ApiException {
// verify required params are set
if(body == null ) {
@ -232,6 +238,9 @@ public class PetApi {
}
}
}
//error info- code: 400 reason: "Invalid ID supplied" model: <none>
//error info- code: 404 reason: "Pet not found" model: <none>
//error info- code: 405 reason: "Validation exception" model: <none>
public void updatePet (Pet body) throws ApiException {
// verify required params are set
if(body == null ) {
@ -267,6 +276,7 @@ public class PetApi {
}
}
}
//error info- code: 400 reason: "Invalid status value" model: <none>
public List<Pet> findPetsByStatus (String status) throws ApiException {
// verify required params are set
if(status == null ) {
@ -304,6 +314,7 @@ public class PetApi {
}
}
}
//error info- code: 400 reason: "Invalid tag value" model: <none>
public List<Pet> findPetsByTags (String tags) throws ApiException {
// verify required params are set
if(tags == null ) {

View File

@ -23,6 +23,8 @@ public class StoreApi {
return basePath;
}
//error info- code: 400 reason: "Invalid ID supplied" model: <none>
//error info- code: 404 reason: "Order not found" model: <none>
public Order getOrderById (String orderId) throws ApiException {
// verify required params are set
if(orderId == null ) {
@ -58,6 +60,8 @@ public class StoreApi {
}
}
}
//error info- code: 400 reason: "Invalid ID supplied" model: <none>
//error info- code: 404 reason: "Order not found" model: <none>
public void deleteOrder (String orderId) throws ApiException {
// verify required params are set
if(orderId == null ) {
@ -93,6 +97,7 @@ public class StoreApi {
}
}
}
//error info- code: 400 reason: "Invalid order" model: <none>
public void placeOrder (Order body) throws ApiException {
// verify required params are set
if(body == null ) {

View File

@ -23,6 +23,8 @@ public class UserApi {
return basePath;
}
//error info- code: 400 reason: "Invalid username supplied" model: <none>
//error info- code: 404 reason: "User not found" model: <none>
public void updateUser (String username, User body) throws ApiException {
// verify required params are set
if(username == null || body == null ) {
@ -58,6 +60,8 @@ public class UserApi {
}
}
}
//error info- code: 400 reason: "Invalid username supplied" model: <none>
//error info- code: 404 reason: "User not found" model: <none>
public void deleteUser (String username) throws ApiException {
// verify required params are set
if(username == null ) {
@ -93,6 +97,8 @@ public class UserApi {
}
}
}
//error info- code: 400 reason: "Invalid username supplied" model: <none>
//error info- code: 404 reason: "User not found" model: <none>
public User getUserByName (String username) throws ApiException {
// verify required params are set
if(username == null ) {
@ -128,6 +134,7 @@ public class UserApi {
}
}
}
//error info- code: 400 reason: "Invalid username and password combination" model: <none>
public String loginUser (String username, String password) throws ApiException {
// verify required params are set
if(username == null || password == null ) {

View File

@ -27,6 +27,10 @@ public class {{classname}} {
}
{{#operation}}
{{#errorList}} //error info- code: {{code}} reason: "{{reason}}" model: {{#responseModel}}{{responseModel}}
{{/responseModel}}{{^responseModel}}<none>
{{/responseModel}}
{{/errorList}}
public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}} {{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException {
{{#requiredParamCount}}
// verify required params are set

View File

@ -30,6 +30,10 @@ public class {{classname}} {
}
{{#operation}}
{{#errorList}} //error info- code: {{code}} reason: "{{reason}}" model: {{#responseModel}}{{responseModel}}
{{/responseModel}}{{^responseModel}}<none>
{{/responseModel}}
{{/errorList}}
public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}} {{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException {
{{#requiredParamCount}}
// verify required params are set

View File

@ -227,10 +227,12 @@ class Codegen(config: CodegenConfig) {
var bodyParamRequired: Option[String] = Some("true")
if (operation.responseMessages != null) {
operation.responseMessages.foreach(param => {
operation.responseMessages.foreach(param => {
val params = new HashMap[String, AnyRef]
params += "code" -> param.code.toString()
params += "reason" -> param.message
if (!param.responseModel.isEmpty)
params += "responseModel" -> param.responseModel
params += "hasMore" -> "true"
errorList += params
})

View File

@ -220,14 +220,28 @@ object SwaggerSerializers {
class ResponseMessageSerializer extends CustomSerializer[ResponseMessage](implicit formats => ({
case json =>
val responseClass = (json \ "responseModel") match {
case e: JObject => {
val inner = {
(e \ "items" \"type").extractOrElse({
(e \ "items" \ "$ref").extract[String]
})
}
Option("%s[%s]".format((e \ "type").extract[String], inner))
}
case _ => (json \ "responseModel").extractOpt[String]
}
ResponseMessage(
(json \ "code").extractOrElse(0),
(json \ "message").extractOrElse("")
(json \ "message").extractOrElse(""),
(json \ "responseModel").extractOpt[String]
)
}, {
case x: ResponseMessage =>
("code" -> x.code) ~
("message" -> x.message)
("message" -> x.message) ~
("responseModel" -> x.responseModel)
}
))

View File

@ -35,7 +35,7 @@ object CoreUtils {
def extractModelNames(op: Operation): Set[String] = {
// // POST, PUT, DELETE body
val modelNames = Set(op.responseClass) ++ op.parameters.filter(_.paramType == "body").map(_.dataType)
val modelNames = Set(op.responseClass) ++ op.parameters.filter(_.paramType == "body").map(_.dataType) ++ op.responseMessages.filter(!_.responseModel.isEmpty).map(_.responseModel.get)
modelNames map extractBasePartFromType
}