mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-08 03:18:53 +00:00
Merge branch 'master' of github.com:wordnik/swagger-codegen
This commit is contained in:
commit
b86eb53256
@ -49,10 +49,13 @@ class SwaggerSpecValidator(private val doc: ResourceListing,
|
|||||||
apis.foreach(api => {
|
apis.foreach(api => {
|
||||||
fixSubDoc(api)
|
fixSubDoc(api)
|
||||||
|
|
||||||
if (api.models != null) {
|
api.models match {
|
||||||
fixReturnModels(api.models.toMap, apis)
|
case Some(models) => {
|
||||||
fixInputDataTypes(api.models.toMap, apis)
|
fixReturnModels(models.toMap, apis)
|
||||||
fixModels(api.models.toMap)
|
fixInputDataTypes(models.toMap, apis)
|
||||||
|
fixModels(models.toMap)
|
||||||
|
}
|
||||||
|
case None => LOGGER.warning("no models found for listing " + api.basePath)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -29,7 +29,9 @@ object CoreUtils {
|
|||||||
val modelObjects = new HashMap[String, Model]
|
val modelObjects = new HashMap[String, Model]
|
||||||
apis.foreach(api => {
|
apis.foreach(api => {
|
||||||
for ((nm, model) <- extractApiModels(api)) modelObjects += nm -> model
|
for ((nm, model) <- extractApiModels(api)) modelObjects += nm -> model
|
||||||
api.models.foreach(model => modelObjects += model._1 -> model._2)
|
if(api.models.isDefined) {
|
||||||
|
api.models.get.foreach(model => modelObjects += model._1 -> model._2)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
modelObjects.toMap
|
modelObjects.toMap
|
||||||
}
|
}
|
||||||
@ -65,8 +67,9 @@ object CoreUtils {
|
|||||||
.foreach(p => modelNames += p.dataType)
|
.foreach(p => modelNames += p.dataType)
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
for ((name, m) <- sd.models)
|
if(sd.models.isDefined)
|
||||||
modelObjects += name -> m
|
for ((name, m) <- sd.models.get)
|
||||||
|
modelObjects += name -> m
|
||||||
|
|
||||||
// extract all base model names, strip away Containers like List[] and primitives
|
// extract all base model names, strip away Containers like List[] and primitives
|
||||||
val baseNames = (for (modelName <- (modelNames.toList filterNot primitives.contains))
|
val baseNames = (for (modelName <- (modelNames.toList filterNot primitives.contains))
|
||||||
@ -120,4 +123,4 @@ object CoreUtils {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ object SwaggerSerializers {
|
|||||||
""
|
""
|
||||||
}),
|
}),
|
||||||
(json \ "apis").extract[List[ApiDescription]],
|
(json \ "apis").extract[List[ApiDescription]],
|
||||||
(json \ "models").extract[Map[String, Model]]
|
(json \ "models").extractOpt[Map[String, Model]]
|
||||||
)
|
)
|
||||||
}, {
|
}, {
|
||||||
case x: ApiListing =>
|
case x: ApiListing =>
|
||||||
@ -391,4 +391,4 @@ object SwaggerSerializers {
|
|||||||
("valueType" -> "RANGE") ~ ("min" -> min) ~ ("max" -> max)
|
("valueType" -> "RANGE") ~ ("min" -> min) ~ ("max" -> max)
|
||||||
}
|
}
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ case class ApiListing (
|
|||||||
basePath: String,
|
basePath: String,
|
||||||
var resourcePath: String,
|
var resourcePath: String,
|
||||||
apis: List[ApiDescription] = List(),
|
apis: List[ApiDescription] = List(),
|
||||||
models: Map[String, Model] = Map())
|
models: Option[Map[String, Model]] = None)
|
||||||
|
|
||||||
case class ApiDescription (
|
case class ApiDescription (
|
||||||
path: String,
|
path: String,
|
||||||
|
@ -57,7 +57,8 @@ class SwaggerModelTest extends FlatSpec with ShouldMatchers {
|
|||||||
apiListing.basePath should be ("http://petstore.swagger.wordnik.com/api")
|
apiListing.basePath should be ("http://petstore.swagger.wordnik.com/api")
|
||||||
apiListing.resourcePath should be ("/pet")
|
apiListing.resourcePath should be ("/pet")
|
||||||
apiListing.apis.size should be (4)
|
apiListing.apis.size should be (4)
|
||||||
apiListing.models.size should be (3)
|
apiListing.models.isDefined should be (true)
|
||||||
|
apiListing.models.get.size should be (3)
|
||||||
|
|
||||||
val apiMap = apiListing.apis.map(api => (api.path, api)).toMap
|
val apiMap = apiListing.apis.map(api => (api.path, api)).toMap
|
||||||
val petBaseApi = apiMap("/pet.{format}/{petId}")
|
val petBaseApi = apiMap("/pet.{format}/{petId}")
|
||||||
@ -115,7 +116,9 @@ class SwaggerModelTest extends FlatSpec with ShouldMatchers {
|
|||||||
val json = Source.fromFile("src/test/resources/petstore/pet.json").mkString
|
val json = Source.fromFile("src/test/resources/petstore/pet.json").mkString
|
||||||
val apiListing = parse(json).extract[ApiListing]
|
val apiListing = parse(json).extract[ApiListing]
|
||||||
|
|
||||||
val models = apiListing.models
|
val modelsOpt = apiListing.models
|
||||||
|
modelsOpt.isDefined should be (true)
|
||||||
|
val models = modelsOpt.get
|
||||||
models.size should be (3)
|
models.size should be (3)
|
||||||
val pet = models("Pet")
|
val pet = models("Pet")
|
||||||
|
|
||||||
@ -134,7 +137,9 @@ class SwaggerModelTest extends FlatSpec with ShouldMatchers {
|
|||||||
val json = Source.fromFile("src/test/resources/petstore/pet.json").mkString
|
val json = Source.fromFile("src/test/resources/petstore/pet.json").mkString
|
||||||
val apiListing = parse(json).extract[ApiListing]
|
val apiListing = parse(json).extract[ApiListing]
|
||||||
|
|
||||||
val models = apiListing.models
|
val modelsOpt = apiListing.models
|
||||||
|
modelsOpt.isDefined should be (true)
|
||||||
|
val models = modelsOpt.get
|
||||||
models.size should be (3)
|
models.size should be (3)
|
||||||
|
|
||||||
val pet = models("Pet")
|
val pet = models("Pet")
|
||||||
@ -162,4 +167,4 @@ class SwaggerModelTest extends FlatSpec with ShouldMatchers {
|
|||||||
allowableValues.valueType should be ("LIST")
|
allowableValues.valueType should be ("LIST")
|
||||||
(allowableValues.values.toSet & Set("available", "pending", "sold")).size should be (3)
|
(allowableValues.values.toSet & Set("available", "pending", "sold")).size should be (3)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user