mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-07 19:08:52 +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 => {
|
||||
fixSubDoc(api)
|
||||
|
||||
if (api.models != null) {
|
||||
fixReturnModels(api.models.toMap, apis)
|
||||
fixInputDataTypes(api.models.toMap, apis)
|
||||
fixModels(api.models.toMap)
|
||||
api.models match {
|
||||
case Some(models) => {
|
||||
fixReturnModels(models.toMap, apis)
|
||||
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]
|
||||
apis.foreach(api => {
|
||||
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
|
||||
}
|
||||
@ -65,8 +67,9 @@ object CoreUtils {
|
||||
.foreach(p => modelNames += p.dataType)
|
||||
})
|
||||
)
|
||||
for ((name, m) <- sd.models)
|
||||
modelObjects += name -> m
|
||||
if(sd.models.isDefined)
|
||||
for ((name, m) <- sd.models.get)
|
||||
modelObjects += name -> m
|
||||
|
||||
// extract all base model names, strip away Containers like List[] and primitives
|
||||
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 \ "models").extract[Map[String, Model]]
|
||||
(json \ "models").extractOpt[Map[String, Model]]
|
||||
)
|
||||
}, {
|
||||
case x: ApiListing =>
|
||||
@ -391,4 +391,4 @@ object SwaggerSerializers {
|
||||
("valueType" -> "RANGE") ~ ("min" -> min) ~ ("max" -> max)
|
||||
}
|
||||
))
|
||||
}
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ case class ApiListing (
|
||||
basePath: String,
|
||||
var resourcePath: String,
|
||||
apis: List[ApiDescription] = List(),
|
||||
models: Map[String, Model] = Map())
|
||||
models: Option[Map[String, Model]] = None)
|
||||
|
||||
case class ApiDescription (
|
||||
path: String,
|
||||
|
@ -57,7 +57,8 @@ class SwaggerModelTest extends FlatSpec with ShouldMatchers {
|
||||
apiListing.basePath should be ("http://petstore.swagger.wordnik.com/api")
|
||||
apiListing.resourcePath should be ("/pet")
|
||||
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 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 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)
|
||||
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 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)
|
||||
|
||||
val pet = models("Pet")
|
||||
@ -162,4 +167,4 @@ class SwaggerModelTest extends FlatSpec with ShouldMatchers {
|
||||
allowableValues.valueType should be ("LIST")
|
||||
(allowableValues.values.toSet & Set("available", "pending", "sold")).size should be (3)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user