diff --git a/.github/workflows/samples-kotlin-wiremock.yaml b/.github/workflows/samples-kotlin-wiremock.yaml new file mode 100644 index 000000000000..6b40912dd265 --- /dev/null +++ b/.github/workflows/samples-kotlin-wiremock.yaml @@ -0,0 +1,44 @@ +name: Samples Kotlin WireMock + +on: + push: + branches: + - samples/server/petstore/kotlin-wiremock/** + - samples/server/echo_api/kotlin-wiremock/** + pull_request: + paths: + - samples/server/petstore/kotlin-wiremock/** + - samples/server/echo_api/kotlin-wiremock/** + +jobs: + build: + name: Build Kotlin WireMock + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + sample: + - samples/server/petstore/kotlin-wiremock + - samples/server/echo_api/kotlin-wiremock + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: 11 + - name: Cache maven dependencies + uses: actions/cache@v4 + env: + cache-name: maven-repository + with: + path: | + ~/.gradle + key: ${{ runner.os }}-${{ github.job }}-${{ env.cache-name }}-${{ hashFiles('**/pom.xml') }} + - name: Install Gradle wrapper + uses: eskatos/gradle-command-action@v3 + with: + build-root-directory: ${{ matrix.sample }} + arguments: wrapper + - name: Build + working-directory: ${{ matrix.sample }} + run: ./gradlew build -x test diff --git a/README.md b/README.md index 31ac8d785762..7674dafc82bd 100644 --- a/README.md +++ b/README.md @@ -1091,6 +1091,7 @@ Here is a list of template creators: * Kotlin (Spring Boot): @dr4ke616 * Kotlin (Vertx): @Wooyme * Kotlin (JAX-RS): @anttileppa + * Kotlin WireMock: @stefankoppier * NodeJS Express: @YishTish * PHP Flight: @daniel-sc * PHP Laravel: @renepardon diff --git a/bin/configs/kotlin-wiremock-echo-api.yaml b/bin/configs/kotlin-wiremock-echo-api.yaml new file mode 100644 index 000000000000..5230b295075a --- /dev/null +++ b/bin/configs/kotlin-wiremock-echo-api.yaml @@ -0,0 +1,4 @@ +generatorName: kotlin-wiremock +outputDir: samples/server/echo_api/kotlin-wiremock +inputSpec: modules/openapi-generator/src/test/resources/3_0/kotlin/echo_api.yaml +templateDir: modules/openapi-generator/src/main/resources/kotlin-wiremock diff --git a/bin/configs/kotlin-wiremock.yaml b/bin/configs/kotlin-wiremock.yaml new file mode 100644 index 000000000000..0e63dfe3cc41 --- /dev/null +++ b/bin/configs/kotlin-wiremock.yaml @@ -0,0 +1,4 @@ +generatorName: kotlin-wiremock +outputDir: samples/server/petstore/kotlin-wiremock +inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml +templateDir: modules/openapi-generator/src/main/resources/kotlin-wiremock diff --git a/docs/generators.md b/docs/generators.md index 16a044f8d86d..bb058761aea1 100644 --- a/docs/generators.md +++ b/docs/generators.md @@ -120,6 +120,7 @@ The following generators are available: * [kotlin-server](generators/kotlin-server.md) * [kotlin-spring](generators/kotlin-spring.md) * [kotlin-vertx (beta)](generators/kotlin-vertx.md) +* [kotlin-wiremock (beta)](generators/kotlin-wiremock.md) * [nodejs-express-server (beta)](generators/nodejs-express-server.md) * [php-flight (experimental)](generators/php-flight.md) * [php-laravel](generators/php-laravel.md) diff --git a/docs/generators/java-wiremock.md b/docs/generators/java-wiremock.md index 1ae178f9927c..081a1296745e 100644 --- a/docs/generators/java-wiremock.md +++ b/docs/generators/java-wiremock.md @@ -11,7 +11,7 @@ title: Documentation for the java-wiremock Generator | generator type | SERVER | | | generator language | Java | | | generator default templating engine | mustache | | -| helpTxt | Generates Java Wiremock stubs, requests and responses samples. | | +| helpTxt | Generates Java WireMock stubs, requests and responses samples. | | ## CONFIG OPTIONS These options may be applied as additional-properties (cli) or configOptions (plugins). Refer to [configuration docs](https://openapi-generator.tech/docs/configuration) for more details. diff --git a/docs/generators/kotlin-wiremock.md b/docs/generators/kotlin-wiremock.md new file mode 100644 index 000000000000..c836ebc7f23b --- /dev/null +++ b/docs/generators/kotlin-wiremock.md @@ -0,0 +1,277 @@ +--- +title: Documentation for the kotlin-wiremock Generator +--- + +## METADATA + +| Property | Value | Notes | +| -------- | ----- | ----- | +| generator name | kotlin-wiremock | pass this to the generate command after -g | +| generator stability | BETA | | +| generator type | SERVER | | +| generator language | Kotlin | | +| generator default templating engine | mustache | | +| helpTxt | Generates Kotlin WireMock stub request and response samples. | | + +## CONFIG OPTIONS +These options may be applied as additional-properties (cli) or configOptions (plugins). Refer to [configuration docs](https://openapi-generator.tech/docs/configuration) for more details. + +| Option | Description | Values | Default | +| ------ | ----------- | ------ | ------- | +|additionalModelTypeAnnotations|Additional annotations for model type(class level annotations). List separated by semicolon(;) or new line (Linux or Windows)| |null| +|apiSuffix|suffix for api classes| |Api| +|artifactId|Generated artifact id (name of jar).| |null| +|artifactVersion|Generated artifact's package version.| |1.0.0| +|enumPropertyNaming|Naming convention for enum properties: 'camelCase', 'PascalCase', 'snake_case', 'UPPERCASE', and 'original'| |original| +|groupId|Generated artifact package's organization (i.e. maven groupId).| |org.openapitools| +|modelMutable|Create mutable models| |false| +|packageName|Generated artifact package name.| |org.openapitools| +|parcelizeModels|toggle "@Parcelize" for generated models| |null| +|serializableModel|boolean - toggle "implements Serializable" for generated models| |null| +|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |null| +|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |null| +|sourceFolder|source folder for generated code| |src/main/kotlin| + +## IMPORT MAPPING + +| Type/Alias | Imports | +| ---------- | ------- | +|BigDecimal|java.math.BigDecimal| +|Date|java.time.LocalDate| +|DateTime|java.time.OffsetDateTime| +|File|java.io.File| +|LocalDate|java.time.LocalDate| +|LocalDateTime|java.time.LocalDateTime| +|LocalTime|java.time.LocalTime| +|Timestamp|java.sql.Timestamp| +|URI|java.net.URI| +|UUID|java.util.UUID| + + +## INSTANTIATION TYPES + +| Type/Alias | Instantiated By | +| ---------- | --------------- | +|array|kotlin.collections.ArrayList| +|list|kotlin.collections.ArrayList| +|map|kotlin.collections.HashMap| + + +## LANGUAGE PRIMITIVES + + + +## RESERVED WORDS + + + +## FEATURE SET + + +### Client Modification Feature +| Name | Supported | Defined By | +| ---- | --------- | ---------- | +|BasePath|✗|ToolingExtension +|Authorizations|✗|ToolingExtension +|UserAgent|✗|ToolingExtension +|MockServer|✗|ToolingExtension + +### Data Type Feature +| Name | Supported | Defined By | +| ---- | --------- | ---------- | +|Custom|✗|OAS2,OAS3 +|Int32|✓|OAS2,OAS3 +|Int64|✓|OAS2,OAS3 +|Float|✓|OAS2,OAS3 +|Double|✓|OAS2,OAS3 +|Decimal|✓|ToolingExtension +|String|✓|OAS2,OAS3 +|Byte|✓|OAS2,OAS3 +|Binary|✓|OAS2,OAS3 +|Boolean|✓|OAS2,OAS3 +|Date|✓|OAS2,OAS3 +|DateTime|✓|OAS2,OAS3 +|Password|✓|OAS2,OAS3 +|File|✓|OAS2 +|Uuid|✗| +|Array|✓|OAS2,OAS3 +|Null|✗|OAS3 +|AnyType|✗|OAS2,OAS3 +|Object|✓|OAS2,OAS3 +|Maps|✓|ToolingExtension +|CollectionFormat|✓|OAS2 +|CollectionFormatMulti|✓|OAS2 +|Enum|✓|OAS2,OAS3 +|ArrayOfEnum|✓|ToolingExtension +|ArrayOfModel|✓|ToolingExtension +|ArrayOfCollectionOfPrimitives|✓|ToolingExtension +|ArrayOfCollectionOfModel|✓|ToolingExtension +|ArrayOfCollectionOfEnum|✓|ToolingExtension +|MapOfEnum|✓|ToolingExtension +|MapOfModel|✓|ToolingExtension +|MapOfCollectionOfPrimitives|✓|ToolingExtension +|MapOfCollectionOfModel|✓|ToolingExtension +|MapOfCollectionOfEnum|✓|ToolingExtension + +### Documentation Feature +| Name | Supported | Defined By | +| ---- | --------- | ---------- | +|Readme|✗|ToolingExtension +|Model|✓|ToolingExtension +|Api|✓|ToolingExtension + +### Global Feature +| Name | Supported | Defined By | +| ---- | --------- | ---------- | +|Host|✓|OAS2,OAS3 +|BasePath|✓|OAS2,OAS3 +|Info|✓|OAS2,OAS3 +|Schemes|✗|OAS2,OAS3 +|PartialSchemes|✓|OAS2,OAS3 +|Consumes|✓|OAS2 +|Produces|✓|OAS2 +|ExternalDocumentation|✓|OAS2,OAS3 +|Examples|✓|OAS2,OAS3 +|XMLStructureDefinitions|✗|OAS2,OAS3 +|MultiServer|✗|OAS3 +|ParameterizedServer|✗|OAS3 +|ParameterStyling|✗|OAS3 +|Callbacks|✓|OAS3 +|LinkObjects|✗|OAS3 + +### Parameter Feature +| Name | Supported | Defined By | +| ---- | --------- | ---------- | +|Path|✓|OAS2,OAS3 +|Query|✓|OAS2,OAS3 +|Header|✓|OAS2,OAS3 +|Body|✓|OAS2 +|FormUnencoded|✓|OAS2 +|FormMultipart|✓|OAS2 +|Cookie|✓|OAS3 + +### Schema Support Feature +| Name | Supported | Defined By | +| ---- | --------- | ---------- | +|Simple|✓|OAS2,OAS3 +|Composite|✓|OAS2,OAS3 +|Polymorphism|✓|OAS2,OAS3 +|Union|✗|OAS3 +|allOf|✗|OAS2,OAS3 +|anyOf|✗|OAS3 +|oneOf|✗|OAS3 +|not|✗|OAS3 + +### Security Feature +| Name | Supported | Defined By | +| ---- | --------- | ---------- | +|BasicAuth|✓|OAS2,OAS3 +|ApiKey|✓|OAS2,OAS3 +|OpenIDConnect|✗|OAS3 +|BearerToken|✓|OAS3 +|OAuth2_Implicit|✓|OAS2,OAS3 +|OAuth2_Password|✓|OAS2,OAS3 +|OAuth2_ClientCredentials|✓|OAS2,OAS3 +|OAuth2_AuthorizationCode|✓|OAS2,OAS3 +|SignatureAuth|✗|OAS3 +|AWSV4Signature|✗|ToolingExtension + +### Wire Format Feature +| Name | Supported | Defined By | +| ---- | --------- | ---------- | +|JSON|✓|OAS2,OAS3 +|XML|✓|OAS2,OAS3 +|PROTOBUF|✗|ToolingExtension +|Custom|✗|OAS2,OAS3 diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractKotlinCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractKotlinCodegen.java index 9485bb2dd7ee..599236a2b820 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractKotlinCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractKotlinCodegen.java @@ -767,7 +767,7 @@ public String toOperationId(String operationId) { // operationId starts with a number if (operationId.matches("^\\d.*")) { - LOGGER.warn(operationId + " (starting with a number) cannot be used as method sname. Renamed to " + camelize("call_" + operationId), LOWERCASE_FIRST_LETTER); + LOGGER.warn(operationId + " (starting with a number) cannot be used as method name. Renamed to " + camelize("call_" + operationId), LOWERCASE_FIRST_LETTER); operationId = camelize("call_" + operationId, LOWERCASE_FIRST_LETTER); } diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaWiremockServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaWiremockServerCodegen.java index d2433483c654..8cb6eebaa7fe 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaWiremockServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaWiremockServerCodegen.java @@ -23,7 +23,7 @@ public String getName() { } public String getHelp() { - return "Generates Java Wiremock stubs, requests and responses samples."; + return "Generates Java WireMock stubs, requests and responses samples."; } public JavaWiremockServerCodegen() { 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 new file mode 100644 index 000000000000..2de5bda7e1fd --- /dev/null +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinWiremockServerCodegen.java @@ -0,0 +1,138 @@ +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 org.openapitools.codegen.meta.GeneratorMetadata; +import org.openapitools.codegen.meta.Stability; +import org.openapitools.codegen.meta.features.GlobalFeature; +import org.openapitools.codegen.meta.features.ParameterFeature; +import org.openapitools.codegen.meta.features.SecurityFeature; +import org.openapitools.codegen.meta.features.WireFormatFeature; +import org.openapitools.codegen.model.ModelMap; +import org.openapitools.codegen.model.ModelsMap; + +import java.io.File; +import java.util.EnumSet; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class KotlinWiremockServerCodegen extends AbstractKotlinCodegen { + + protected static final String VENDOR_EXTENSION_BASE_NAME_LITERAL = "x-base-name-literal"; + + @Override + public CodegenType getTag() { + return CodegenType.SERVER; + } + + @Override + public String getName() { + return "kotlin-wiremock"; + } + + @Override + public String getHelp() { + return "Generates Kotlin WireMock stub request and response samples."; + } + + public KotlinWiremockServerCodegen() { + super(); + + generatorMetadata = GeneratorMetadata.newBuilder(generatorMetadata) + .stability(Stability.BETA) + .build(); + + setArtifactId("kotlin-wiremock"); + setApiPackage(packageName + ".apis"); + setModelPackage(packageName + ".models"); + } + + @Override + public void processOpts() { + super.processOpts(); + + modifyFeatureSet(features -> features + .securityFeatures(EnumSet.allOf(SecurityFeature.class)) + .excludeWireFormatFeatures( + WireFormatFeature.XML, + WireFormatFeature.PROTOBUF + ) + .excludeGlobalFeatures( + GlobalFeature.XMLStructureDefinitions, + GlobalFeature.Callbacks, + GlobalFeature.LinkObjects + ) + .excludeParameterFeatures( + ParameterFeature.Cookie + ) + ); + + typeMapping.put("array", "kotlin.collections.List"); + + reservedWords.remove("ApiResponse"); + + additionalProperties.put(CodegenConstants.API_PACKAGE, apiPackage()); + additionalProperties.put(CodegenConstants.MODEL_PACKAGE, modelPackage()); + + apiTemplateFiles.put("api-stub.mustache", "Stubs.kt"); + apiTemplateFiles.put("api-stub-builder.mustache", "StubBuilders.kt"); + + modelTemplateFiles.put("model.mustache", ".kt"); + + supportingFiles.addAll(List.of( + new SupportingFile("build.gradle.kts.mustache", "", "build.gradle.kts"), + new SupportingFile("settings.gradle.kts.mustache", "", "settings.gradle.kts"), + new SupportingFile("libs.versions.toml.mustache", "gradle", "libs.versions.toml"), + new SupportingFile("gradlew.mustache", "", "gradlew"), + new SupportingFile("gradlew.bat.mustache", "", "gradlew.bat"), + new SupportingFile("gradle-wrapper.properties.mustache", "gradle" + File.separator + "wrapper", "gradle-wrapper.properties"), + new SupportingFile("gradle-wrapper.jar", "gradle" + File.separator + "wrapper", "gradle-wrapper.jar") + ) + ); + + supportingFiles.add( + new SupportingFile(".gitignore.mustache", "", ".gitignore") + ); + } + + @Override + public ModelsMap postProcessModels(ModelsMap objs) { + var objects = super.postProcessModels(objs); + + for (ModelMap model : objects.getModels()) { + var cm = model.getModel(); + var vars = Stream.of( + cm.vars, + cm.allVars, + cm.optionalVars, + cm.requiredVars, + cm.readOnlyVars, + cm.readWriteVars, + cm.parentVars + ) + .flatMap(List::stream) + .collect(Collectors.toList()); + + for (CodegenProperty var : vars) { + var.vendorExtensions.put(VENDOR_EXTENSION_BASE_NAME_LITERAL, var.baseName.replace("$", "\\$")); + } + } + + return objects; + } + + @Override + public void postProcess() { + System.out.println("################################################################################"); + System.out.println("# Thanks for using OpenAPI Generator. #"); + System.out.println("# Please consider donation to help us maintain this project \uD83D\uDE4F #"); + System.out.println("# https://opencollective.com/openapi_generator/donate #"); + System.out.println("# #"); + System.out.println("# This generator's contributed by Stefan Koppier (https://github.com/stefankoppier)#"); + System.out.println("################################################################################"); + } + +} diff --git a/modules/openapi-generator/src/main/resources/META-INF/services/org.openapitools.codegen.CodegenConfig b/modules/openapi-generator/src/main/resources/META-INF/services/org.openapitools.codegen.CodegenConfig index 8fae8fb9b968..ba2d139af981 100644 --- a/modules/openapi-generator/src/main/resources/META-INF/services/org.openapitools.codegen.CodegenConfig +++ b/modules/openapi-generator/src/main/resources/META-INF/services/org.openapitools.codegen.CodegenConfig @@ -43,6 +43,7 @@ org.openapitools.codegen.languages.KotlinClientCodegen org.openapitools.codegen.languages.KotlinServerCodegen org.openapitools.codegen.languages.KotlinSpringServerCodegen org.openapitools.codegen.languages.KotlinVertxServerCodegen +org.openapitools.codegen.languages.KotlinWiremockServerCodegen org.openapitools.codegen.languages.KtormSchemaCodegen org.openapitools.codegen.languages.HaskellHttpClientCodegen org.openapitools.codegen.languages.HaskellServantCodegen diff --git a/modules/openapi-generator/src/main/resources/kotlin-wiremock/.gitignore.mustache b/modules/openapi-generator/src/main/resources/kotlin-wiremock/.gitignore.mustache new file mode 100644 index 000000000000..2983e3c1db32 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-wiremock/.gitignore.mustache @@ -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/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 new file mode 100644 index 000000000000..ef98a549fe39 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-wiremock/api-stub-builder.mustache @@ -0,0 +1,78 @@ +@file:Suppress( + "RemoveRedundantQualifierName", + "UnusedImport", + "unused", +) + +package {{apiPackage}} + +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 {{modelPackage}}.* + +{{#operations}} +{{#operation}} +/** + * Builder for WireMock stubs of operation {{operationId}}. + */ +class {{operationIdCamelCase}}StubBuilder internal constructor(private val objectMapper: ObjectMapper, private val stub: MappingBuilder) { + {{#responses}} + {{^wildcard}} + + /** + * Let the stub for {{operationId}} respond with HTTP status code {{code}}. + * + {{#returnType}} + * @param body response body for the [MappingBuilder]. + {{/returnType}} + * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @return a [MappingBuilder] to be registered with a WireMock instance. + */ + fun respondWith{{code}}( + {{#returnType}} + body: {{{.}}}, + {{/returnType}} + configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, + ): MappingBuilder = + stub.willReturn(aResponse() + .withStatus({{code}}) + {{#returnType}} + .withHeader("Content-Type", "application/json") + .withBody(objectMapper.writeValueAsString(body)) + {{/returnType}} + .configurer() + ) + {{/wildcard}} + {{/responses}} + + /** + * Let the stub for {{operationId}} respond with HTTP status code [code]. + * + {{#returnType}} + * @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. + */ + 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() + ) +} + +{{/operation}} +{{/operations}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-wiremock/api-stub.mustache b/modules/openapi-generator/src/main/resources/kotlin-wiremock/api-stub.mustache new file mode 100644 index 000000000000..804e23134966 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-wiremock/api-stub.mustache @@ -0,0 +1,47 @@ +@file:Suppress( + "RemoveRedundantQualifierName", + "UnusedImport", + "unused", +) + +package {{apiPackage}} + +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 {{modelPackage}}.* + +{{#operations}} +/** + * WireMock stub request builder. + */ +open class {{classname}}Stubs(private val objectMapper: ObjectMapper) { +{{#operation}} + + /** + * Construct a stub for the operation {{operationId}}. + * + {{#pathParams}} + * @param {{paramName}} path parameter {{paramName}} pattern. + {{/pathParams}} + {{#queryParams}} + * @param {{paramName}} query parameter {{paramName}} pattern. + {{/queryParams}} + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. + * @return A [{{operationIdCamelCase}}StubBuilder] to configure the response, and the final [MappingBuilder]. + */ + fun {{operationId}}({{#pathParams}}{{paramName}}: StringValuePattern, {{/pathParams}}{{#queryParams}}{{paramName}}: StringValuePattern? = null, {{/queryParams}}configurer: MappingBuilder.() -> MappingBuilder = { this }): {{operationIdCamelCase}}StubBuilder = + {{operationIdCamelCase}}StubBuilder(objectMapper, {{#lambda.lowercase}}{{httpMethod}}{{/lambda.lowercase}}(urlPathTemplate("{{path}}")) + {{#pathParams}} + .withPathParam("{{paramName}}", {{paramName}}) + {{/pathParams}} + {{#queryParams}} + .apply { {{paramName}}?.let { withQueryParam("{{paramName}}", it) } } + {{/queryParams}} + .configurer() + ) +{{/operation}} +} +{{/operations}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-wiremock/build.gradle.kts.mustache b/modules/openapi-generator/src/main/resources/kotlin-wiremock/build.gradle.kts.mustache new file mode 100644 index 000000000000..776d58d1be97 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-wiremock/build.gradle.kts.mustache @@ -0,0 +1,21 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +group = "{{groupId}}" +version = "{{artifactVersion}}" + +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/modules/openapi-generator/src/main/resources/kotlin-wiremock/gradle-wrapper.jar b/modules/openapi-generator/src/main/resources/kotlin-wiremock/gradle-wrapper.jar new file mode 100644 index 000000000000..d64cd4917707 Binary files /dev/null and b/modules/openapi-generator/src/main/resources/kotlin-wiremock/gradle-wrapper.jar differ diff --git a/modules/openapi-generator/src/main/resources/kotlin-wiremock/gradle-wrapper.properties.mustache b/modules/openapi-generator/src/main/resources/kotlin-wiremock/gradle-wrapper.properties.mustache new file mode 100644 index 000000000000..e7646dead063 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-wiremock/gradle-wrapper.properties.mustache @@ -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/modules/openapi-generator/src/main/resources/kotlin-wiremock/gradlew.bat.mustache b/modules/openapi-generator/src/main/resources/kotlin-wiremock/gradlew.bat.mustache new file mode 100644 index 000000000000..9d0ce634cb11 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-wiremock/gradlew.bat.mustache @@ -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/modules/openapi-generator/src/main/resources/kotlin-wiremock/gradlew.mustache b/modules/openapi-generator/src/main/resources/kotlin-wiremock/gradlew.mustache new file mode 100644 index 000000000000..9d0ce634cb11 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-wiremock/gradlew.mustache @@ -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/modules/openapi-generator/src/main/resources/kotlin-wiremock/libs.versions.toml.mustache b/modules/openapi-generator/src/main/resources/kotlin-wiremock/libs.versions.toml.mustache new file mode 100644 index 000000000000..23fdd0ddbc19 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-wiremock/libs.versions.toml.mustache @@ -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/modules/openapi-generator/src/main/resources/kotlin-wiremock/model.mustache b/modules/openapi-generator/src/main/resources/kotlin-wiremock/model.mustache new file mode 100644 index 000000000000..c060ec50935c --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-wiremock/model.mustache @@ -0,0 +1,33 @@ +@file:Suppress( + "RemoveRedundantQualifierName", + "unused", +) + +package {{modelPackage}} + +import com.fasterxml.jackson.annotation.JsonProperty + +{{#models}} +{{#model}} +{{#isEnum}} +enum class {{classname}} { + {{#allowableValues}} + {{#enumVars}} + @JsonProperty(value = {{#lambda.doublequote}}{{{value}}}{{/lambda.doublequote}}) {{&name}}, + {{/enumVars}} + {{/allowableValues}} +} +{{/isEnum}} +{{^isEnum}} +data class {{classname}}( + {{#allVars}} + @field:JsonProperty("{{{vendorExtensions.x-base-name-literal}}}") + val {{{name}}}: {{{dataType}}}{{^required}}?{{/required}}{{! + !}}{{^required}} = {{^defaultValue}}null{{/defaultValue}}{{#defaultValue}}{{{.}}}{{/defaultValue}}{{/required}}{{! + }}{{#required}}{{#defaultValue}} = {{{.}}}{{/defaultValue}}{{/required}}, + + {{/allVars}} +) +{{/isEnum}} +{{/model}} +{{/models}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/kotlin-wiremock/settings.gradle.kts.mustache b/modules/openapi-generator/src/main/resources/kotlin-wiremock/settings.gradle.kts.mustache new file mode 100644 index 000000000000..25e0c476492c --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-wiremock/settings.gradle.kts.mustache @@ -0,0 +1,7 @@ +rootProject.name = "{{artifactId}}" + +dependencyResolutionManagement { + repositories { + mavenCentral() + } +} \ No newline at end of file diff --git a/samples/server/echo_api/kotlin-wiremock/.gitignore b/samples/server/echo_api/kotlin-wiremock/.gitignore new file mode 100644 index 000000000000..2983e3c1db32 --- /dev/null +++ b/samples/server/echo_api/kotlin-wiremock/.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/echo_api/kotlin-wiremock/.openapi-generator-ignore b/samples/server/echo_api/kotlin-wiremock/.openapi-generator-ignore new file mode 100644 index 000000000000..7484ee590a38 --- /dev/null +++ b/samples/server/echo_api/kotlin-wiremock/.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/echo_api/kotlin-wiremock/.openapi-generator/FILES b/samples/server/echo_api/kotlin-wiremock/.openapi-generator/FILES new file mode 100644 index 000000000000..762b52754833 --- /dev/null +++ b/samples/server/echo_api/kotlin-wiremock/.openapi-generator/FILES @@ -0,0 +1,29 @@ +.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/AuthApiStubBuilders.kt +src/main/kotlin/org/openapitools/apis/AuthApiStubs.kt +src/main/kotlin/org/openapitools/apis/BodyApiStubBuilders.kt +src/main/kotlin/org/openapitools/apis/BodyApiStubs.kt +src/main/kotlin/org/openapitools/apis/FormApiStubBuilders.kt +src/main/kotlin/org/openapitools/apis/FormApiStubs.kt +src/main/kotlin/org/openapitools/apis/HeaderApiStubBuilders.kt +src/main/kotlin/org/openapitools/apis/HeaderApiStubs.kt +src/main/kotlin/org/openapitools/apis/PathApiStubBuilders.kt +src/main/kotlin/org/openapitools/apis/PathApiStubs.kt +src/main/kotlin/org/openapitools/apis/QueryApiStubBuilders.kt +src/main/kotlin/org/openapitools/apis/QueryApiStubs.kt +src/main/kotlin/org/openapitools/models/Bird.kt +src/main/kotlin/org/openapitools/models/Category.kt +src/main/kotlin/org/openapitools/models/DefaultValue.kt +src/main/kotlin/org/openapitools/models/NumberPropertiesOnly.kt +src/main/kotlin/org/openapitools/models/Pet.kt +src/main/kotlin/org/openapitools/models/Query.kt +src/main/kotlin/org/openapitools/models/StringEnumRef.kt +src/main/kotlin/org/openapitools/models/Tag.kt +src/main/kotlin/org/openapitools/models/TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.kt diff --git a/samples/server/echo_api/kotlin-wiremock/.openapi-generator/VERSION b/samples/server/echo_api/kotlin-wiremock/.openapi-generator/VERSION new file mode 100644 index 000000000000..ecb21862b1ee --- /dev/null +++ b/samples/server/echo_api/kotlin-wiremock/.openapi-generator/VERSION @@ -0,0 +1 @@ +7.6.0-SNAPSHOT diff --git a/samples/server/echo_api/kotlin-wiremock/build.gradle.kts b/samples/server/echo_api/kotlin-wiremock/build.gradle.kts new file mode 100644 index 000000000000..f5d878978f3e --- /dev/null +++ b/samples/server/echo_api/kotlin-wiremock/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/echo_api/kotlin-wiremock/gradle/libs.versions.toml b/samples/server/echo_api/kotlin-wiremock/gradle/libs.versions.toml new file mode 100644 index 000000000000..23fdd0ddbc19 --- /dev/null +++ b/samples/server/echo_api/kotlin-wiremock/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/echo_api/kotlin-wiremock/gradle/wrapper/gradle-wrapper.jar b/samples/server/echo_api/kotlin-wiremock/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 000000000000..d64cd4917707 Binary files /dev/null and b/samples/server/echo_api/kotlin-wiremock/gradle/wrapper/gradle-wrapper.jar differ diff --git a/samples/server/echo_api/kotlin-wiremock/gradle/wrapper/gradle-wrapper.properties b/samples/server/echo_api/kotlin-wiremock/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 000000000000..e7646dead063 --- /dev/null +++ b/samples/server/echo_api/kotlin-wiremock/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/echo_api/kotlin-wiremock/gradlew b/samples/server/echo_api/kotlin-wiremock/gradlew new file mode 100644 index 000000000000..9d0ce634cb11 --- /dev/null +++ b/samples/server/echo_api/kotlin-wiremock/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/echo_api/kotlin-wiremock/gradlew.bat b/samples/server/echo_api/kotlin-wiremock/gradlew.bat new file mode 100644 index 000000000000..9d0ce634cb11 --- /dev/null +++ b/samples/server/echo_api/kotlin-wiremock/gradlew.bat @@ -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/echo_api/kotlin-wiremock/settings.gradle.kts b/samples/server/echo_api/kotlin-wiremock/settings.gradle.kts new file mode 100644 index 000000000000..537908ca655b --- /dev/null +++ b/samples/server/echo_api/kotlin-wiremock/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/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 new file mode 100644 index 000000000000..cccbcd941687 --- /dev/null +++ b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/AuthApiStubBuilders.kt @@ -0,0 +1,109 @@ +@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 testAuthHttpBasic. + */ +class TestAuthHttpBasicStubBuilder internal constructor(private val objectMapper: ObjectMapper, private val stub: MappingBuilder) { + + /** + * 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. + * @return a [MappingBuilder] to be registered with a WireMock instance. + */ + fun respondWith200( + body: kotlin.String, + configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, + ): MappingBuilder = + stub.willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(objectMapper.writeValueAsString(body)) + .configurer() + ) + + /** + * Let the stub for testAuthHttpBasic respond with HTTP status code [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() + ) +} + +/** + * Builder for WireMock stubs of operation testAuthHttpBearer. + */ +class TestAuthHttpBearerStubBuilder internal constructor(private val objectMapper: ObjectMapper, private val stub: MappingBuilder) { + + /** + * 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. + * @return a [MappingBuilder] to be registered with a WireMock instance. + */ + fun respondWith200( + body: kotlin.String, + configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, + ): MappingBuilder = + stub.willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(objectMapper.writeValueAsString(body)) + .configurer() + ) + + /** + * Let the stub for testAuthHttpBearer respond with HTTP status code [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/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/AuthApiStubs.kt b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/AuthApiStubs.kt new file mode 100644 index 000000000000..2de65e35b680 --- /dev/null +++ b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/AuthApiStubs.kt @@ -0,0 +1,42 @@ +@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 AuthApiStubs(private val objectMapper: ObjectMapper) { + + /** + * Construct a stub for the operation testAuthHttpBasic. + * + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. + * @return A [TestAuthHttpBasicStubBuilder] to configure the response, and the final [MappingBuilder]. + */ + fun testAuthHttpBasic(configurer: MappingBuilder.() -> MappingBuilder = { this }): TestAuthHttpBasicStubBuilder = + TestAuthHttpBasicStubBuilder(objectMapper, post(urlPathTemplate("/auth/http/basic")) + .configurer() + ) + + /** + * Construct a stub for the operation testAuthHttpBearer. + * + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. + * @return A [TestAuthHttpBearerStubBuilder] to configure the response, and the final [MappingBuilder]. + */ + fun testAuthHttpBearer(configurer: MappingBuilder.() -> MappingBuilder = { this }): TestAuthHttpBearerStubBuilder = + TestAuthHttpBearerStubBuilder(objectMapper, post(urlPathTemplate("/auth/http/bearer")) + .configurer() + ) +} 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 new file mode 100644 index 000000000000..16286fdec9d7 --- /dev/null +++ b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/BodyApiStubBuilders.kt @@ -0,0 +1,391 @@ +@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 testBinaryGif. + */ +class TestBinaryGifStubBuilder internal constructor(private val objectMapper: ObjectMapper, private val stub: MappingBuilder) { + + /** + * 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. + * @return a [MappingBuilder] to be registered with a WireMock instance. + */ + fun respondWith200( + body: java.io.File, + configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, + ): MappingBuilder = + stub.willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(objectMapper.writeValueAsString(body)) + .configurer() + ) + + /** + * Let the stub for testBinaryGif respond with HTTP status code [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() + ) +} + +/** + * Builder for WireMock stubs of operation testBodyApplicationOctetstreamBinary. + */ +class TestBodyApplicationOctetstreamBinaryStubBuilder internal constructor(private val objectMapper: ObjectMapper, private val stub: MappingBuilder) { + + /** + * 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. + * @return a [MappingBuilder] to be registered with a WireMock instance. + */ + fun respondWith200( + body: kotlin.String, + configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, + ): MappingBuilder = + stub.willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(objectMapper.writeValueAsString(body)) + .configurer() + ) + + /** + * Let the stub for testBodyApplicationOctetstreamBinary respond with HTTP status code [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() + ) +} + +/** + * Builder for WireMock stubs of operation testBodyMultipartFormdataArrayOfBinary. + */ +class TestBodyMultipartFormdataArrayOfBinaryStubBuilder internal constructor(private val objectMapper: ObjectMapper, private val stub: MappingBuilder) { + + /** + * 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. + * @return a [MappingBuilder] to be registered with a WireMock instance. + */ + fun respondWith200( + body: kotlin.String, + configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, + ): MappingBuilder = + stub.willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(objectMapper.writeValueAsString(body)) + .configurer() + ) + + /** + * Let the stub for testBodyMultipartFormdataArrayOfBinary respond with HTTP status code [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() + ) +} + +/** + * Builder for WireMock stubs of operation testBodyMultipartFormdataSingleBinary. + */ +class TestBodyMultipartFormdataSingleBinaryStubBuilder internal constructor(private val objectMapper: ObjectMapper, private val stub: MappingBuilder) { + + /** + * 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. + * @return a [MappingBuilder] to be registered with a WireMock instance. + */ + fun respondWith200( + body: kotlin.String, + configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, + ): MappingBuilder = + stub.willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(objectMapper.writeValueAsString(body)) + .configurer() + ) + + /** + * Let the stub for testBodyMultipartFormdataSingleBinary respond with HTTP status code [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() + ) +} + +/** + * Builder for WireMock stubs of operation testEchoBodyFreeFormObjectResponseString. + */ +class TestEchoBodyFreeFormObjectResponseStringStubBuilder internal constructor(private val objectMapper: ObjectMapper, private val stub: MappingBuilder) { + + /** + * 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. + * @return a [MappingBuilder] to be registered with a WireMock instance. + */ + fun respondWith200( + body: kotlin.String, + configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, + ): MappingBuilder = + stub.willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(objectMapper.writeValueAsString(body)) + .configurer() + ) + + /** + * Let the stub for testEchoBodyFreeFormObjectResponseString respond with HTTP status code [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() + ) +} + +/** + * Builder for WireMock stubs of operation testEchoBodyPet. + */ +class TestEchoBodyPetStubBuilder internal constructor(private val objectMapper: ObjectMapper, private val stub: MappingBuilder) { + + /** + * 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. + * @return a [MappingBuilder] to be registered with a WireMock instance. + */ + fun respondWith200( + body: Pet, + configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, + ): MappingBuilder = + stub.willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(objectMapper.writeValueAsString(body)) + .configurer() + ) + + /** + * Let the stub for testEchoBodyPet respond with HTTP status code [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() + ) +} + +/** + * Builder for WireMock stubs of operation testEchoBodyPetResponseString. + */ +class TestEchoBodyPetResponseStringStubBuilder internal constructor(private val objectMapper: ObjectMapper, private val stub: MappingBuilder) { + + /** + * 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. + * @return a [MappingBuilder] to be registered with a WireMock instance. + */ + fun respondWith200( + body: kotlin.String, + configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, + ): MappingBuilder = + stub.willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(objectMapper.writeValueAsString(body)) + .configurer() + ) + + /** + * Let the stub for testEchoBodyPetResponseString respond with HTTP status code [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() + ) +} + +/** + * Builder for WireMock stubs of operation testEchoBodyTagResponseString. + */ +class TestEchoBodyTagResponseStringStubBuilder internal constructor(private val objectMapper: ObjectMapper, private val stub: MappingBuilder) { + + /** + * 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. + * @return a [MappingBuilder] to be registered with a WireMock instance. + */ + fun respondWith200( + body: kotlin.String, + configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, + ): MappingBuilder = + stub.willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(objectMapper.writeValueAsString(body)) + .configurer() + ) + + /** + * Let the stub for testEchoBodyTagResponseString respond with HTTP status code [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/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/BodyApiStubs.kt b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/BodyApiStubs.kt new file mode 100644 index 000000000000..9a4f49a9ce0b --- /dev/null +++ b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/BodyApiStubs.kt @@ -0,0 +1,108 @@ +@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 BodyApiStubs(private val objectMapper: ObjectMapper) { + + /** + * Construct a stub for the operation testBinaryGif. + * + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. + * @return A [TestBinaryGifStubBuilder] to configure the response, and the final [MappingBuilder]. + */ + fun testBinaryGif(configurer: MappingBuilder.() -> MappingBuilder = { this }): TestBinaryGifStubBuilder = + TestBinaryGifStubBuilder(objectMapper, post(urlPathTemplate("/binary/gif")) + .configurer() + ) + + /** + * Construct a stub for the operation testBodyApplicationOctetstreamBinary. + * + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. + * @return A [TestBodyApplicationOctetstreamBinaryStubBuilder] to configure the response, and the final [MappingBuilder]. + */ + fun testBodyApplicationOctetstreamBinary(configurer: MappingBuilder.() -> MappingBuilder = { this }): TestBodyApplicationOctetstreamBinaryStubBuilder = + TestBodyApplicationOctetstreamBinaryStubBuilder(objectMapper, post(urlPathTemplate("/body/application/octetstream/binary")) + .configurer() + ) + + /** + * Construct a stub for the operation testBodyMultipartFormdataArrayOfBinary. + * + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. + * @return A [TestBodyMultipartFormdataArrayOfBinaryStubBuilder] to configure the response, and the final [MappingBuilder]. + */ + fun testBodyMultipartFormdataArrayOfBinary(configurer: MappingBuilder.() -> MappingBuilder = { this }): TestBodyMultipartFormdataArrayOfBinaryStubBuilder = + TestBodyMultipartFormdataArrayOfBinaryStubBuilder(objectMapper, post(urlPathTemplate("/body/application/octetstream/array_of_binary")) + .configurer() + ) + + /** + * Construct a stub for the operation testBodyMultipartFormdataSingleBinary. + * + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. + * @return A [TestBodyMultipartFormdataSingleBinaryStubBuilder] to configure the response, and the final [MappingBuilder]. + */ + fun testBodyMultipartFormdataSingleBinary(configurer: MappingBuilder.() -> MappingBuilder = { this }): TestBodyMultipartFormdataSingleBinaryStubBuilder = + TestBodyMultipartFormdataSingleBinaryStubBuilder(objectMapper, post(urlPathTemplate("/body/application/octetstream/single_binary")) + .configurer() + ) + + /** + * Construct a stub for the operation testEchoBodyFreeFormObjectResponseString. + * + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. + * @return A [TestEchoBodyFreeFormObjectResponseStringStubBuilder] to configure the response, and the final [MappingBuilder]. + */ + fun testEchoBodyFreeFormObjectResponseString(configurer: MappingBuilder.() -> MappingBuilder = { this }): TestEchoBodyFreeFormObjectResponseStringStubBuilder = + TestEchoBodyFreeFormObjectResponseStringStubBuilder(objectMapper, post(urlPathTemplate("/echo/body/FreeFormObject/response_string")) + .configurer() + ) + + /** + * Construct a stub for the operation testEchoBodyPet. + * + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. + * @return A [TestEchoBodyPetStubBuilder] to configure the response, and the final [MappingBuilder]. + */ + fun testEchoBodyPet(configurer: MappingBuilder.() -> MappingBuilder = { this }): TestEchoBodyPetStubBuilder = + TestEchoBodyPetStubBuilder(objectMapper, post(urlPathTemplate("/echo/body/Pet")) + .configurer() + ) + + /** + * Construct a stub for the operation testEchoBodyPetResponseString. + * + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. + * @return A [TestEchoBodyPetResponseStringStubBuilder] to configure the response, and the final [MappingBuilder]. + */ + fun testEchoBodyPetResponseString(configurer: MappingBuilder.() -> MappingBuilder = { this }): TestEchoBodyPetResponseStringStubBuilder = + TestEchoBodyPetResponseStringStubBuilder(objectMapper, post(urlPathTemplate("/echo/body/Pet/response_string")) + .configurer() + ) + + /** + * Construct a stub for the operation testEchoBodyTagResponseString. + * + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. + * @return A [TestEchoBodyTagResponseStringStubBuilder] to configure the response, and the final [MappingBuilder]. + */ + fun testEchoBodyTagResponseString(configurer: MappingBuilder.() -> MappingBuilder = { this }): TestEchoBodyTagResponseStringStubBuilder = + TestEchoBodyTagResponseStringStubBuilder(objectMapper, post(urlPathTemplate("/echo/body/Tag/response_string")) + .configurer() + ) +} 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 new file mode 100644 index 000000000000..a25e427db019 --- /dev/null +++ b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/FormApiStubBuilders.kt @@ -0,0 +1,109 @@ +@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 testFormIntegerBooleanString. + */ +class TestFormIntegerBooleanStringStubBuilder internal constructor(private val objectMapper: ObjectMapper, private val stub: MappingBuilder) { + + /** + * 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. + * @return a [MappingBuilder] to be registered with a WireMock instance. + */ + fun respondWith200( + body: kotlin.String, + configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, + ): MappingBuilder = + stub.willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(objectMapper.writeValueAsString(body)) + .configurer() + ) + + /** + * Let the stub for testFormIntegerBooleanString respond with HTTP status code [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() + ) +} + +/** + * Builder for WireMock stubs of operation testFormOneof. + */ +class TestFormOneofStubBuilder internal constructor(private val objectMapper: ObjectMapper, private val stub: MappingBuilder) { + + /** + * 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. + * @return a [MappingBuilder] to be registered with a WireMock instance. + */ + fun respondWith200( + body: kotlin.String, + configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, + ): MappingBuilder = + stub.willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(objectMapper.writeValueAsString(body)) + .configurer() + ) + + /** + * Let the stub for testFormOneof respond with HTTP status code [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/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/FormApiStubs.kt b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/FormApiStubs.kt new file mode 100644 index 000000000000..d428eadc7b9e --- /dev/null +++ b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/FormApiStubs.kt @@ -0,0 +1,42 @@ +@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 FormApiStubs(private val objectMapper: ObjectMapper) { + + /** + * Construct a stub for the operation testFormIntegerBooleanString. + * + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. + * @return A [TestFormIntegerBooleanStringStubBuilder] to configure the response, and the final [MappingBuilder]. + */ + fun testFormIntegerBooleanString(configurer: MappingBuilder.() -> MappingBuilder = { this }): TestFormIntegerBooleanStringStubBuilder = + TestFormIntegerBooleanStringStubBuilder(objectMapper, post(urlPathTemplate("/form/integer/boolean/string")) + .configurer() + ) + + /** + * Construct a stub for the operation testFormOneof. + * + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. + * @return A [TestFormOneofStubBuilder] to configure the response, and the final [MappingBuilder]. + */ + fun testFormOneof(configurer: MappingBuilder.() -> MappingBuilder = { this }): TestFormOneofStubBuilder = + TestFormOneofStubBuilder(objectMapper, post(urlPathTemplate("/form/oneof")) + .configurer() + ) +} 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 new file mode 100644 index 000000000000..4dbe40addb0a --- /dev/null +++ b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/HeaderApiStubBuilders.kt @@ -0,0 +1,62 @@ +@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 testHeaderIntegerBooleanStringEnums. + */ +class TestHeaderIntegerBooleanStringEnumsStubBuilder internal constructor(private val objectMapper: ObjectMapper, private val stub: MappingBuilder) { + + /** + * 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. + * @return a [MappingBuilder] to be registered with a WireMock instance. + */ + fun respondWith200( + body: kotlin.String, + configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, + ): MappingBuilder = + stub.willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(objectMapper.writeValueAsString(body)) + .configurer() + ) + + /** + * Let the stub for testHeaderIntegerBooleanStringEnums respond with HTTP status code [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/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/HeaderApiStubs.kt b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/HeaderApiStubs.kt new file mode 100644 index 000000000000..3a394fe962e9 --- /dev/null +++ b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/HeaderApiStubs.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 HeaderApiStubs(private val objectMapper: ObjectMapper) { + + /** + * Construct a stub for the operation testHeaderIntegerBooleanStringEnums. + * + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. + * @return A [TestHeaderIntegerBooleanStringEnumsStubBuilder] to configure the response, and the final [MappingBuilder]. + */ + fun testHeaderIntegerBooleanStringEnums(configurer: MappingBuilder.() -> MappingBuilder = { this }): TestHeaderIntegerBooleanStringEnumsStubBuilder = + TestHeaderIntegerBooleanStringEnumsStubBuilder(objectMapper, get(urlPathTemplate("/header/integer/boolean/string/enums")) + .configurer() + ) +} 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 new file mode 100644 index 000000000000..c33be23bb98f --- /dev/null +++ b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/PathApiStubBuilders.kt @@ -0,0 +1,62 @@ +@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 testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath. + */ +class TestsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPathStubBuilder internal constructor(private val objectMapper: ObjectMapper, private val stub: MappingBuilder) { + + /** + * 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. + * @return a [MappingBuilder] to be registered with a WireMock instance. + */ + fun respondWith200( + body: kotlin.String, + configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, + ): MappingBuilder = + stub.willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(objectMapper.writeValueAsString(body)) + .configurer() + ) + + /** + * Let the stub for testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath respond with HTTP status code [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/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/PathApiStubs.kt b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/PathApiStubs.kt new file mode 100644 index 000000000000..011d4e396e0c --- /dev/null +++ b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/PathApiStubs.kt @@ -0,0 +1,39 @@ +@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 PathApiStubs(private val objectMapper: ObjectMapper) { + + /** + * Construct a stub for the operation testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath. + * + * @param pathString path parameter pathString pattern. + * @param pathInteger path parameter pathInteger pattern. + * @param enumNonrefStringPath path parameter enumNonrefStringPath pattern. + * @param enumRefStringPath path parameter enumRefStringPath pattern. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. + * @return A [TestsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPathStubBuilder] to configure the response, and the final [MappingBuilder]. + */ + fun testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath(pathString: StringValuePattern, pathInteger: StringValuePattern, enumNonrefStringPath: StringValuePattern, enumRefStringPath: StringValuePattern, configurer: MappingBuilder.() -> MappingBuilder = { this }): TestsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPathStubBuilder = + TestsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPathStubBuilder(objectMapper, get(urlPathTemplate("/path/string/{path_string}/integer/{path_integer}/{enum_nonref_string_path}/{enum_ref_string_path}")) + .withPathParam("pathString", pathString) + .withPathParam("pathInteger", pathInteger) + .withPathParam("enumNonrefStringPath", enumNonrefStringPath) + .withPathParam("enumRefStringPath", enumRefStringPath) + .configurer() + ) +} 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 new file mode 100644 index 000000000000..77e10817e14c --- /dev/null +++ b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/QueryApiStubBuilders.kt @@ -0,0 +1,297 @@ +@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 testEnumRefString. + */ +class TestEnumRefStringStubBuilder internal constructor(private val objectMapper: ObjectMapper, private val stub: MappingBuilder) { + + /** + * 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. + * @return a [MappingBuilder] to be registered with a WireMock instance. + */ + fun respondWith200( + body: kotlin.String, + configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, + ): MappingBuilder = + stub.willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(objectMapper.writeValueAsString(body)) + .configurer() + ) + + /** + * Let the stub for testEnumRefString respond with HTTP status code [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() + ) +} + +/** + * Builder for WireMock stubs of operation testQueryDatetimeDateString. + */ +class TestQueryDatetimeDateStringStubBuilder internal constructor(private val objectMapper: ObjectMapper, private val stub: MappingBuilder) { + + /** + * 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. + * @return a [MappingBuilder] to be registered with a WireMock instance. + */ + fun respondWith200( + body: kotlin.String, + configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, + ): MappingBuilder = + stub.willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(objectMapper.writeValueAsString(body)) + .configurer() + ) + + /** + * Let the stub for testQueryDatetimeDateString respond with HTTP status code [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() + ) +} + +/** + * Builder for WireMock stubs of operation testQueryIntegerBooleanString. + */ +class TestQueryIntegerBooleanStringStubBuilder internal constructor(private val objectMapper: ObjectMapper, private val stub: MappingBuilder) { + + /** + * 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. + * @return a [MappingBuilder] to be registered with a WireMock instance. + */ + fun respondWith200( + body: kotlin.String, + configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, + ): MappingBuilder = + stub.willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(objectMapper.writeValueAsString(body)) + .configurer() + ) + + /** + * Let the stub for testQueryIntegerBooleanString respond with HTTP status code [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() + ) +} + +/** + * Builder for WireMock stubs of operation testQueryStyleDeepObjectExplodeTrueObject. + */ +class TestQueryStyleDeepObjectExplodeTrueObjectStubBuilder internal constructor(private val objectMapper: ObjectMapper, private val stub: MappingBuilder) { + + /** + * 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. + * @return a [MappingBuilder] to be registered with a WireMock instance. + */ + fun respondWith200( + body: kotlin.String, + configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, + ): MappingBuilder = + stub.willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(objectMapper.writeValueAsString(body)) + .configurer() + ) + + /** + * Let the stub for testQueryStyleDeepObjectExplodeTrueObject respond with HTTP status code [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() + ) +} + +/** + * Builder for WireMock stubs of operation testQueryStyleFormExplodeTrueArrayString. + */ +class TestQueryStyleFormExplodeTrueArrayStringStubBuilder internal constructor(private val objectMapper: ObjectMapper, private val stub: MappingBuilder) { + + /** + * 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. + * @return a [MappingBuilder] to be registered with a WireMock instance. + */ + fun respondWith200( + body: kotlin.String, + configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, + ): MappingBuilder = + stub.willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(objectMapper.writeValueAsString(body)) + .configurer() + ) + + /** + * Let the stub for testQueryStyleFormExplodeTrueArrayString respond with HTTP status code [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() + ) +} + +/** + * Builder for WireMock stubs of operation testQueryStyleFormExplodeTrueObject. + */ +class TestQueryStyleFormExplodeTrueObjectStubBuilder internal constructor(private val objectMapper: ObjectMapper, private val stub: MappingBuilder) { + + /** + * 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. + * @return a [MappingBuilder] to be registered with a WireMock instance. + */ + fun respondWith200( + body: kotlin.String, + configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, + ): MappingBuilder = + stub.willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(objectMapper.writeValueAsString(body)) + .configurer() + ) + + /** + * Let the stub for testQueryStyleFormExplodeTrueObject respond with HTTP status code [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/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/QueryApiStubs.kt b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/QueryApiStubs.kt new file mode 100644 index 000000000000..96f7bf35cb21 --- /dev/null +++ b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/QueryApiStubs.kt @@ -0,0 +1,108 @@ +@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 QueryApiStubs(private val objectMapper: ObjectMapper) { + + /** + * Construct a stub for the operation testEnumRefString. + * + * @param enumNonrefStringQuery query parameter enumNonrefStringQuery pattern. + * @param enumRefStringQuery query parameter enumRefStringQuery pattern. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. + * @return A [TestEnumRefStringStubBuilder] to configure the response, and the final [MappingBuilder]. + */ + fun testEnumRefString(enumNonrefStringQuery: StringValuePattern? = null, enumRefStringQuery: StringValuePattern? = null, configurer: MappingBuilder.() -> MappingBuilder = { this }): TestEnumRefStringStubBuilder = + TestEnumRefStringStubBuilder(objectMapper, get(urlPathTemplate("/query/enum_ref_string")) + .apply { enumNonrefStringQuery?.let { withQueryParam("enumNonrefStringQuery", it) } } + .apply { enumRefStringQuery?.let { withQueryParam("enumRefStringQuery", it) } } + .configurer() + ) + + /** + * Construct a stub for the operation testQueryDatetimeDateString. + * + * @param datetimeQuery query parameter datetimeQuery pattern. + * @param dateQuery query parameter dateQuery pattern. + * @param stringQuery query parameter stringQuery pattern. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. + * @return A [TestQueryDatetimeDateStringStubBuilder] to configure the response, and the final [MappingBuilder]. + */ + fun testQueryDatetimeDateString(datetimeQuery: StringValuePattern? = null, dateQuery: StringValuePattern? = null, stringQuery: StringValuePattern? = null, configurer: MappingBuilder.() -> MappingBuilder = { this }): TestQueryDatetimeDateStringStubBuilder = + TestQueryDatetimeDateStringStubBuilder(objectMapper, get(urlPathTemplate("/query/datetime/date/string")) + .apply { datetimeQuery?.let { withQueryParam("datetimeQuery", it) } } + .apply { dateQuery?.let { withQueryParam("dateQuery", it) } } + .apply { stringQuery?.let { withQueryParam("stringQuery", it) } } + .configurer() + ) + + /** + * Construct a stub for the operation testQueryIntegerBooleanString. + * + * @param integerQuery query parameter integerQuery pattern. + * @param booleanQuery query parameter booleanQuery pattern. + * @param stringQuery query parameter stringQuery pattern. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. + * @return A [TestQueryIntegerBooleanStringStubBuilder] to configure the response, and the final [MappingBuilder]. + */ + fun testQueryIntegerBooleanString(integerQuery: StringValuePattern? = null, booleanQuery: StringValuePattern? = null, stringQuery: StringValuePattern? = null, configurer: MappingBuilder.() -> MappingBuilder = { this }): TestQueryIntegerBooleanStringStubBuilder = + TestQueryIntegerBooleanStringStubBuilder(objectMapper, get(urlPathTemplate("/query/integer/boolean/string")) + .apply { integerQuery?.let { withQueryParam("integerQuery", it) } } + .apply { booleanQuery?.let { withQueryParam("booleanQuery", it) } } + .apply { stringQuery?.let { withQueryParam("stringQuery", it) } } + .configurer() + ) + + /** + * Construct a stub for the operation testQueryStyleDeepObjectExplodeTrueObject. + * + * @param queryObject query parameter queryObject pattern. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. + * @return A [TestQueryStyleDeepObjectExplodeTrueObjectStubBuilder] to configure the response, and the final [MappingBuilder]. + */ + fun testQueryStyleDeepObjectExplodeTrueObject(queryObject: StringValuePattern? = null, configurer: MappingBuilder.() -> MappingBuilder = { this }): TestQueryStyleDeepObjectExplodeTrueObjectStubBuilder = + TestQueryStyleDeepObjectExplodeTrueObjectStubBuilder(objectMapper, get(urlPathTemplate("/query/style_deepObject/explode_true/object")) + .apply { queryObject?.let { withQueryParam("queryObject", it) } } + .configurer() + ) + + /** + * Construct a stub for the operation testQueryStyleFormExplodeTrueArrayString. + * + * @param queryObject query parameter queryObject pattern. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. + * @return A [TestQueryStyleFormExplodeTrueArrayStringStubBuilder] to configure the response, and the final [MappingBuilder]. + */ + fun testQueryStyleFormExplodeTrueArrayString(queryObject: StringValuePattern? = null, configurer: MappingBuilder.() -> MappingBuilder = { this }): TestQueryStyleFormExplodeTrueArrayStringStubBuilder = + TestQueryStyleFormExplodeTrueArrayStringStubBuilder(objectMapper, get(urlPathTemplate("/query/style_form/explode_true/array_string")) + .apply { queryObject?.let { withQueryParam("queryObject", it) } } + .configurer() + ) + + /** + * Construct a stub for the operation testQueryStyleFormExplodeTrueObject. + * + * @param queryObject query parameter queryObject pattern. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. + * @return A [TestQueryStyleFormExplodeTrueObjectStubBuilder] to configure the response, and the final [MappingBuilder]. + */ + fun testQueryStyleFormExplodeTrueObject(queryObject: StringValuePattern? = null, configurer: MappingBuilder.() -> MappingBuilder = { this }): TestQueryStyleFormExplodeTrueObjectStubBuilder = + TestQueryStyleFormExplodeTrueObjectStubBuilder(objectMapper, get(urlPathTemplate("/query/style_form/explode_true/object")) + .apply { queryObject?.let { withQueryParam("queryObject", it) } } + .configurer() + ) +} diff --git a/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/models/Bird.kt b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/models/Bird.kt new file mode 100644 index 000000000000..e98d044343b0 --- /dev/null +++ b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/models/Bird.kt @@ -0,0 +1,17 @@ +@file:Suppress( + "RemoveRedundantQualifierName", + "unused", +) + +package org.openapitools.models + +import com.fasterxml.jackson.annotation.JsonProperty + +data class Bird( + @field:JsonProperty("size") + val propertySize: kotlin.String? = null, + + @field:JsonProperty("color") + val color: kotlin.String? = null, + +) diff --git a/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/models/Category.kt b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/models/Category.kt new file mode 100644 index 000000000000..8904ea0c3b82 --- /dev/null +++ b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/models/Category.kt @@ -0,0 +1,17 @@ +@file:Suppress( + "RemoveRedundantQualifierName", + "unused", +) + +package org.openapitools.models + +import com.fasterxml.jackson.annotation.JsonProperty + +data class Category( + @field:JsonProperty("id") + val id: kotlin.Long? = null, + + @field:JsonProperty("name") + val name: kotlin.String? = null, + +) diff --git a/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/models/DefaultValue.kt b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/models/DefaultValue.kt new file mode 100644 index 000000000000..f99343080101 --- /dev/null +++ b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/models/DefaultValue.kt @@ -0,0 +1,35 @@ +@file:Suppress( + "RemoveRedundantQualifierName", + "unused", +) + +package org.openapitools.models + +import com.fasterxml.jackson.annotation.JsonProperty + +data class DefaultValue( + @field:JsonProperty("array_string_enum_ref_default") + val arrayStringEnumRefDefault: kotlin.collections.List? = null, + + @field:JsonProperty("array_string_enum_default") + val arrayStringEnumDefault: kotlin.collections.List? = null, + + @field:JsonProperty("array_string_default") + val arrayStringDefault: kotlin.collections.List? = arrayListOf("failure","skipped"), + + @field:JsonProperty("array_integer_default") + val arrayIntegerDefault: kotlin.collections.List? = arrayListOf(1,3), + + @field:JsonProperty("array_string") + val arrayString: kotlin.collections.List? = null, + + @field:JsonProperty("array_string_nullable") + val arrayStringNullable: kotlin.collections.List? = null, + + @field:JsonProperty("array_string_extension_nullable") + val arrayStringExtensionNullable: kotlin.collections.List? = null, + + @field:JsonProperty("string_nullable") + val stringNullable: kotlin.String? = null, + +) diff --git a/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/models/NumberPropertiesOnly.kt b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/models/NumberPropertiesOnly.kt new file mode 100644 index 000000000000..b16a9ec2306d --- /dev/null +++ b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/models/NumberPropertiesOnly.kt @@ -0,0 +1,20 @@ +@file:Suppress( + "RemoveRedundantQualifierName", + "unused", +) + +package org.openapitools.models + +import com.fasterxml.jackson.annotation.JsonProperty + +data class NumberPropertiesOnly( + @field:JsonProperty("number") + val number: java.math.BigDecimal? = null, + + @field:JsonProperty("float") + val float: kotlin.Float? = null, + + @field:JsonProperty("double") + val double: kotlin.Double? = null, + +) diff --git a/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/models/Pet.kt b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/models/Pet.kt new file mode 100644 index 000000000000..2498edf60525 --- /dev/null +++ b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/models/Pet.kt @@ -0,0 +1,29 @@ +@file:Suppress( + "RemoveRedundantQualifierName", + "unused", +) + +package org.openapitools.models + +import com.fasterxml.jackson.annotation.JsonProperty + +data class Pet( + @field:JsonProperty("name") + val name: kotlin.String, + + @field:JsonProperty("photoUrls") + val photoUrls: kotlin.collections.List, + + @field:JsonProperty("id") + val id: kotlin.Long? = null, + + @field:JsonProperty("category") + val category: Category? = null, + + @field:JsonProperty("tags") + val tags: kotlin.collections.List? = null, + + @field:JsonProperty("status") + val status: kotlin.String? = null, + +) diff --git a/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/models/Query.kt b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/models/Query.kt new file mode 100644 index 000000000000..77b111d9042d --- /dev/null +++ b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/models/Query.kt @@ -0,0 +1,17 @@ +@file:Suppress( + "RemoveRedundantQualifierName", + "unused", +) + +package org.openapitools.models + +import com.fasterxml.jackson.annotation.JsonProperty + +data class Query( + @field:JsonProperty("id") + val id: kotlin.Long? = null, + + @field:JsonProperty("outcomes") + val outcomes: kotlin.collections.List? = null, + +) diff --git a/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/models/StringEnumRef.kt b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/models/StringEnumRef.kt new file mode 100644 index 000000000000..8c89d4f7f8df --- /dev/null +++ b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/models/StringEnumRef.kt @@ -0,0 +1,14 @@ +@file:Suppress( + "RemoveRedundantQualifierName", + "unused", +) + +package org.openapitools.models + +import com.fasterxml.jackson.annotation.JsonProperty + +enum class StringEnumRef { + @JsonProperty(value = "success") success, + @JsonProperty(value = "failure") failure, + @JsonProperty(value = "unclassified") unclassified, +} diff --git a/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/models/Tag.kt b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/models/Tag.kt new file mode 100644 index 000000000000..b1b72f4cd188 --- /dev/null +++ b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/models/Tag.kt @@ -0,0 +1,17 @@ +@file:Suppress( + "RemoveRedundantQualifierName", + "unused", +) + +package org.openapitools.models + +import com.fasterxml.jackson.annotation.JsonProperty + +data class Tag( + @field:JsonProperty("id") + val id: kotlin.Long? = null, + + @field:JsonProperty("name") + val name: kotlin.String? = null, + +) diff --git a/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/models/TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.kt b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/models/TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.kt new file mode 100644 index 000000000000..4f541fb34589 --- /dev/null +++ b/samples/server/echo_api/kotlin-wiremock/src/main/kotlin/org/openapitools/models/TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter.kt @@ -0,0 +1,14 @@ +@file:Suppress( + "RemoveRedundantQualifierName", + "unused", +) + +package org.openapitools.models + +import com.fasterxml.jackson.annotation.JsonProperty + +data class TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter( + @field:JsonProperty("values") + val propertyValues: kotlin.collections.List? = null, + +) diff --git a/samples/server/petstore/kotlin-wiremock/.gitignore b/samples/server/petstore/kotlin-wiremock/.gitignore new file mode 100644 index 000000000000..2983e3c1db32 --- /dev/null +++ b/samples/server/petstore/kotlin-wiremock/.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/.openapi-generator-ignore b/samples/server/petstore/kotlin-wiremock/.openapi-generator-ignore new file mode 100644 index 000000000000..7484ee590a38 --- /dev/null +++ b/samples/server/petstore/kotlin-wiremock/.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/.openapi-generator/FILES b/samples/server/petstore/kotlin-wiremock/.openapi-generator/FILES new file mode 100644 index 000000000000..20ae24df3871 --- /dev/null +++ b/samples/server/petstore/kotlin-wiremock/.openapi-generator/FILES @@ -0,0 +1,20 @@ +.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/PetApiStubBuilders.kt +src/main/kotlin/org/openapitools/apis/PetApiStubs.kt +src/main/kotlin/org/openapitools/apis/StoreApiStubBuilders.kt +src/main/kotlin/org/openapitools/apis/StoreApiStubs.kt +src/main/kotlin/org/openapitools/apis/UserApiStubBuilders.kt +src/main/kotlin/org/openapitools/apis/UserApiStubs.kt +src/main/kotlin/org/openapitools/models/ApiResponse.kt +src/main/kotlin/org/openapitools/models/Category.kt +src/main/kotlin/org/openapitools/models/Order.kt +src/main/kotlin/org/openapitools/models/Pet.kt +src/main/kotlin/org/openapitools/models/Tag.kt +src/main/kotlin/org/openapitools/models/User.kt diff --git a/samples/server/petstore/kotlin-wiremock/.openapi-generator/VERSION b/samples/server/petstore/kotlin-wiremock/.openapi-generator/VERSION new file mode 100644 index 000000000000..ecb21862b1ee --- /dev/null +++ b/samples/server/petstore/kotlin-wiremock/.openapi-generator/VERSION @@ -0,0 +1 @@ +7.6.0-SNAPSHOT diff --git a/samples/server/petstore/kotlin-wiremock/build.gradle.kts b/samples/server/petstore/kotlin-wiremock/build.gradle.kts new file mode 100644 index 000000000000..f5d878978f3e --- /dev/null +++ b/samples/server/petstore/kotlin-wiremock/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/gradle/libs.versions.toml b/samples/server/petstore/kotlin-wiremock/gradle/libs.versions.toml new file mode 100644 index 000000000000..23fdd0ddbc19 --- /dev/null +++ b/samples/server/petstore/kotlin-wiremock/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/gradle/wrapper/gradle-wrapper.jar b/samples/server/petstore/kotlin-wiremock/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 000000000000..d64cd4917707 Binary files /dev/null and b/samples/server/petstore/kotlin-wiremock/gradle/wrapper/gradle-wrapper.jar differ diff --git a/samples/server/petstore/kotlin-wiremock/gradle/wrapper/gradle-wrapper.properties b/samples/server/petstore/kotlin-wiremock/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 000000000000..e7646dead063 --- /dev/null +++ b/samples/server/petstore/kotlin-wiremock/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/gradlew b/samples/server/petstore/kotlin-wiremock/gradlew new file mode 100644 index 000000000000..9d0ce634cb11 --- /dev/null +++ b/samples/server/petstore/kotlin-wiremock/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/gradlew.bat b/samples/server/petstore/kotlin-wiremock/gradlew.bat new file mode 100644 index 000000000000..9d0ce634cb11 --- /dev/null +++ b/samples/server/petstore/kotlin-wiremock/gradlew.bat @@ -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/settings.gradle.kts b/samples/server/petstore/kotlin-wiremock/settings.gradle.kts new file mode 100644 index 000000000000..537908ca655b --- /dev/null +++ b/samples/server/petstore/kotlin-wiremock/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/src/main/kotlin/org/openapitools/apis/PetApiStubBuilders.kt b/samples/server/petstore/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/PetApiStubBuilders.kt new file mode 100644 index 000000000000..429cb65a3ce5 --- /dev/null +++ b/samples/server/petstore/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/PetApiStubBuilders.kt @@ -0,0 +1,525 @@ +@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 addPet. + */ +class AddPetStubBuilder internal constructor(private val objectMapper: ObjectMapper, private val stub: MappingBuilder) { + + /** + * 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. + * @return a [MappingBuilder] to be registered with a WireMock instance. + */ + fun respondWith200( + body: Pet, + configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, + ): MappingBuilder = + stub.willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(objectMapper.writeValueAsString(body)) + .configurer() + ) + + /** + * 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. + * @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 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() + ) +} + +/** + * Builder for WireMock stubs of operation deletePet. + */ +class DeletePetStubBuilder internal constructor(private val objectMapper: ObjectMapper, private val stub: MappingBuilder) { + + /** + * Let the stub for deletePet respond with HTTP status code 400. + * + * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @return a [MappingBuilder] to be registered with a WireMock instance. + */ + fun respondWith400( + configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, + ): MappingBuilder = + stub.willReturn(aResponse() + .withStatus(400) + .configurer() + ) + + /** + * Let the stub for deletePet respond with HTTP status code [code]. + * + * @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() + ) +} + +/** + * Builder for WireMock stubs of operation findPetsByStatus. + */ +class FindPetsByStatusStubBuilder internal constructor(private val objectMapper: ObjectMapper, private val stub: MappingBuilder) { + + /** + * 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. + * @return a [MappingBuilder] to be registered with a WireMock instance. + */ + fun respondWith200( + body: kotlin.collections.List, + configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, + ): MappingBuilder = + stub.willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(objectMapper.writeValueAsString(body)) + .configurer() + ) + + /** + * 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. + * @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 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() + ) +} + +/** + * Builder for WireMock stubs of operation findPetsByTags. + */ +class FindPetsByTagsStubBuilder internal constructor(private val objectMapper: ObjectMapper, private val stub: MappingBuilder) { + + /** + * 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. + * @return a [MappingBuilder] to be registered with a WireMock instance. + */ + fun respondWith200( + body: kotlin.collections.List, + configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, + ): MappingBuilder = + stub.willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(objectMapper.writeValueAsString(body)) + .configurer() + ) + + /** + * 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. + * @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 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() + ) +} + +/** + * Builder for WireMock stubs of operation getPetById. + */ +class GetPetByIdStubBuilder internal constructor(private val objectMapper: ObjectMapper, private val stub: MappingBuilder) { + + /** + * 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. + * @return a [MappingBuilder] to be registered with a WireMock instance. + */ + fun respondWith200( + body: Pet, + configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, + ): MappingBuilder = + stub.willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(objectMapper.writeValueAsString(body)) + .configurer() + ) + + /** + * 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. + * @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. + * @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 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() + ) +} + +/** + * Builder for WireMock stubs of operation updatePet. + */ +class UpdatePetStubBuilder internal constructor(private val objectMapper: ObjectMapper, private val stub: MappingBuilder) { + + /** + * 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. + * @return a [MappingBuilder] to be registered with a WireMock instance. + */ + fun respondWith200( + body: Pet, + configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, + ): MappingBuilder = + stub.willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(objectMapper.writeValueAsString(body)) + .configurer() + ) + + /** + * 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. + * @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. + * @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. + * @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 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() + ) +} + +/** + * Builder for WireMock stubs of operation updatePetWithForm. + */ +class UpdatePetWithFormStubBuilder internal constructor(private val objectMapper: ObjectMapper, private val stub: MappingBuilder) { + + /** + * Let the stub for updatePetWithForm respond with HTTP status code 405. + * + * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @return a [MappingBuilder] to be registered with a WireMock instance. + */ + fun respondWith405( + configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, + ): MappingBuilder = + stub.willReturn(aResponse() + .withStatus(405) + .configurer() + ) + + /** + * Let the stub for updatePetWithForm respond with HTTP status code [code]. + * + * @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() + ) +} + +/** + * Builder for WireMock stubs of operation uploadFile. + */ +class UploadFileStubBuilder internal constructor(private val objectMapper: ObjectMapper, private val stub: MappingBuilder) { + + /** + * 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. + * @return a [MappingBuilder] to be registered with a WireMock instance. + */ + fun respondWith200( + body: ApiResponse, + configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, + ): MappingBuilder = + stub.willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(objectMapper.writeValueAsString(body)) + .configurer() + ) + + /** + * Let the stub for uploadFile respond with HTTP status code [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/src/main/kotlin/org/openapitools/apis/PetApiStubs.kt b/samples/server/petstore/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/PetApiStubs.kt new file mode 100644 index 000000000000..133e670964ec --- /dev/null +++ b/samples/server/petstore/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/PetApiStubs.kt @@ -0,0 +1,120 @@ +@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 PetApiStubs(private val objectMapper: ObjectMapper) { + + /** + * Construct a stub for the operation addPet. + * + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. + * @return A [AddPetStubBuilder] to configure the response, and the final [MappingBuilder]. + */ + fun addPet(configurer: MappingBuilder.() -> MappingBuilder = { this }): AddPetStubBuilder = + AddPetStubBuilder(objectMapper, post(urlPathTemplate("/pet")) + .configurer() + ) + + /** + * Construct a stub for the operation deletePet. + * + * @param petId path parameter petId pattern. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. + * @return A [DeletePetStubBuilder] to configure the response, and the final [MappingBuilder]. + */ + fun deletePet(petId: StringValuePattern, configurer: MappingBuilder.() -> MappingBuilder = { this }): DeletePetStubBuilder = + DeletePetStubBuilder(objectMapper, delete(urlPathTemplate("/pet/{petId}")) + .withPathParam("petId", petId) + .configurer() + ) + + /** + * Construct a stub for the operation findPetsByStatus. + * + * @param status query parameter status pattern. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. + * @return A [FindPetsByStatusStubBuilder] to configure the response, and the final [MappingBuilder]. + */ + fun findPetsByStatus(status: StringValuePattern? = null, configurer: MappingBuilder.() -> MappingBuilder = { this }): FindPetsByStatusStubBuilder = + FindPetsByStatusStubBuilder(objectMapper, get(urlPathTemplate("/pet/findByStatus")) + .apply { status?.let { withQueryParam("status", it) } } + .configurer() + ) + + /** + * Construct a stub for the operation findPetsByTags. + * + * @param tags query parameter tags pattern. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. + * @return A [FindPetsByTagsStubBuilder] to configure the response, and the final [MappingBuilder]. + */ + fun findPetsByTags(tags: StringValuePattern? = null, configurer: MappingBuilder.() -> MappingBuilder = { this }): FindPetsByTagsStubBuilder = + FindPetsByTagsStubBuilder(objectMapper, get(urlPathTemplate("/pet/findByTags")) + .apply { tags?.let { withQueryParam("tags", it) } } + .configurer() + ) + + /** + * Construct a stub for the operation getPetById. + * + * @param petId path parameter petId pattern. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. + * @return A [GetPetByIdStubBuilder] to configure the response, and the final [MappingBuilder]. + */ + fun getPetById(petId: StringValuePattern, configurer: MappingBuilder.() -> MappingBuilder = { this }): GetPetByIdStubBuilder = + GetPetByIdStubBuilder(objectMapper, get(urlPathTemplate("/pet/{petId}")) + .withPathParam("petId", petId) + .configurer() + ) + + /** + * Construct a stub for the operation updatePet. + * + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. + * @return A [UpdatePetStubBuilder] to configure the response, and the final [MappingBuilder]. + */ + fun updatePet(configurer: MappingBuilder.() -> MappingBuilder = { this }): UpdatePetStubBuilder = + UpdatePetStubBuilder(objectMapper, put(urlPathTemplate("/pet")) + .configurer() + ) + + /** + * Construct a stub for the operation updatePetWithForm. + * + * @param petId path parameter petId pattern. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. + * @return A [UpdatePetWithFormStubBuilder] to configure the response, and the final [MappingBuilder]. + */ + fun updatePetWithForm(petId: StringValuePattern, configurer: MappingBuilder.() -> MappingBuilder = { this }): UpdatePetWithFormStubBuilder = + UpdatePetWithFormStubBuilder(objectMapper, post(urlPathTemplate("/pet/{petId}")) + .withPathParam("petId", petId) + .configurer() + ) + + /** + * Construct a stub for the operation uploadFile. + * + * @param petId path parameter petId pattern. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. + * @return A [UploadFileStubBuilder] to configure the response, and the final [MappingBuilder]. + */ + fun uploadFile(petId: StringValuePattern, configurer: MappingBuilder.() -> MappingBuilder = { this }): UploadFileStubBuilder = + UploadFileStubBuilder(objectMapper, post(urlPathTemplate("/pet/{petId}/uploadImage")) + .withPathParam("petId", petId) + .configurer() + ) +} 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 new file mode 100644 index 000000000000..297a5498bf27 --- /dev/null +++ b/samples/server/petstore/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/StoreApiStubBuilders.kt @@ -0,0 +1,266 @@ +@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 deleteOrder. + */ +class DeleteOrderStubBuilder internal constructor(private val objectMapper: ObjectMapper, private val stub: MappingBuilder) { + + /** + * Let the stub for deleteOrder respond with HTTP status code 400. + * + * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @return a [MappingBuilder] to be registered with a WireMock instance. + */ + fun respondWith400( + configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, + ): MappingBuilder = + stub.willReturn(aResponse() + .withStatus(400) + .configurer() + ) + + /** + * Let the stub for deleteOrder respond with HTTP status code 404. + * + * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @return a [MappingBuilder] to be registered with a WireMock instance. + */ + fun respondWith404( + configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, + ): MappingBuilder = + stub.willReturn(aResponse() + .withStatus(404) + .configurer() + ) + + /** + * Let the stub for deleteOrder respond with HTTP status code [code]. + * + * @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() + ) +} + +/** + * Builder for WireMock stubs of operation getInventory. + */ +class GetInventoryStubBuilder internal constructor(private val objectMapper: ObjectMapper, private val stub: MappingBuilder) { + + /** + * 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. + * @return a [MappingBuilder] to be registered with a WireMock instance. + */ + fun respondWith200( + body: kotlin.collections.Map, + configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, + ): MappingBuilder = + stub.willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(objectMapper.writeValueAsString(body)) + .configurer() + ) + + /** + * Let the stub for getInventory respond with HTTP status code [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() + ) +} + +/** + * Builder for WireMock stubs of operation getOrderById. + */ +class GetOrderByIdStubBuilder internal constructor(private val objectMapper: ObjectMapper, private val stub: MappingBuilder) { + + /** + * 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. + * @return a [MappingBuilder] to be registered with a WireMock instance. + */ + fun respondWith200( + body: Order, + configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, + ): MappingBuilder = + stub.willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(objectMapper.writeValueAsString(body)) + .configurer() + ) + + /** + * 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. + * @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. + * @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 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() + ) +} + +/** + * Builder for WireMock stubs of operation placeOrder. + */ +class PlaceOrderStubBuilder internal constructor(private val objectMapper: ObjectMapper, private val stub: MappingBuilder) { + + /** + * 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. + * @return a [MappingBuilder] to be registered with a WireMock instance. + */ + fun respondWith200( + body: Order, + configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, + ): MappingBuilder = + stub.willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(objectMapper.writeValueAsString(body)) + .configurer() + ) + + /** + * 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. + * @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 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/src/main/kotlin/org/openapitools/apis/StoreApiStubs.kt b/samples/server/petstore/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/StoreApiStubs.kt new file mode 100644 index 000000000000..dc6a53855742 --- /dev/null +++ b/samples/server/petstore/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/StoreApiStubs.kt @@ -0,0 +1,68 @@ +@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 StoreApiStubs(private val objectMapper: ObjectMapper) { + + /** + * Construct a stub for the operation deleteOrder. + * + * @param orderId path parameter orderId pattern. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. + * @return A [DeleteOrderStubBuilder] to configure the response, and the final [MappingBuilder]. + */ + fun deleteOrder(orderId: StringValuePattern, configurer: MappingBuilder.() -> MappingBuilder = { this }): DeleteOrderStubBuilder = + DeleteOrderStubBuilder(objectMapper, delete(urlPathTemplate("/store/order/{orderId}")) + .withPathParam("orderId", orderId) + .configurer() + ) + + /** + * Construct a stub for the operation getInventory. + * + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. + * @return A [GetInventoryStubBuilder] to configure the response, and the final [MappingBuilder]. + */ + fun getInventory(configurer: MappingBuilder.() -> MappingBuilder = { this }): GetInventoryStubBuilder = + GetInventoryStubBuilder(objectMapper, get(urlPathTemplate("/store/inventory")) + .configurer() + ) + + /** + * Construct a stub for the operation getOrderById. + * + * @param orderId path parameter orderId pattern. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. + * @return A [GetOrderByIdStubBuilder] to configure the response, and the final [MappingBuilder]. + */ + fun getOrderById(orderId: StringValuePattern, configurer: MappingBuilder.() -> MappingBuilder = { this }): GetOrderByIdStubBuilder = + GetOrderByIdStubBuilder(objectMapper, get(urlPathTemplate("/store/order/{orderId}")) + .withPathParam("orderId", orderId) + .configurer() + ) + + /** + * Construct a stub for the operation placeOrder. + * + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. + * @return A [PlaceOrderStubBuilder] to configure the response, and the final [MappingBuilder]. + */ + fun placeOrder(configurer: MappingBuilder.() -> MappingBuilder = { this }): PlaceOrderStubBuilder = + PlaceOrderStubBuilder(objectMapper, post(urlPathTemplate("/store/order")) + .configurer() + ) +} 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 new file mode 100644 index 000000000000..817c40844f23 --- /dev/null +++ b/samples/server/petstore/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/UserApiStubBuilders.kt @@ -0,0 +1,387 @@ +@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 createUser. + */ +class CreateUserStubBuilder internal constructor(private val objectMapper: ObjectMapper, private val stub: MappingBuilder) { + + /** + * Let the stub for createUser respond with HTTP status code [code]. + * + * @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() + ) +} + +/** + * Builder for WireMock stubs of operation createUsersWithArrayInput. + */ +class CreateUsersWithArrayInputStubBuilder internal constructor(private val objectMapper: ObjectMapper, private val stub: MappingBuilder) { + + /** + * Let the stub for createUsersWithArrayInput respond with HTTP status code [code]. + * + * @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() + ) +} + +/** + * Builder for WireMock stubs of operation createUsersWithListInput. + */ +class CreateUsersWithListInputStubBuilder internal constructor(private val objectMapper: ObjectMapper, private val stub: MappingBuilder) { + + /** + * Let the stub for createUsersWithListInput respond with HTTP status code [code]. + * + * @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() + ) +} + +/** + * Builder for WireMock stubs of operation deleteUser. + */ +class DeleteUserStubBuilder internal constructor(private val objectMapper: ObjectMapper, private val stub: MappingBuilder) { + + /** + * Let the stub for deleteUser respond with HTTP status code 400. + * + * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @return a [MappingBuilder] to be registered with a WireMock instance. + */ + fun respondWith400( + configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, + ): MappingBuilder = + stub.willReturn(aResponse() + .withStatus(400) + .configurer() + ) + + /** + * Let the stub for deleteUser respond with HTTP status code 404. + * + * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @return a [MappingBuilder] to be registered with a WireMock instance. + */ + fun respondWith404( + configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, + ): MappingBuilder = + stub.willReturn(aResponse() + .withStatus(404) + .configurer() + ) + + /** + * Let the stub for deleteUser respond with HTTP status code [code]. + * + * @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() + ) +} + +/** + * Builder for WireMock stubs of operation getUserByName. + */ +class GetUserByNameStubBuilder internal constructor(private val objectMapper: ObjectMapper, private val stub: MappingBuilder) { + + /** + * 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. + * @return a [MappingBuilder] to be registered with a WireMock instance. + */ + fun respondWith200( + body: User, + configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, + ): MappingBuilder = + stub.willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(objectMapper.writeValueAsString(body)) + .configurer() + ) + + /** + * 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. + * @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. + * @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 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() + ) +} + +/** + * Builder for WireMock stubs of operation loginUser. + */ +class LoginUserStubBuilder internal constructor(private val objectMapper: ObjectMapper, private val stub: MappingBuilder) { + + /** + * 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. + * @return a [MappingBuilder] to be registered with a WireMock instance. + */ + fun respondWith200( + body: kotlin.String, + configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, + ): MappingBuilder = + stub.willReturn(aResponse() + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody(objectMapper.writeValueAsString(body)) + .configurer() + ) + + /** + * 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. + * @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 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() + ) +} + +/** + * Builder for WireMock stubs of operation logoutUser. + */ +class LogoutUserStubBuilder internal constructor(private val objectMapper: ObjectMapper, private val stub: MappingBuilder) { + + /** + * Let the stub for logoutUser respond with HTTP status code [code]. + * + * @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() + ) +} + +/** + * Builder for WireMock stubs of operation updateUser. + */ +class UpdateUserStubBuilder internal constructor(private val objectMapper: ObjectMapper, private val stub: MappingBuilder) { + + /** + * Let the stub for updateUser respond with HTTP status code 400. + * + * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @return a [MappingBuilder] to be registered with a WireMock instance. + */ + fun respondWith400( + configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, + ): MappingBuilder = + stub.willReturn(aResponse() + .withStatus(400) + .configurer() + ) + + /** + * Let the stub for updateUser respond with HTTP status code 404. + * + * @param configurer fonfigurer for the [MappingBuilder], allowing for arbitrary changes. + * @return a [MappingBuilder] to be registered with a WireMock instance. + */ + fun respondWith404( + configurer: ResponseDefinitionBuilder.() -> ResponseDefinitionBuilder = { this }, + ): MappingBuilder = + stub.willReturn(aResponse() + .withStatus(404) + .configurer() + ) + + /** + * Let the stub for updateUser respond with HTTP status code [code]. + * + * @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/src/main/kotlin/org/openapitools/apis/UserApiStubs.kt b/samples/server/petstore/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/UserApiStubs.kt new file mode 100644 index 000000000000..72a458086869 --- /dev/null +++ b/samples/server/petstore/kotlin-wiremock/src/main/kotlin/org/openapitools/apis/UserApiStubs.kt @@ -0,0 +1,118 @@ +@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 UserApiStubs(private val objectMapper: ObjectMapper) { + + /** + * Construct a stub for the operation createUser. + * + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. + * @return A [CreateUserStubBuilder] to configure the response, and the final [MappingBuilder]. + */ + fun createUser(configurer: MappingBuilder.() -> MappingBuilder = { this }): CreateUserStubBuilder = + CreateUserStubBuilder(objectMapper, post(urlPathTemplate("/user")) + .configurer() + ) + + /** + * Construct a stub for the operation createUsersWithArrayInput. + * + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. + * @return A [CreateUsersWithArrayInputStubBuilder] to configure the response, and the final [MappingBuilder]. + */ + fun createUsersWithArrayInput(configurer: MappingBuilder.() -> MappingBuilder = { this }): CreateUsersWithArrayInputStubBuilder = + CreateUsersWithArrayInputStubBuilder(objectMapper, post(urlPathTemplate("/user/createWithArray")) + .configurer() + ) + + /** + * Construct a stub for the operation createUsersWithListInput. + * + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. + * @return A [CreateUsersWithListInputStubBuilder] to configure the response, and the final [MappingBuilder]. + */ + fun createUsersWithListInput(configurer: MappingBuilder.() -> MappingBuilder = { this }): CreateUsersWithListInputStubBuilder = + CreateUsersWithListInputStubBuilder(objectMapper, post(urlPathTemplate("/user/createWithList")) + .configurer() + ) + + /** + * Construct a stub for the operation deleteUser. + * + * @param username path parameter username pattern. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. + * @return A [DeleteUserStubBuilder] to configure the response, and the final [MappingBuilder]. + */ + fun deleteUser(username: StringValuePattern, configurer: MappingBuilder.() -> MappingBuilder = { this }): DeleteUserStubBuilder = + DeleteUserStubBuilder(objectMapper, delete(urlPathTemplate("/user/{username}")) + .withPathParam("username", username) + .configurer() + ) + + /** + * Construct a stub for the operation getUserByName. + * + * @param username path parameter username pattern. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. + * @return A [GetUserByNameStubBuilder] to configure the response, and the final [MappingBuilder]. + */ + fun getUserByName(username: StringValuePattern, configurer: MappingBuilder.() -> MappingBuilder = { this }): GetUserByNameStubBuilder = + GetUserByNameStubBuilder(objectMapper, get(urlPathTemplate("/user/{username}")) + .withPathParam("username", username) + .configurer() + ) + + /** + * Construct a stub for the operation loginUser. + * + * @param username query parameter username pattern. + * @param password query parameter password pattern. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. + * @return A [LoginUserStubBuilder] to configure the response, and the final [MappingBuilder]. + */ + fun loginUser(username: StringValuePattern? = null, password: StringValuePattern? = null, configurer: MappingBuilder.() -> MappingBuilder = { this }): LoginUserStubBuilder = + LoginUserStubBuilder(objectMapper, get(urlPathTemplate("/user/login")) + .apply { username?.let { withQueryParam("username", it) } } + .apply { password?.let { withQueryParam("password", it) } } + .configurer() + ) + + /** + * Construct a stub for the operation logoutUser. + * + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. + * @return A [LogoutUserStubBuilder] to configure the response, and the final [MappingBuilder]. + */ + fun logoutUser(configurer: MappingBuilder.() -> MappingBuilder = { this }): LogoutUserStubBuilder = + LogoutUserStubBuilder(objectMapper, get(urlPathTemplate("/user/logout")) + .configurer() + ) + + /** + * Construct a stub for the operation updateUser. + * + * @param username path parameter username pattern. + * @param configurer configurer for the [MappingBuilder], allowing for arbitrary changes. + * @return A [UpdateUserStubBuilder] to configure the response, and the final [MappingBuilder]. + */ + fun updateUser(username: StringValuePattern, configurer: MappingBuilder.() -> MappingBuilder = { this }): UpdateUserStubBuilder = + UpdateUserStubBuilder(objectMapper, put(urlPathTemplate("/user/{username}")) + .withPathParam("username", username) + .configurer() + ) +} diff --git a/samples/server/petstore/kotlin-wiremock/src/main/kotlin/org/openapitools/models/ApiResponse.kt b/samples/server/petstore/kotlin-wiremock/src/main/kotlin/org/openapitools/models/ApiResponse.kt new file mode 100644 index 000000000000..762ff9aefc91 --- /dev/null +++ b/samples/server/petstore/kotlin-wiremock/src/main/kotlin/org/openapitools/models/ApiResponse.kt @@ -0,0 +1,20 @@ +@file:Suppress( + "RemoveRedundantQualifierName", + "unused", +) + +package org.openapitools.models + +import com.fasterxml.jackson.annotation.JsonProperty + +data class ApiResponse( + @field:JsonProperty("code") + val code: kotlin.Int? = null, + + @field:JsonProperty("type") + val type: kotlin.String? = null, + + @field:JsonProperty("message") + val message: kotlin.String? = null, + +) diff --git a/samples/server/petstore/kotlin-wiremock/src/main/kotlin/org/openapitools/models/Category.kt b/samples/server/petstore/kotlin-wiremock/src/main/kotlin/org/openapitools/models/Category.kt new file mode 100644 index 000000000000..8904ea0c3b82 --- /dev/null +++ b/samples/server/petstore/kotlin-wiremock/src/main/kotlin/org/openapitools/models/Category.kt @@ -0,0 +1,17 @@ +@file:Suppress( + "RemoveRedundantQualifierName", + "unused", +) + +package org.openapitools.models + +import com.fasterxml.jackson.annotation.JsonProperty + +data class Category( + @field:JsonProperty("id") + val id: kotlin.Long? = null, + + @field:JsonProperty("name") + val name: kotlin.String? = null, + +) diff --git a/samples/server/petstore/kotlin-wiremock/src/main/kotlin/org/openapitools/models/Order.kt b/samples/server/petstore/kotlin-wiremock/src/main/kotlin/org/openapitools/models/Order.kt new file mode 100644 index 000000000000..bd5fb1641883 --- /dev/null +++ b/samples/server/petstore/kotlin-wiremock/src/main/kotlin/org/openapitools/models/Order.kt @@ -0,0 +1,29 @@ +@file:Suppress( + "RemoveRedundantQualifierName", + "unused", +) + +package org.openapitools.models + +import com.fasterxml.jackson.annotation.JsonProperty + +data class Order( + @field:JsonProperty("id") + val id: kotlin.Long? = null, + + @field:JsonProperty("petId") + val petId: kotlin.Long? = null, + + @field:JsonProperty("quantity") + val quantity: kotlin.Int? = null, + + @field:JsonProperty("shipDate") + val shipDate: java.time.OffsetDateTime? = null, + + @field:JsonProperty("status") + val status: kotlin.String? = null, + + @field:JsonProperty("complete") + val complete: kotlin.Boolean? = false, + +) diff --git a/samples/server/petstore/kotlin-wiremock/src/main/kotlin/org/openapitools/models/Pet.kt b/samples/server/petstore/kotlin-wiremock/src/main/kotlin/org/openapitools/models/Pet.kt new file mode 100644 index 000000000000..2498edf60525 --- /dev/null +++ b/samples/server/petstore/kotlin-wiremock/src/main/kotlin/org/openapitools/models/Pet.kt @@ -0,0 +1,29 @@ +@file:Suppress( + "RemoveRedundantQualifierName", + "unused", +) + +package org.openapitools.models + +import com.fasterxml.jackson.annotation.JsonProperty + +data class Pet( + @field:JsonProperty("name") + val name: kotlin.String, + + @field:JsonProperty("photoUrls") + val photoUrls: kotlin.collections.List, + + @field:JsonProperty("id") + val id: kotlin.Long? = null, + + @field:JsonProperty("category") + val category: Category? = null, + + @field:JsonProperty("tags") + val tags: kotlin.collections.List? = null, + + @field:JsonProperty("status") + val status: kotlin.String? = null, + +) diff --git a/samples/server/petstore/kotlin-wiremock/src/main/kotlin/org/openapitools/models/Tag.kt b/samples/server/petstore/kotlin-wiremock/src/main/kotlin/org/openapitools/models/Tag.kt new file mode 100644 index 000000000000..b1b72f4cd188 --- /dev/null +++ b/samples/server/petstore/kotlin-wiremock/src/main/kotlin/org/openapitools/models/Tag.kt @@ -0,0 +1,17 @@ +@file:Suppress( + "RemoveRedundantQualifierName", + "unused", +) + +package org.openapitools.models + +import com.fasterxml.jackson.annotation.JsonProperty + +data class Tag( + @field:JsonProperty("id") + val id: kotlin.Long? = null, + + @field:JsonProperty("name") + val name: kotlin.String? = null, + +) diff --git a/samples/server/petstore/kotlin-wiremock/src/main/kotlin/org/openapitools/models/User.kt b/samples/server/petstore/kotlin-wiremock/src/main/kotlin/org/openapitools/models/User.kt new file mode 100644 index 000000000000..1090a716110c --- /dev/null +++ b/samples/server/petstore/kotlin-wiremock/src/main/kotlin/org/openapitools/models/User.kt @@ -0,0 +1,35 @@ +@file:Suppress( + "RemoveRedundantQualifierName", + "unused", +) + +package org.openapitools.models + +import com.fasterxml.jackson.annotation.JsonProperty + +data class User( + @field:JsonProperty("id") + val id: kotlin.Long? = null, + + @field:JsonProperty("username") + val username: kotlin.String? = null, + + @field:JsonProperty("firstName") + val firstName: kotlin.String? = null, + + @field:JsonProperty("lastName") + val lastName: kotlin.String? = null, + + @field:JsonProperty("email") + val email: kotlin.String? = null, + + @field:JsonProperty("password") + val password: kotlin.String? = null, + + @field:JsonProperty("phone") + val phone: kotlin.String? = null, + + @field:JsonProperty("userStatus") + val userStatus: kotlin.Int? = null, + +) diff --git a/samples/server/petstore/kotlin-wiremock/src/test/kotlin/org/openapitools/apis/PetApiStubsTest.kt b/samples/server/petstore/kotlin-wiremock/src/test/kotlin/org/openapitools/apis/PetApiStubsTest.kt new file mode 100644 index 000000000000..2b3bb824e93e --- /dev/null +++ b/samples/server/petstore/kotlin-wiremock/src/test/kotlin/org/openapitools/apis/PetApiStubsTest.kt @@ -0,0 +1,44 @@ +package org.openapitools.apis + +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule +import com.fasterxml.jackson.module.kotlin.kotlinModule +import com.github.tomakehurst.wiremock.client.WireMock.equalTo +import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo +import com.github.tomakehurst.wiremock.junit5.WireMockTest +import org.openapitools.models.Pet +import java.net.URI +import java.net.http.HttpClient +import java.net.http.HttpRequest +import java.net.http.HttpResponse +import kotlin.test.Test +import kotlin.test.assertEquals + +@WireMockTest +class PetApiStubsTest { + + private val objectMapper = ObjectMapper() + .registerModules(JavaTimeModule()) + .registerModules(kotlinModule()) + + private val stubs = PetApiStubs(objectMapper) + + private val client = HttpClient.newBuilder().build() + + @Test + fun `stub and retrieve`(wiremock: WireMockRuntimeInfo) { + val pet = Pet("Pet", emptyList(), null, null, null, null) + + wiremock.wireMock.register( + stubs.getPetById(equalTo("2")).respondWith200(pet) + ) + + val request = HttpRequest.newBuilder(URI.create(wiremock.httpBaseUrl + "/pet/1")) + .GET() + .build() + + val response = client.send(request, HttpResponse.BodyHandlers.ofString()) + + assertEquals(pet, objectMapper.readValue(response.body(), Pet::class.java)) + } +} \ No newline at end of file