diff --git a/.github/workflows/samples-kotlin-wiremock.yaml b/.github/workflows/samples-kotlin-wiremock.yaml index 6b40912dd26..bd6bb37e9cb 100644 --- a/.github/workflows/samples-kotlin-wiremock.yaml +++ b/.github/workflows/samples-kotlin-wiremock.yaml @@ -3,11 +3,11 @@ name: Samples Kotlin WireMock on: push: branches: - - samples/server/petstore/kotlin-wiremock/** + - samples/server/petstore/kotlin-wiremock*/** - samples/server/echo_api/kotlin-wiremock/** pull_request: paths: - - samples/server/petstore/kotlin-wiremock/** + - samples/server/petstore/kotlin-wiremock*/** - samples/server/echo_api/kotlin-wiremock/** jobs: @@ -19,6 +19,7 @@ jobs: matrix: sample: - samples/server/petstore/kotlin-wiremock + - samples/server/petstore/kotlin-wiremock-responses - samples/server/echo_api/kotlin-wiremock steps: - uses: actions/checkout@v4 diff --git a/bin/configs/kotlin-wiremock-responses.yaml b/bin/configs/kotlin-wiremock-responses.yaml new file mode 100644 index 00000000000..13a957d9408 --- /dev/null +++ b/bin/configs/kotlin-wiremock-responses.yaml @@ -0,0 +1,4 @@ +generatorName: kotlin-wiremock +outputDir: samples/server/petstore/kotlin-wiremock-responses +inputSpec: modules/openapi-generator/src/test/resources/3_0/kotlin/issue7193-responses.yaml +templateDir: modules/openapi-generator/src/main/resources/kotlin-wiremock diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinWiremockServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinWiremockServerCodegen.java index 4ed88127122..f876ef2cbd1 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinWiremockServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinWiremockServerCodegen.java @@ -1,9 +1,7 @@ package org.openapitools.codegen.languages; -import org.openapitools.codegen.CodegenConstants; -import org.openapitools.codegen.CodegenProperty; -import org.openapitools.codegen.CodegenType; -import org.openapitools.codegen.SupportingFile; +import io.swagger.v3.oas.models.responses.ApiResponse; +import org.openapitools.codegen.*; import org.openapitools.codegen.meta.GeneratorMetadata; import org.openapitools.codegen.meta.Stability; import org.openapitools.codegen.meta.features.GlobalFeature; @@ -16,6 +14,7 @@ import org.openapitools.codegen.model.ModelsMap; import java.io.File; import java.util.EnumSet; import java.util.List; +import java.util.Locale; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -23,6 +22,8 @@ public class KotlinWiremockServerCodegen extends AbstractKotlinCodegen { protected static final String VENDOR_EXTENSION_BASE_NAME_LITERAL = "x-base-name-literal"; + protected static final String VENDOR_EXTENSION_IS_RANGE_RESPONSE_CODE = "x-is-range-code"; + @Override public CodegenType getTag() { return CodegenType.SERVER; @@ -126,6 +127,15 @@ public class KotlinWiremockServerCodegen extends AbstractKotlinCodegen { return objects; } + @Override + public CodegenResponse fromResponse(String responseCode, ApiResponse response) { + var r = super.fromResponse(responseCode, response); + + var isRange = List.of("1xx", "2xx", "3xx", "4xx", "5xx").contains(responseCode.toLowerCase(Locale.ROOT)); + r.vendorExtensions.put(VENDOR_EXTENSION_IS_RANGE_RESPONSE_CODE, isRange); + return r; + } + @Override public void postProcess() { System.out.println("################################################################################"); diff --git a/modules/openapi-generator/src/main/resources/kotlin-wiremock/api-stub-builder.mustache b/modules/openapi-generator/src/main/resources/kotlin-wiremock/api-stub-builder.mustache index ef98a549fe3..be46b58e7d5 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-wiremock/api-stub-builder.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-wiremock/api-stub-builder.mustache @@ -21,39 +21,68 @@ import {{modelPackage}}.* class {{operationIdCamelCase}}StubBuilder internal constructor(private val objectMapper: ObjectMapper, private val stub: MappingBuilder) { {{#responses}} {{^wildcard}} + {{^vendorExtensions.x-is-range-code}} /** * Let the stub for {{operationId}} respond with HTTP status code {{code}}. * - {{#returnType}} + {{#dataType}} * @param body response body for the [MappingBuilder]. - {{/returnType}} - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + {{/dataType}} + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith{{code}}( - {{#returnType}} + {{#dataType}} body: {{{.}}}, - {{/returnType}} + {{/dataType}} configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, ): MappingBuilder = stub.willReturn(aResponse() .withStatus({{code}}) - {{#returnType}} + {{#dataType}} .withHeader("Content-Type", "application/json") .withBody(objectMapper.writeValueAsString(body)) - {{/returnType}} + {{/dataType}} .configurer() ) + {{/vendorExtensions.x-is-range-code}} {{/wildcard}} + {{#vendorExtensions.x-is-range-code}} + + /** + * Let the stub for {{operationId}} respond with HTTP status code [code]. + * + * @param code the response code. + {{#dataType}} + * @param body response body for the [MappingBuilder]. + {{/dataType}} + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. + * @return a [MappingBuilder] to be registered with a WireMock instance. + */ + fun respondWith{{code}}( + code: Int, + {{#dataType}} + body: {{{.}}}, + {{/dataType}} + configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, + ): MappingBuilder = + stub.willReturn(aResponse() + .withStatus(code) + {{#dataType}} + .withHeader("Content-Type", "application/json") + .withBody(objectMapper.writeValueAsString(body)) + {{/dataType}} + .configurer() + ) + {{/vendorExtensions.x-is-range-code}} {{/responses}} /** * Let the stub for {{operationId}} respond with HTTP status code [code]. * - {{#returnType}} + * @param code the response code. * @param body response body for the [MappingBuilder]. - {{/returnType}} * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ diff --git a/modules/openapi-generator/src/test/resources/3_0/kotlin/issue7193-responses.yaml b/modules/openapi-generator/src/test/resources/3_0/kotlin/issue7193-responses.yaml new file mode 100644 index 00000000000..4adb9f3e47c --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/kotlin/issue7193-responses.yaml @@ -0,0 +1,51 @@ +openapi: 3.0.0 +info: + description: >- + This spec is mainly for testing Petstore server and contains fake endpoints, + models. Please do not use this for any other purpose. Special characters: " + \ + version: 1.0.0 + title: OpenAPI Petstore + license: + name: Apache-2.0 + url: 'https://www.apache.org/licenses/LICENSE-2.0.html' +paths: + /foo: + get: + responses: + default: + description: response + content: + application/json: + schema: + type: number + 4XX: + description: client error + content: + application/json: + schema: + $ref: '#/components/schemas/Foo' + 404: + description: not found + content: + application/json: + schema: + type: string + 400: + description: bad request + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Foo' +components: + schemas: + Foo: + type: object + properties: + bar: + $ref: '#/components/schemas/Bar' + Bar: + type: string + default: bar diff --git a/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/AuthApiStubBuilders.kt b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/AuthApiStubBuilders.kt index cccbcd94168..680ce5a3262 100644 --- a/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/AuthApiStubBuilders.kt +++ b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/AuthApiStubBuilders.kt @@ -22,7 +22,7 @@ class TestAuthHttpBasicStubBuilder internal constructor(private val objectMapper * Let the stub for testAuthHttpBasic respond with HTTP status code 200. * * @param body response body for the [MappingBuilder]. - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith200( @@ -39,6 +39,7 @@ class TestAuthHttpBasicStubBuilder internal constructor(private val objectMapper /** * Let the stub for testAuthHttpBasic respond with HTTP status code [code]. * + * @param code the response code. * @param body response body for the [MappingBuilder]. * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. @@ -69,7 +70,7 @@ class TestAuthHttpBearerStubBuilder internal constructor(private val objectMappe * Let the stub for testAuthHttpBearer respond with HTTP status code 200. * * @param body response body for the [MappingBuilder]. - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith200( @@ -86,6 +87,7 @@ class TestAuthHttpBearerStubBuilder internal constructor(private val objectMappe /** * Let the stub for testAuthHttpBearer respond with HTTP status code [code]. * + * @param code the response code. * @param body response body for the [MappingBuilder]. * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. diff --git a/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/BodyApiStubBuilders.kt b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/BodyApiStubBuilders.kt index 16286fdec9d..a98077e6ec7 100644 --- a/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/BodyApiStubBuilders.kt +++ b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/BodyApiStubBuilders.kt @@ -22,7 +22,7 @@ class TestBinaryGifStubBuilder internal constructor(private val objectMapper: Ob * Let the stub for testBinaryGif respond with HTTP status code 200. * * @param body response body for the [MappingBuilder]. - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith200( @@ -39,6 +39,7 @@ class TestBinaryGifStubBuilder internal constructor(private val objectMapper: Ob /** * Let the stub for testBinaryGif respond with HTTP status code [code]. * + * @param code the response code. * @param body response body for the [MappingBuilder]. * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. @@ -69,7 +70,7 @@ class TestBodyApplicationOctetstreamBinaryStubBuilder internal constructor(priva * Let the stub for testBodyApplicationOctetstreamBinary respond with HTTP status code 200. * * @param body response body for the [MappingBuilder]. - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith200( @@ -86,6 +87,7 @@ class TestBodyApplicationOctetstreamBinaryStubBuilder internal constructor(priva /** * Let the stub for testBodyApplicationOctetstreamBinary respond with HTTP status code [code]. * + * @param code the response code. * @param body response body for the [MappingBuilder]. * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. @@ -116,7 +118,7 @@ class TestBodyMultipartFormdataArrayOfBinaryStubBuilder internal constructor(pri * Let the stub for testBodyMultipartFormdataArrayOfBinary respond with HTTP status code 200. * * @param body response body for the [MappingBuilder]. - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith200( @@ -133,6 +135,7 @@ class TestBodyMultipartFormdataArrayOfBinaryStubBuilder internal constructor(pri /** * Let the stub for testBodyMultipartFormdataArrayOfBinary respond with HTTP status code [code]. * + * @param code the response code. * @param body response body for the [MappingBuilder]. * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. @@ -163,7 +166,7 @@ class TestBodyMultipartFormdataSingleBinaryStubBuilder internal constructor(priv * Let the stub for testBodyMultipartFormdataSingleBinary respond with HTTP status code 200. * * @param body response body for the [MappingBuilder]. - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith200( @@ -180,6 +183,7 @@ class TestBodyMultipartFormdataSingleBinaryStubBuilder internal constructor(priv /** * Let the stub for testBodyMultipartFormdataSingleBinary respond with HTTP status code [code]. * + * @param code the response code. * @param body response body for the [MappingBuilder]. * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. @@ -210,7 +214,7 @@ class TestEchoBodyFreeFormObjectResponseStringStubBuilder internal constructor(p * Let the stub for testEchoBodyFreeFormObjectResponseString respond with HTTP status code 200. * * @param body response body for the [MappingBuilder]. - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith200( @@ -227,6 +231,7 @@ class TestEchoBodyFreeFormObjectResponseStringStubBuilder internal constructor(p /** * Let the stub for testEchoBodyFreeFormObjectResponseString respond with HTTP status code [code]. * + * @param code the response code. * @param body response body for the [MappingBuilder]. * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. @@ -257,7 +262,7 @@ class TestEchoBodyPetStubBuilder internal constructor(private val objectMapper: * Let the stub for testEchoBodyPet respond with HTTP status code 200. * * @param body response body for the [MappingBuilder]. - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith200( @@ -274,6 +279,7 @@ class TestEchoBodyPetStubBuilder internal constructor(private val objectMapper: /** * Let the stub for testEchoBodyPet respond with HTTP status code [code]. * + * @param code the response code. * @param body response body for the [MappingBuilder]. * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. @@ -304,7 +310,7 @@ class TestEchoBodyPetResponseStringStubBuilder internal constructor(private val * Let the stub for testEchoBodyPetResponseString respond with HTTP status code 200. * * @param body response body for the [MappingBuilder]. - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith200( @@ -321,6 +327,7 @@ class TestEchoBodyPetResponseStringStubBuilder internal constructor(private val /** * Let the stub for testEchoBodyPetResponseString respond with HTTP status code [code]. * + * @param code the response code. * @param body response body for the [MappingBuilder]. * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. @@ -351,7 +358,7 @@ class TestEchoBodyTagResponseStringStubBuilder internal constructor(private val * Let the stub for testEchoBodyTagResponseString respond with HTTP status code 200. * * @param body response body for the [MappingBuilder]. - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith200( @@ -368,6 +375,7 @@ class TestEchoBodyTagResponseStringStubBuilder internal constructor(private val /** * Let the stub for testEchoBodyTagResponseString respond with HTTP status code [code]. * + * @param code the response code. * @param body response body for the [MappingBuilder]. * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. diff --git a/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/FormApiStubBuilders.kt b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/FormApiStubBuilders.kt index a25e427db01..2a761ab4c06 100644 --- a/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/FormApiStubBuilders.kt +++ b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/FormApiStubBuilders.kt @@ -22,7 +22,7 @@ class TestFormIntegerBooleanStringStubBuilder internal constructor(private val o * Let the stub for testFormIntegerBooleanString respond with HTTP status code 200. * * @param body response body for the [MappingBuilder]. - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith200( @@ -39,6 +39,7 @@ class TestFormIntegerBooleanStringStubBuilder internal constructor(private val o /** * Let the stub for testFormIntegerBooleanString respond with HTTP status code [code]. * + * @param code the response code. * @param body response body for the [MappingBuilder]. * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. @@ -69,7 +70,7 @@ class TestFormOneofStubBuilder internal constructor(private val objectMapper: Ob * Let the stub for testFormOneof respond with HTTP status code 200. * * @param body response body for the [MappingBuilder]. - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith200( @@ -86,6 +87,7 @@ class TestFormOneofStubBuilder internal constructor(private val objectMapper: Ob /** * Let the stub for testFormOneof respond with HTTP status code [code]. * + * @param code the response code. * @param body response body for the [MappingBuilder]. * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. diff --git a/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/HeaderApiStubBuilders.kt b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/HeaderApiStubBuilders.kt index 4dbe40addb0..15185453b17 100644 --- a/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/HeaderApiStubBuilders.kt +++ b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/HeaderApiStubBuilders.kt @@ -22,7 +22,7 @@ class TestHeaderIntegerBooleanStringEnumsStubBuilder internal constructor(privat * Let the stub for testHeaderIntegerBooleanStringEnums respond with HTTP status code 200. * * @param body response body for the [MappingBuilder]. - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith200( @@ -39,6 +39,7 @@ class TestHeaderIntegerBooleanStringEnumsStubBuilder internal constructor(privat /** * Let the stub for testHeaderIntegerBooleanStringEnums respond with HTTP status code [code]. * + * @param code the response code. * @param body response body for the [MappingBuilder]. * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. diff --git a/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/PathApiStubBuilders.kt b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/PathApiStubBuilders.kt index c33be23bb98..66955515985 100644 --- a/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/PathApiStubBuilders.kt +++ b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/PathApiStubBuilders.kt @@ -22,7 +22,7 @@ class TestsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStri * Let the stub for testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath respond with HTTP status code 200. * * @param body response body for the [MappingBuilder]. - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith200( @@ -39,6 +39,7 @@ class TestsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStri /** * Let the stub for testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath respond with HTTP status code [code]. * + * @param code the response code. * @param body response body for the [MappingBuilder]. * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. diff --git a/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/QueryApiStubBuilders.kt b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/QueryApiStubBuilders.kt index 77e10817e14..3fbc927fd9f 100644 --- a/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/QueryApiStubBuilders.kt +++ b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/QueryApiStubBuilders.kt @@ -22,7 +22,7 @@ class TestEnumRefStringStubBuilder internal constructor(private val objectMapper * Let the stub for testEnumRefString respond with HTTP status code 200. * * @param body response body for the [MappingBuilder]. - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith200( @@ -39,6 +39,7 @@ class TestEnumRefStringStubBuilder internal constructor(private val objectMapper /** * Let the stub for testEnumRefString respond with HTTP status code [code]. * + * @param code the response code. * @param body response body for the [MappingBuilder]. * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. @@ -69,7 +70,7 @@ class TestQueryDatetimeDateStringStubBuilder internal constructor(private val ob * Let the stub for testQueryDatetimeDateString respond with HTTP status code 200. * * @param body response body for the [MappingBuilder]. - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith200( @@ -86,6 +87,7 @@ class TestQueryDatetimeDateStringStubBuilder internal constructor(private val ob /** * Let the stub for testQueryDatetimeDateString respond with HTTP status code [code]. * + * @param code the response code. * @param body response body for the [MappingBuilder]. * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. @@ -116,7 +118,7 @@ class TestQueryIntegerBooleanStringStubBuilder internal constructor(private val * Let the stub for testQueryIntegerBooleanString respond with HTTP status code 200. * * @param body response body for the [MappingBuilder]. - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith200( @@ -133,6 +135,7 @@ class TestQueryIntegerBooleanStringStubBuilder internal constructor(private val /** * Let the stub for testQueryIntegerBooleanString respond with HTTP status code [code]. * + * @param code the response code. * @param body response body for the [MappingBuilder]. * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. @@ -163,7 +166,7 @@ class TestQueryStyleDeepObjectExplodeTrueObjectStubBuilder internal constructor( * Let the stub for testQueryStyleDeepObjectExplodeTrueObject respond with HTTP status code 200. * * @param body response body for the [MappingBuilder]. - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith200( @@ -180,6 +183,7 @@ class TestQueryStyleDeepObjectExplodeTrueObjectStubBuilder internal constructor( /** * Let the stub for testQueryStyleDeepObjectExplodeTrueObject respond with HTTP status code [code]. * + * @param code the response code. * @param body response body for the [MappingBuilder]. * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. @@ -210,7 +214,7 @@ class TestQueryStyleFormExplodeTrueArrayStringStubBuilder internal constructor(p * Let the stub for testQueryStyleFormExplodeTrueArrayString respond with HTTP status code 200. * * @param body response body for the [MappingBuilder]. - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith200( @@ -227,6 +231,7 @@ class TestQueryStyleFormExplodeTrueArrayStringStubBuilder internal constructor(p /** * Let the stub for testQueryStyleFormExplodeTrueArrayString respond with HTTP status code [code]. * + * @param code the response code. * @param body response body for the [MappingBuilder]. * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. @@ -257,7 +262,7 @@ class TestQueryStyleFormExplodeTrueObjectStubBuilder internal constructor(privat * Let the stub for testQueryStyleFormExplodeTrueObject respond with HTTP status code 200. * * @param body response body for the [MappingBuilder]. - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith200( @@ -274,6 +279,7 @@ class TestQueryStyleFormExplodeTrueObjectStubBuilder internal constructor(privat /** * Let the stub for testQueryStyleFormExplodeTrueObject respond with HTTP status code [code]. * + * @param code the response code. * @param body response body for the [MappingBuilder]. * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. diff --git a/samples/server/petstore/kotlin-wiremock-responses/.gitignore b/samples/server/petstore/kotlin-wiremock-responses/.gitignore new file mode 100644 index 00000000000..2983e3c1db3 --- /dev/null +++ b/samples/server/petstore/kotlin-wiremock-responses/.gitignore @@ -0,0 +1,106 @@ +./bin/ +# Created by https://www.gitignore.io/api/java,intellij,gradle + +### Intellij ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff: +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/dictionaries + +# Sensitive or high-churn files: +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.xml +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml + +# Gradle: +.idea/**/gradle.xml +.idea/**/libraries + +# CMake +cmake-build-debug/ + +# Mongo Explorer plugin: +.idea/**/mongoSettings.xml + +## File-based project format: +*.iws + +## Plugin-specific files: + +# IntelliJ +/out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +### Intellij Patch ### +# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 + +# *.iml +# modules.xml +# .idea/misc.xml +# *.ipr + +# Sonarlint plugin +.idea/sonarlint + +### Java ### +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +### Gradle ### +.gradle +/build/ + +# Ignore Gradle GUI config +gradle-app.setting + +# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) +!gradle-wrapper.jar + +# Cache of project +.gradletasknamecache + +# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 +# gradle/wrapper/gradle-wrapper.properties + +# End of https://www.gitignore.io/api/java,intellij,gradle diff --git a/samples/server/petstore/kotlin-wiremock-responses/.openapi-generator-ignore b/samples/server/petstore/kotlin-wiremock-responses/.openapi-generator-ignore new file mode 100644 index 00000000000..7484ee590a3 --- /dev/null +++ b/samples/server/petstore/kotlin-wiremock-responses/.openapi-generator-ignore @@ -0,0 +1,23 @@ +# OpenAPI Generator Ignore +# Generated by openapi-generator https://github.com/openapitools/openapi-generator + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/samples/server/petstore/kotlin-wiremock-responses/.openapi-generator/FILES b/samples/server/petstore/kotlin-wiremock-responses/.openapi-generator/FILES new file mode 100644 index 00000000000..54febc95233 --- /dev/null +++ b/samples/server/petstore/kotlin-wiremock-responses/.openapi-generator/FILES @@ -0,0 +1,11 @@ +.gitignore +build.gradle.kts +gradle/libs.versions.toml +gradle/wrapper/gradle-wrapper.jar +gradle/wrapper/gradle-wrapper.properties +gradlew +gradlew.bat +settings.gradle.kts +src/main/kotlin/org/openapitools/apis/DefaultApiStubBuilders.kt +src/main/kotlin/org/openapitools/apis/DefaultApiStubs.kt +src/main/kotlin/org/openapitools/models/Foo.kt diff --git a/samples/server/petstore/kotlin-wiremock-responses/.openapi-generator/VERSION b/samples/server/petstore/kotlin-wiremock-responses/.openapi-generator/VERSION new file mode 100644 index 00000000000..6116b14d2c5 --- /dev/null +++ b/samples/server/petstore/kotlin-wiremock-responses/.openapi-generator/VERSION @@ -0,0 +1 @@ +7.8.0-SNAPSHOT diff --git a/samples/server/petstore/kotlin-wiremock-responses/build.gradle.kts b/samples/server/petstore/kotlin-wiremock-responses/build.gradle.kts new file mode 100644 index 00000000000..f5d878978f3 --- /dev/null +++ b/samples/server/petstore/kotlin-wiremock-responses/build.gradle.kts @@ -0,0 +1,21 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +group = "org.openapitools" +version = "1.0.0" + +tasks.wrapper { + gradleVersion = "8.7" +} + +plugins { + alias(libs.plugins.kotlin.jvm) +} + +tasks.withType { + kotlinOptions.jvmTarget = "11" +} + +dependencies { + implementation(libs.wiremock) + implementation(libs.jackson.databind) +} \ No newline at end of file diff --git a/samples/server/petstore/kotlin-wiremock-responses/gradle/libs.versions.toml b/samples/server/petstore/kotlin-wiremock-responses/gradle/libs.versions.toml new file mode 100644 index 00000000000..23fdd0ddbc1 --- /dev/null +++ b/samples/server/petstore/kotlin-wiremock-responses/gradle/libs.versions.toml @@ -0,0 +1,10 @@ +[versions] +kotlin = "1.9.23" +wiremock = "3.5.4" + +[libraries] +wiremock = { module = "org.wiremock:wiremock", version.ref = "wiremock" } +jackson-databind = { module = "com.fasterxml.jackson.core:jackson-databind", version = "2.17.1" } + +[plugins] +kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } \ No newline at end of file diff --git a/samples/server/petstore/kotlin-wiremock-responses/gradle/wrapper/gradle-wrapper.jar b/samples/server/petstore/kotlin-wiremock-responses/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000000..d64cd491770 Binary files /dev/null and b/samples/server/petstore/kotlin-wiremock-responses/gradle/wrapper/gradle-wrapper.jar differ diff --git a/samples/server/petstore/kotlin-wiremock-responses/gradle/wrapper/gradle-wrapper.properties b/samples/server/petstore/kotlin-wiremock-responses/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000000..e7646dead06 --- /dev/null +++ b/samples/server/petstore/kotlin-wiremock-responses/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/samples/server/petstore/kotlin-wiremock-responses/gradlew b/samples/server/petstore/kotlin-wiremock-responses/gradlew new file mode 100644 index 00000000000..9d0ce634cb1 --- /dev/null +++ b/samples/server/petstore/kotlin-wiremock-responses/gradlew @@ -0,0 +1,249 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while +APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path +[ -h "$app_path" ] +do +ls=$( ls -ld "$app_path" ) +link=${ls#*' -> '} +case $link in #( +/*) app_path=$link ;; #( +*) app_path=$APP_HOME$link ;; +esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { +echo "$*" +} >&2 + +die () { +echo +echo "$*" +echo +exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( +CYGWIN* ) cygwin=true ;; #( +Darwin* ) darwin=true ;; #( +MSYS* | MINGW* ) msys=true ;; #( +NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then +if [ -x "$JAVA_HOME/jre/sh/java" ] ; then +# IBM's JDK on AIX uses strange locations for the executables +JAVACMD=$JAVA_HOME/jre/sh/java +else +JAVACMD=$JAVA_HOME/bin/java +fi +if [ ! -x "$JAVACMD" ] ; then +die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi +else +JAVACMD=java +if ! command -v java >/dev/null 2>&1 +then +die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then +case $MAX_FD in #( +max*) +# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. +# shellcheck disable=SC2039,SC3045 +MAX_FD=$( ulimit -H -n ) || +warn "Could not query maximum file descriptor limit" +esac +case $MAX_FD in #( +'' | soft) :;; #( +*) +# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. +# shellcheck disable=SC2039,SC3045 +ulimit -n "$MAX_FD" || +warn "Could not set maximum file descriptor limit to $MAX_FD" +esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then +APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) +CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + +JAVACMD=$( cygpath --unix "$JAVACMD" ) + +# Now convert the arguments - kludge to limit ourselves to /bin/sh +for arg do +if +case $arg in #( +-*) false ;; # don't mess with options #( +/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath +[ -e "$t" ] ;; #( +*) false ;; +esac +then +arg=$( cygpath --path --ignore --mixed "$arg" ) +fi +# Roll the args list around exactly as many times as the number of +# args, so each arg winds up back in the position where it started, but +# possibly modified. +# +# NB: a `for` loop captures its iteration list before it begins, so +# changing the positional parameters here affects neither the number of +# iterations, nor the values presented in `arg`. +shift # remove old arg +set -- "$@" "$arg" # push replacement arg +done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ +"-Dorg.gradle.appname=$APP_BASE_NAME" \ +-classpath "$CLASSPATH" \ +org.gradle.wrapper.GradleWrapperMain \ +"$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then +die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( +printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | +xargs -n1 | +sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | +tr '\n' ' ' +)" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/samples/server/petstore/kotlin-wiremock-responses/gradlew.bat b/samples/server/petstore/kotlin-wiremock-responses/gradlew.bat new file mode 100644 index 00000000000..107acd32c4e --- /dev/null +++ b/samples/server/petstore/kotlin-wiremock-responses/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/samples/server/petstore/kotlin-wiremock-responses/settings.gradle.kts b/samples/server/petstore/kotlin-wiremock-responses/settings.gradle.kts new file mode 100644 index 00000000000..537908ca655 --- /dev/null +++ b/samples/server/petstore/kotlin-wiremock-responses/settings.gradle.kts @@ -0,0 +1,7 @@ +rootProject.name = "kotlin-wiremock" + +dependencyResolutionManagement { + repositories { + mavenCentral() + } +} \ No newline at end of file diff --git a/samples/server/petstore/kotlin-wiremock-responses/src/main/kotlin/org/openapitools/apis/DefaultApiStubBuilders.kt b/samples/server/petstore/kotlin-wiremock-responses/src/main/kotlin/org/openapitools/apis/DefaultApiStubBuilders.kt new file mode 100644 index 00000000000..a082e0209b9 --- /dev/null +++ b/samples/server/petstore/kotlin-wiremock-responses/src/main/kotlin/org/openapitools/apis/DefaultApiStubBuilders.kt @@ -0,0 +1,101 @@ +@file:Suppress( + "RemoveRedundantQualifierName", + "UnusedImport", + "unused", +) + +package org.openapitools.apis + +import com.fasterxml.jackson.databind.ObjectMapper +import com.github.tomakehurst.wiremock.client.MappingBuilder +import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder +import com.github.tomakehurst.wiremock.client.WireMock.* +import com.github.tomakehurst.wiremock.matching.StringValuePattern +import org.openapitools.models.* + +/** + * Builder for WireMock stubs of operation fooGet. + */ +class FooGetStubBuilder internal constructor(private val objectMapper: ObjectMapper, private val stub: MappingBuilder) { + + /** + * Let the stub for fooGet respond with HTTP status code 404. + * + * @param body response body for the [MappingBuilder]. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. + * @return a [MappingBuilder] to be registered with a WireMock instance. + */ + fun respondWith404( + body: kotlin.String, + configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, + ): MappingBuilder = + stub.willReturn(aResponse() + .withStatus(404) + .withHeader("Content-Type", "application/json") + .withBody(objectMapper.writeValueAsString(body)) + .configurer() + ) + + /** + * Let the stub for fooGet respond with HTTP status code 400. + * + * @param body response body for the [MappingBuilder]. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. + * @return a [MappingBuilder] to be registered with a WireMock instance. + */ + fun respondWith400( + body: kotlin.collections.List, + configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, + ): MappingBuilder = + stub.willReturn(aResponse() + .withStatus(400) + .withHeader("Content-Type", "application/json") + .withBody(objectMapper.writeValueAsString(body)) + .configurer() + ) + + /** + * Let the stub for fooGet respond with HTTP status code [code]. + * + * @param code the response code. + * @param body response body for the [MappingBuilder]. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. + * @return a [MappingBuilder] to be registered with a WireMock instance. + */ + fun respondWith4XX( + code: Int, + body: Foo, + configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, + ): MappingBuilder = + stub.willReturn(aResponse() + .withStatus(code) + .withHeader("Content-Type", "application/json") + .withBody(objectMapper.writeValueAsString(body)) + .configurer() + ) + + /** + * Let the stub for fooGet respond with HTTP status code [code]. + * + * @param code the response code. + * @param body response body for the [MappingBuilder]. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. + * @return a [MappingBuilder] to be registered with a WireMock instance. + */ + fun respondWith( + code: Int, + body: Any? = null, + configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this } + ): MappingBuilder = + stub.willReturn(aResponse() + .withStatus(code) + .apply { + body?.let { + withHeader("Content-Type", "application/json") + withBody(objectMapper.writeValueAsString(it)) + } + } + .configurer() + ) +} + diff --git a/samples/server/petstore/kotlin-wiremock-responses/src/main/kotlin/org/openapitools/apis/DefaultApiStubs.kt b/samples/server/petstore/kotlin-wiremock-responses/src/main/kotlin/org/openapitools/apis/DefaultApiStubs.kt new file mode 100644 index 00000000000..8a0480e334c --- /dev/null +++ b/samples/server/petstore/kotlin-wiremock-responses/src/main/kotlin/org/openapitools/apis/DefaultApiStubs.kt @@ -0,0 +1,31 @@ +@file:Suppress( + "RemoveRedundantQualifierName", + "UnusedImport", + "unused", +) + +package org.openapitools.apis + +import com.fasterxml.jackson.databind.ObjectMapper +import com.github.tomakehurst.wiremock.client.MappingBuilder +import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder +import com.github.tomakehurst.wiremock.client.WireMock.* +import com.github.tomakehurst.wiremock.matching.StringValuePattern +import org.openapitools.models.* + +/** + * WireMock stub request builder. + */ +open class DefaultApiStubs(private val objectMapper: ObjectMapper) { + + /** + * Construct a stub for the operation fooGet. + * + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. + * @return A [FooGetStubBuilder] to configure the response, and the final [MappingBuilder]. + */ + fun fooGet(configurer: MappingBuilder.() -> MappingBuilder = { this }): FooGetStubBuilder = + FooGetStubBuilder(objectMapper, get(urlPathTemplate("/foo")) + .configurer() + ) +} diff --git a/samples/server/petstore/kotlin-wiremock-responses/src/main/kotlin/org/openapitools/models/Foo.kt b/samples/server/petstore/kotlin-wiremock-responses/src/main/kotlin/org/openapitools/models/Foo.kt new file mode 100644 index 00000000000..d4633ef4459 --- /dev/null +++ b/samples/server/petstore/kotlin-wiremock-responses/src/main/kotlin/org/openapitools/models/Foo.kt @@ -0,0 +1,14 @@ +@file:Suppress( + "RemoveRedundantQualifierName", + "unused", +) + +package org.openapitools.models + +import com.fasterxml.jackson.annotation.JsonProperty + +data class Foo( + @field:JsonProperty("bar") + val bar: kotlin.String? = "bar", + +) diff --git a/samples/server/petstore/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/PetApiStubBuilders.kt b/samples/server/petstore/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/PetApiStubBuilders.kt index 429cb65a3ce..51b8f4ec1c3 100644 --- a/samples/server/petstore/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/PetApiStubBuilders.kt +++ b/samples/server/petstore/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/PetApiStubBuilders.kt @@ -22,7 +22,7 @@ class AddPetStubBuilder internal constructor(private val objectMapper: ObjectMap * Let the stub for addPet respond with HTTP status code 200. * * @param body response body for the [MappingBuilder]. - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith200( @@ -39,24 +39,21 @@ class AddPetStubBuilder internal constructor(private val objectMapper: ObjectMap /** * Let the stub for addPet respond with HTTP status code 405. * - * @param body response body for the [MappingBuilder]. - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith405( - body: Pet, configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, ): MappingBuilder = stub.willReturn(aResponse() .withStatus(405) - .withHeader("Content-Type", "application/json") - .withBody(objectMapper.writeValueAsString(body)) .configurer() ) /** * Let the stub for addPet respond with HTTP status code [code]. * + * @param code the response code. * @param body response body for the [MappingBuilder]. * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. @@ -86,7 +83,7 @@ class DeletePetStubBuilder internal constructor(private val objectMapper: Object /** * Let the stub for deletePet respond with HTTP status code 400. * - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith400( @@ -100,6 +97,8 @@ class DeletePetStubBuilder internal constructor(private val objectMapper: Object /** * Let the stub for deletePet respond with HTTP status code [code]. * + * @param code the response code. + * @param body response body for the [MappingBuilder]. * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ @@ -129,7 +128,7 @@ class FindPetsByStatusStubBuilder internal constructor(private val objectMapper: * Let the stub for findPetsByStatus respond with HTTP status code 200. * * @param body response body for the [MappingBuilder]. - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith200( @@ -146,24 +145,21 @@ class FindPetsByStatusStubBuilder internal constructor(private val objectMapper: /** * Let the stub for findPetsByStatus respond with HTTP status code 400. * - * @param body response body for the [MappingBuilder]. - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith400( - body: kotlin.collections.List, configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, ): MappingBuilder = stub.willReturn(aResponse() .withStatus(400) - .withHeader("Content-Type", "application/json") - .withBody(objectMapper.writeValueAsString(body)) .configurer() ) /** * Let the stub for findPetsByStatus respond with HTTP status code [code]. * + * @param code the response code. * @param body response body for the [MappingBuilder]. * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. @@ -194,7 +190,7 @@ class FindPetsByTagsStubBuilder internal constructor(private val objectMapper: O * Let the stub for findPetsByTags respond with HTTP status code 200. * * @param body response body for the [MappingBuilder]. - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith200( @@ -211,24 +207,21 @@ class FindPetsByTagsStubBuilder internal constructor(private val objectMapper: O /** * Let the stub for findPetsByTags respond with HTTP status code 400. * - * @param body response body for the [MappingBuilder]. - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith400( - body: kotlin.collections.List, configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, ): MappingBuilder = stub.willReturn(aResponse() .withStatus(400) - .withHeader("Content-Type", "application/json") - .withBody(objectMapper.writeValueAsString(body)) .configurer() ) /** * Let the stub for findPetsByTags respond with HTTP status code [code]. * + * @param code the response code. * @param body response body for the [MappingBuilder]. * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. @@ -259,7 +252,7 @@ class GetPetByIdStubBuilder internal constructor(private val objectMapper: Objec * Let the stub for getPetById respond with HTTP status code 200. * * @param body response body for the [MappingBuilder]. - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith200( @@ -276,42 +269,35 @@ class GetPetByIdStubBuilder internal constructor(private val objectMapper: Objec /** * Let the stub for getPetById respond with HTTP status code 400. * - * @param body response body for the [MappingBuilder]. - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith400( - body: Pet, configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, ): MappingBuilder = stub.willReturn(aResponse() .withStatus(400) - .withHeader("Content-Type", "application/json") - .withBody(objectMapper.writeValueAsString(body)) .configurer() ) /** * Let the stub for getPetById respond with HTTP status code 404. * - * @param body response body for the [MappingBuilder]. - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith404( - body: Pet, configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, ): MappingBuilder = stub.willReturn(aResponse() .withStatus(404) - .withHeader("Content-Type", "application/json") - .withBody(objectMapper.writeValueAsString(body)) .configurer() ) /** * Let the stub for getPetById respond with HTTP status code [code]. * + * @param code the response code. * @param body response body for the [MappingBuilder]. * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. @@ -342,7 +328,7 @@ class UpdatePetStubBuilder internal constructor(private val objectMapper: Object * Let the stub for updatePet respond with HTTP status code 200. * * @param body response body for the [MappingBuilder]. - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith200( @@ -359,60 +345,49 @@ class UpdatePetStubBuilder internal constructor(private val objectMapper: Object /** * Let the stub for updatePet respond with HTTP status code 400. * - * @param body response body for the [MappingBuilder]. - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith400( - body: Pet, configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, ): MappingBuilder = stub.willReturn(aResponse() .withStatus(400) - .withHeader("Content-Type", "application/json") - .withBody(objectMapper.writeValueAsString(body)) .configurer() ) /** * Let the stub for updatePet respond with HTTP status code 404. * - * @param body response body for the [MappingBuilder]. - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith404( - body: Pet, configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, ): MappingBuilder = stub.willReturn(aResponse() .withStatus(404) - .withHeader("Content-Type", "application/json") - .withBody(objectMapper.writeValueAsString(body)) .configurer() ) /** * Let the stub for updatePet respond with HTTP status code 405. * - * @param body response body for the [MappingBuilder]. - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith405( - body: Pet, configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, ): MappingBuilder = stub.willReturn(aResponse() .withStatus(405) - .withHeader("Content-Type", "application/json") - .withBody(objectMapper.writeValueAsString(body)) .configurer() ) /** * Let the stub for updatePet respond with HTTP status code [code]. * + * @param code the response code. * @param body response body for the [MappingBuilder]. * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. @@ -442,7 +417,7 @@ class UpdatePetWithFormStubBuilder internal constructor(private val objectMapper /** * Let the stub for updatePetWithForm respond with HTTP status code 405. * - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith405( @@ -456,6 +431,8 @@ class UpdatePetWithFormStubBuilder internal constructor(private val objectMapper /** * Let the stub for updatePetWithForm respond with HTTP status code [code]. * + * @param code the response code. + * @param body response body for the [MappingBuilder]. * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ @@ -485,7 +462,7 @@ class UploadFileStubBuilder internal constructor(private val objectMapper: Objec * Let the stub for uploadFile respond with HTTP status code 200. * * @param body response body for the [MappingBuilder]. - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith200( @@ -502,6 +479,7 @@ class UploadFileStubBuilder internal constructor(private val objectMapper: Objec /** * Let the stub for uploadFile respond with HTTP status code [code]. * + * @param code the response code. * @param body response body for the [MappingBuilder]. * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. diff --git a/samples/server/petstore/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/StoreApiStubBuilders.kt b/samples/server/petstore/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/StoreApiStubBuilders.kt index 297a5498bf2..2acd37fedf9 100644 --- a/samples/server/petstore/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/StoreApiStubBuilders.kt +++ b/samples/server/petstore/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/StoreApiStubBuilders.kt @@ -21,7 +21,7 @@ class DeleteOrderStubBuilder internal constructor(private val objectMapper: Obje /** * Let the stub for deleteOrder respond with HTTP status code 400. * - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith400( @@ -35,7 +35,7 @@ class DeleteOrderStubBuilder internal constructor(private val objectMapper: Obje /** * Let the stub for deleteOrder respond with HTTP status code 404. * - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith404( @@ -49,6 +49,8 @@ class DeleteOrderStubBuilder internal constructor(private val objectMapper: Obje /** * Let the stub for deleteOrder respond with HTTP status code [code]. * + * @param code the response code. + * @param body response body for the [MappingBuilder]. * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ @@ -78,7 +80,7 @@ class GetInventoryStubBuilder internal constructor(private val objectMapper: Obj * Let the stub for getInventory respond with HTTP status code 200. * * @param body response body for the [MappingBuilder]. - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith200( @@ -95,6 +97,7 @@ class GetInventoryStubBuilder internal constructor(private val objectMapper: Obj /** * Let the stub for getInventory respond with HTTP status code [code]. * + * @param code the response code. * @param body response body for the [MappingBuilder]. * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. @@ -125,7 +128,7 @@ class GetOrderByIdStubBuilder internal constructor(private val objectMapper: Obj * Let the stub for getOrderById respond with HTTP status code 200. * * @param body response body for the [MappingBuilder]. - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith200( @@ -142,42 +145,35 @@ class GetOrderByIdStubBuilder internal constructor(private val objectMapper: Obj /** * Let the stub for getOrderById respond with HTTP status code 400. * - * @param body response body for the [MappingBuilder]. - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith400( - body: Order, configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, ): MappingBuilder = stub.willReturn(aResponse() .withStatus(400) - .withHeader("Content-Type", "application/json") - .withBody(objectMapper.writeValueAsString(body)) .configurer() ) /** * Let the stub for getOrderById respond with HTTP status code 404. * - * @param body response body for the [MappingBuilder]. - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith404( - body: Order, configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, ): MappingBuilder = stub.willReturn(aResponse() .withStatus(404) - .withHeader("Content-Type", "application/json") - .withBody(objectMapper.writeValueAsString(body)) .configurer() ) /** * Let the stub for getOrderById respond with HTTP status code [code]. * + * @param code the response code. * @param body response body for the [MappingBuilder]. * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. @@ -208,7 +204,7 @@ class PlaceOrderStubBuilder internal constructor(private val objectMapper: Objec * Let the stub for placeOrder respond with HTTP status code 200. * * @param body response body for the [MappingBuilder]. - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith200( @@ -225,24 +221,21 @@ class PlaceOrderStubBuilder internal constructor(private val objectMapper: Objec /** * Let the stub for placeOrder respond with HTTP status code 400. * - * @param body response body for the [MappingBuilder]. - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith400( - body: Order, configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, ): MappingBuilder = stub.willReturn(aResponse() .withStatus(400) - .withHeader("Content-Type", "application/json") - .withBody(objectMapper.writeValueAsString(body)) .configurer() ) /** * Let the stub for placeOrder respond with HTTP status code [code]. * + * @param code the response code. * @param body response body for the [MappingBuilder]. * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. diff --git a/samples/server/petstore/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/UserApiStubBuilders.kt b/samples/server/petstore/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/UserApiStubBuilders.kt index 817c40844f2..d5443e5955d 100644 --- a/samples/server/petstore/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/UserApiStubBuilders.kt +++ b/samples/server/petstore/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/UserApiStubBuilders.kt @@ -21,6 +21,8 @@ class CreateUserStubBuilder internal constructor(private val objectMapper: Objec /** * Let the stub for createUser respond with HTTP status code [code]. * + * @param code the response code. + * @param body response body for the [MappingBuilder]. * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ @@ -49,6 +51,8 @@ class CreateUsersWithArrayInputStubBuilder internal constructor(private val obje /** * Let the stub for createUsersWithArrayInput respond with HTTP status code [code]. * + * @param code the response code. + * @param body response body for the [MappingBuilder]. * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ @@ -77,6 +81,8 @@ class CreateUsersWithListInputStubBuilder internal constructor(private val objec /** * Let the stub for createUsersWithListInput respond with HTTP status code [code]. * + * @param code the response code. + * @param body response body for the [MappingBuilder]. * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ @@ -105,7 +111,7 @@ class DeleteUserStubBuilder internal constructor(private val objectMapper: Objec /** * Let the stub for deleteUser respond with HTTP status code 400. * - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith400( @@ -119,7 +125,7 @@ class DeleteUserStubBuilder internal constructor(private val objectMapper: Objec /** * Let the stub for deleteUser respond with HTTP status code 404. * - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith404( @@ -133,6 +139,8 @@ class DeleteUserStubBuilder internal constructor(private val objectMapper: Objec /** * Let the stub for deleteUser respond with HTTP status code [code]. * + * @param code the response code. + * @param body response body for the [MappingBuilder]. * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ @@ -162,7 +170,7 @@ class GetUserByNameStubBuilder internal constructor(private val objectMapper: Ob * Let the stub for getUserByName respond with HTTP status code 200. * * @param body response body for the [MappingBuilder]. - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith200( @@ -179,42 +187,35 @@ class GetUserByNameStubBuilder internal constructor(private val objectMapper: Ob /** * Let the stub for getUserByName respond with HTTP status code 400. * - * @param body response body for the [MappingBuilder]. - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith400( - body: User, configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, ): MappingBuilder = stub.willReturn(aResponse() .withStatus(400) - .withHeader("Content-Type", "application/json") - .withBody(objectMapper.writeValueAsString(body)) .configurer() ) /** * Let the stub for getUserByName respond with HTTP status code 404. * - * @param body response body for the [MappingBuilder]. - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith404( - body: User, configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, ): MappingBuilder = stub.willReturn(aResponse() .withStatus(404) - .withHeader("Content-Type", "application/json") - .withBody(objectMapper.writeValueAsString(body)) .configurer() ) /** * Let the stub for getUserByName respond with HTTP status code [code]. * + * @param code the response code. * @param body response body for the [MappingBuilder]. * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. @@ -245,7 +246,7 @@ class LoginUserStubBuilder internal constructor(private val objectMapper: Object * Let the stub for loginUser respond with HTTP status code 200. * * @param body response body for the [MappingBuilder]. - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith200( @@ -262,24 +263,21 @@ class LoginUserStubBuilder internal constructor(private val objectMapper: Object /** * Let the stub for loginUser respond with HTTP status code 400. * - * @param body response body for the [MappingBuilder]. - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith400( - body: kotlin.String, configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, ): MappingBuilder = stub.willReturn(aResponse() .withStatus(400) - .withHeader("Content-Type", "application/json") - .withBody(objectMapper.writeValueAsString(body)) .configurer() ) /** * Let the stub for loginUser respond with HTTP status code [code]. * + * @param code the response code. * @param body response body for the [MappingBuilder]. * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. @@ -309,6 +307,8 @@ class LogoutUserStubBuilder internal constructor(private val objectMapper: Objec /** * Let the stub for logoutUser respond with HTTP status code [code]. * + * @param code the response code. + * @param body response body for the [MappingBuilder]. * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ @@ -337,7 +337,7 @@ class UpdateUserStubBuilder internal constructor(private val objectMapper: Objec /** * Let the stub for updateUser respond with HTTP status code 400. * - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith400( @@ -351,7 +351,7 @@ class UpdateUserStubBuilder internal constructor(private val objectMapper: Objec /** * Let the stub for updateUser respond with HTTP status code 404. * - * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */ fun respondWith404( @@ -365,6 +365,8 @@ class UpdateUserStubBuilder internal constructor(private val objectMapper: Objec /** * Let the stub for updateUser respond with HTTP status code [code]. * + * @param code the response code. + * @param body response body for the [MappingBuilder]. * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. * @return a [MappingBuilder] to be registered with a WireMock instance. */