mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-06-02 06:50:53 +00:00
added apiToMap test
This commit is contained in:
parent
b0c15d1c9b
commit
dd88a6b0ac
@ -320,11 +320,11 @@ class Codegen(config: CodegenConfig) {
|
||||
"deprecated" -> op.deprecated,
|
||||
"bodyParam" -> bodyParam,
|
||||
"allParams" -> sp,
|
||||
"bodyParams" -> bodyParams,
|
||||
"pathParams" -> pathParams,
|
||||
"queryParams" -> queryParams,
|
||||
"headerParams" -> headerParams,
|
||||
"requiredParams" -> requiredParams,
|
||||
"bodyParams" -> bodyParams.toList,
|
||||
"pathParams" -> pathParams.toList,
|
||||
"queryParams" -> queryParams.toList,
|
||||
"headerParams" -> headerParams.toList,
|
||||
"requiredParams" -> requiredParams.toList,
|
||||
"httpMethod" -> op.httpMethod.toUpperCase,
|
||||
op.httpMethod.toLowerCase -> "true")
|
||||
if (requiredParams.size > 0) properties += "requiredParamCount" -> requiredParams.size.toString
|
||||
@ -346,7 +346,7 @@ class Codegen(config: CodegenConfig) {
|
||||
val ComplexTypeMatcher(basePart) = op.responseClass
|
||||
properties += "returnType" -> config.processResponseDeclaration(op.responseClass.replaceAll(basePart, config.processResponseClass(basePart).get))
|
||||
properties += "returnContainer" -> (op.responseClass.substring(0, n))
|
||||
properties += "returnBaseType" -> Some(config.processResponseClass(basePart))
|
||||
properties += "returnBaseType" -> config.processResponseClass(basePart)
|
||||
properties += "returnTypeIsPrimitive" -> {
|
||||
(config.languageSpecificPrimitives.contains(basePart) || primitives.contains(basePart)) match {
|
||||
case true => Some("true")
|
||||
|
@ -38,26 +38,26 @@ class BasicGeneratorTest extends FlatSpec with ShouldMatchers {
|
||||
val generator = new SampleGenerator
|
||||
val ops = generator.extractOperations(subDocs, allModels)
|
||||
|
||||
allModels.size should be (5)
|
||||
ops.size should be (16)
|
||||
allModels.size should be (5)
|
||||
ops.size should be (16)
|
||||
|
||||
val operations = ops.map(op => (op._2, op._3)).toMap
|
||||
val operations = ops.map(op => (op._2, op._3)).toMap
|
||||
|
||||
(operations.keys.toSet &
|
||||
Set("/pet.{format}/findByTags", "/user.{format}/createWithArray", "/user.{format}/createWithList",
|
||||
"/store.{format}/order", "/user.{format}", "/pet.{format}/findByStatus", "/user.{format}/{username}",
|
||||
"/user.{format}/logout", "/user.{format}/login", "/pet.{format}/{petId}", "/store.{format}/order/{orderId}",
|
||||
"/pet.{format}")).size should be (12)
|
||||
(operations.keys.toSet &
|
||||
Set("/pet.{format}/findByTags", "/user.{format}/createWithArray", "/user.{format}/createWithList",
|
||||
"/store.{format}/order", "/user.{format}", "/pet.{format}/findByStatus", "/user.{format}/{username}",
|
||||
"/user.{format}/logout", "/user.{format}/login", "/pet.{format}/{petId}", "/store.{format}/order/{orderId}",
|
||||
"/pet.{format}")).size should be (12)
|
||||
|
||||
// pick apart the /store/order api
|
||||
val orderApi = operations("/store.{format}/order")
|
||||
// pick apart the /store/order api
|
||||
val orderApi = operations("/store.{format}/order")
|
||||
|
||||
orderApi.httpMethod should be ("POST")
|
||||
orderApi.summary should be ("Place an order for a pet")
|
||||
orderApi.responseClass should be ("void")
|
||||
orderApi.nickname should be ("placeOrder")
|
||||
orderApi.getParameters.size should be (1)
|
||||
orderApi.getErrorResponses.size should be (1)
|
||||
orderApi.httpMethod should be ("POST")
|
||||
orderApi.summary should be ("Place an order for a pet")
|
||||
orderApi.responseClass should be ("void")
|
||||
orderApi.nickname should be ("placeOrder")
|
||||
orderApi.getParameters.size should be (1)
|
||||
orderApi.getErrorResponses.size should be (1)
|
||||
}
|
||||
|
||||
it should "verify ops are grouped by path correctly" in {
|
||||
|
@ -18,21 +18,21 @@ class CodegenConfigTest extends FlatSpec with ShouldMatchers {
|
||||
val json = ScalaJsonUtil.getJsonMapper
|
||||
|
||||
class SampleCodegenConfig extends CodegenConfig with PathUtil {
|
||||
override def packageName = "com.test"
|
||||
override def templateDir = "src/test/resources/sampleConfigTemplates"
|
||||
override def destinationDir = {
|
||||
val tmpFile = java.io.File.createTempFile("test",".tmp")
|
||||
tmpFile.delete; tmpFile.mkdir
|
||||
tmpFile.deleteOnExit
|
||||
tmpFile.toString
|
||||
}
|
||||
override def escapeReservedWord(word: String) = "`" + word + "`"
|
||||
override def typeMapping = Map("int" -> "integer")
|
||||
override def invokerPackage = Some("com.wordnik.something")
|
||||
override def apiPackage = Some("com.wordnik.api")
|
||||
override def modelPackage = Some("com.wordnik.models")
|
||||
override def reservedWords = Set("special")
|
||||
override def importMapping = super.importMapping ++ Map("User" -> "com.mypackage.User")
|
||||
override def packageName = "com.test"
|
||||
override def templateDir = "src/test/resources/sampleConfigTemplates"
|
||||
override def destinationDir = {
|
||||
val tmpFile = java.io.File.createTempFile("test",".tmp")
|
||||
tmpFile.delete; tmpFile.mkdir
|
||||
tmpFile.deleteOnExit
|
||||
tmpFile.toString
|
||||
}
|
||||
override def escapeReservedWord(word: String) = "`" + word + "`"
|
||||
override def typeMapping = Map("int" -> "integer")
|
||||
override def invokerPackage = Some("com.wordnik.something")
|
||||
override def apiPackage = Some("com.wordnik.api")
|
||||
override def modelPackage = Some("com.wordnik.models")
|
||||
override def reservedWords = Set("special")
|
||||
override def importMapping = super.importMapping ++ Map("User" -> "com.mypackage.User")
|
||||
}
|
||||
|
||||
val config = new SampleCodegenConfig
|
||||
@ -42,7 +42,7 @@ class CodegenConfigTest extends FlatSpec with ShouldMatchers {
|
||||
* We will take an api in the spec and create an API name from it
|
||||
*/
|
||||
it should "convert an api name" in {
|
||||
config.toApiName("fun") should be ("FunApi")
|
||||
config.toApiName("fun") should be ("FunApi")
|
||||
}
|
||||
|
||||
/*
|
||||
@ -50,7 +50,7 @@ class CodegenConfigTest extends FlatSpec with ShouldMatchers {
|
||||
* i.e. /foo will follow rules to become FooApi
|
||||
*/
|
||||
it should "convert a path" in {
|
||||
config.apiNameFromPath("/foo/bar/cats/dogs") should be ("FooApi")
|
||||
config.apiNameFromPath("/foo/bar/cats/dogs") should be ("FooApi")
|
||||
}
|
||||
|
||||
behavior of "CodegenConfig"
|
||||
@ -59,7 +59,7 @@ class CodegenConfigTest extends FlatSpec with ShouldMatchers {
|
||||
* for the template generator
|
||||
*/
|
||||
it should "process a response declaration" in {
|
||||
config.processResponseDeclaration("void") should be (None)
|
||||
config.processResponseDeclaration("void") should be (None)
|
||||
}
|
||||
|
||||
/*
|
||||
@ -67,7 +67,7 @@ class CodegenConfigTest extends FlatSpec with ShouldMatchers {
|
||||
* unchanged
|
||||
*/
|
||||
it should "process an unchanged response" in {
|
||||
config.processResponseDeclaration("string") should be (Some("string"))
|
||||
config.processResponseDeclaration("string") should be (Some("string"))
|
||||
}
|
||||
|
||||
/*
|
||||
@ -75,28 +75,28 @@ class CodegenConfigTest extends FlatSpec with ShouldMatchers {
|
||||
* from a method should be translated
|
||||
*/
|
||||
it should "process an mapped response type" in {
|
||||
config.processResponseDeclaration("int") should be (Some("integer"))
|
||||
config.processResponseDeclaration("int") should be (Some("integer"))
|
||||
}
|
||||
|
||||
/*
|
||||
* returns the invoker package from the config
|
||||
*/
|
||||
it should "get the invoker package" in {
|
||||
config.invokerPackage should be (Some("com.wordnik.something"))
|
||||
config.invokerPackage should be (Some("com.wordnik.something"))
|
||||
}
|
||||
|
||||
/*
|
||||
* returns the api package
|
||||
*/
|
||||
it should "get the api package" in {
|
||||
config.apiPackage should be (Some("com.wordnik.api"))
|
||||
config.apiPackage should be (Some("com.wordnik.api"))
|
||||
}
|
||||
|
||||
/*
|
||||
* returns the model package
|
||||
*/
|
||||
it should "get the model package" in {
|
||||
config.modelPackage should be (Some("com.wordnik.models"))
|
||||
config.modelPackage should be (Some("com.wordnik.models"))
|
||||
}
|
||||
|
||||
/*
|
||||
@ -104,7 +104,7 @@ class CodegenConfigTest extends FlatSpec with ShouldMatchers {
|
||||
* types
|
||||
*/
|
||||
it should "convert to a declared type" in {
|
||||
config.toDeclaredType("int") should be ("integer")
|
||||
config.toDeclaredType("int") should be ("integer")
|
||||
}
|
||||
|
||||
/*
|
||||
@ -112,7 +112,7 @@ class CodegenConfigTest extends FlatSpec with ShouldMatchers {
|
||||
* classes
|
||||
*/
|
||||
it should "honor the import mapping" in {
|
||||
config.importMapping("User") should be ("com.mypackage.User")
|
||||
config.importMapping("User") should be ("com.mypackage.User")
|
||||
}
|
||||
|
||||
/*
|
||||
@ -120,6 +120,6 @@ class CodegenConfigTest extends FlatSpec with ShouldMatchers {
|
||||
* either by quoting or manipulating them with a prefix/suffix
|
||||
*/
|
||||
it should "quote a reserved var name" in {
|
||||
config.toVarName("special") should be ("`special`")
|
||||
config.toVarName("special") should be ("`special`")
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user