Skip to content

Commit

Permalink
Merge pull request #107 from outfoxx/task/test-jaxrs-produces-override
Browse files Browse the repository at this point in the history
Add test validating JAXRS @produces
  • Loading branch information
kdubb authored Oct 27, 2024
2 parents f352d7d + b4c9972 commit ff3a165
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,77 @@ class ServiceTest {
},
)
}

@Test
fun `test default media types are overridden correctly (Server)`(
@ResourceUri("raml/service-gen/svc-override-multiple-media-types.raml") testUri: URI,
) {

val typeRegistry = KotlinTypeRegistry("io.test", null, GenerationMode.Server, setOf())

val options = KotlinJAXRSGenerator.Options(
false,
null,
false,
null,
false,
"io.test.service",
"http://example.com/",
listOf("application/json", "application/yaml"),
"API",
false,
)

val builtTypes =
generate(testUri, typeRegistry) { document, shapeIndex ->
KotlinJAXRSGenerator(
document,
shapeIndex,
typeRegistry,
options,
)
}

val typeSpec = findType("io.test.service.API", builtTypes)

assertEquals(
"""
package io.test.service
import javax.ws.rs.Consumes
import javax.ws.rs.GET
import javax.ws.rs.Path
import javax.ws.rs.Produces
import javax.ws.rs.core.Response
@Produces(value = ["application/json","application/yaml"])
@Consumes(value = ["application/json","application/yaml"])
public interface API {
@GET
@Path(value = "/tests/1")
@Produces(value = ["application/yaml"])
public fun fetchTest1(): Response
@GET
@Path(value = "/tests/2s")
public fun fetchTest2Same(): Response
@GET
@Path(value = "/tests/2d")
@Produces(value = ["application/yaml","application/cbor"])
public fun fetchTest2Different(): Response
@GET
@Path(value = "/tests/3")
@Produces(value = ["application/yaml","application/json","application/cbor"])
public fun fetchTest3(): Response
}
""".trimIndent(),
buildString {
FileSpec.get("io.test.service", typeSpec)
.writeTo(this)
},
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#%RAML 1.0
title: Test API
mediaType:
- application/json
- application/yaml

types:

Test:
type: object
properties:
value1: string
value2: integer


/tests/1:
get:
displayName: fetchTest1
responses:
200:
body:
application/yaml:
type: Test
/tests/2s:
get:
displayName: fetchTest2Same
responses:
200:
body:
application/yaml:
type: Test
application/json:
type: Test
/tests/2d:
get:
displayName: fetchTest2Different
responses:
200:
body:
application/yaml:
type: Test
application/cbor:
type: Test
/tests/3:
get:
displayName: fetchTest3
responses:
200:
body:
application/yaml:
type: Test
application/json:
type: Test
application/cbor:
type: Test

0 comments on commit ff3a165

Please sign in to comment.