Skip to content

Commit

Permalink
[Kotlin Server] Fix problems
Browse files Browse the repository at this point in the history
  • Loading branch information
Stexxe committed Dec 6, 2024
1 parent 8779e1d commit 385e3a4
Show file tree
Hide file tree
Showing 32 changed files with 51 additions and 563 deletions.
1 change: 1 addition & 0 deletions docs/generators/kotlin-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl

| Option | Description | Values | Default |
| ------ | ----------- | ------ | ------- |
|Whether Kotlin serialization should be used|Whether Kotlin serialization should be used| |true|
|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).| |kotlin-server|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public class KotlinServerCodegen extends AbstractKotlinCodegen implements BeanVa
@Getter @Setter
private Boolean compressionFeatureEnabled = true;
@Getter @Setter
private Boolean kotlinSerializationEnabled = true;
@Getter @Setter
private Boolean resourcesFeatureEnabled = true;
@Getter @Setter
private Boolean metricsFeatureEnabled = true;
Expand Down Expand Up @@ -136,6 +138,7 @@ public KotlinServerCodegen() {
addSwitch(Constants.AUTOMATIC_HEAD_REQUESTS, Constants.AUTOMATIC_HEAD_REQUESTS_DESC, getAutoHeadFeatureEnabled());
addSwitch(Constants.CONDITIONAL_HEADERS, Constants.CONDITIONAL_HEADERS_DESC, getConditionalHeadersFeatureEnabled());
addSwitch(Constants.HSTS, Constants.HSTS_DESC, getHstsFeatureEnabled());
addSwitch(Constants.KOTLIN_SERIALIZATION, Constants.KOTLIN_SERIALIZATION, getKotlinSerializationEnabled());
addSwitch(Constants.CORS, Constants.CORS_DESC, getCorsFeatureEnabled());
addSwitch(Constants.COMPRESSION, Constants.COMPRESSION_DESC, getCompressionFeatureEnabled());
addSwitch(Constants.RESOURCES, Constants.RESOURCES_DESC, getResourcesFeatureEnabled());
Expand Down Expand Up @@ -292,6 +295,14 @@ public void processOpts() {
supportingFiles.add(new SupportingFile("gradle.properties", "", "gradle.properties"));

if (isKtor()) {
setKotlinSerializationEnabled(true);

if (additionalProperties.containsKey(Constants.KOTLIN_SERIALIZATION)) {
setKotlinSerializationEnabled(convertPropertyToBooleanAndWriteBack(Constants.KOTLIN_SERIALIZATION));
} else {
additionalProperties.put(Constants.KOTLIN_SERIALIZATION, getKotlinSerializationEnabled());
}

supportingFiles.add(new SupportingFile("AppMain.kt.mustache", packageFolder, "AppMain.kt"));
supportingFiles.add(new SupportingFile("Configuration.kt.mustache", packageFolder, "Configuration.kt"));

Expand Down Expand Up @@ -358,6 +369,7 @@ public static class Constants {
public static final String USE_MUTINY_DESC = "Whether to use Mutiny (should not be used with useCoroutines). This option is currently supported only when using jaxrs-spec library.";
public static final String OMIT_GRADLE_WRAPPER = "omitGradleWrapper";
public static final String OMIT_GRADLE_WRAPPER_DESC = "Whether to omit Gradle wrapper for creating a sub project.";
public static final String KOTLIN_SERIALIZATION = "Whether Kotlin serialization should be used";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
import kotlinx.serialization.Serializable
{{#parcelizeModels}}
import android.os.Parcelable
import kotlinx.parcelize.Parcelize
{{/parcelizeModels}}
{{#serializableModel}}
import java.io.Serializable
{{/serializableModel}}
{{#kotlinSerialization}}
import kotlinx.serialization.Serializable
{{/kotlinSerialization}}
/**
* {{{description}}}
{{#vars}}
* @param {{{name}}} {{{description}}}
{{/vars}}
*/
{{#parcelizeModels}}
@Parcelize
{{/parcelizeModels}}
{{#kotlinSerialization}}
@Serializable
{{/kotlinSerialization}}
{{#hasVars}}data {{/hasVars}}class {{classname}}(
{{#requiredVars}}
{{>data_class_req_var}}{{^-last}},
{{/-last}}{{/requiredVars}}{{#hasRequired}}{{#hasOptional}},
{{/hasOptional}}{{/hasRequired}}{{#optionalVars}}{{>data_class_opt_var}}{{^-last}},
{{/-last}}{{/optionalVars}}
)
){{^serializableModel}}{{#parcelizeModels}} : Parcelable{{/parcelizeModels}}{{/serializableModel}}{{^parcelizeModels}}{{#serializableModel}}: Serializable {{/serializableModel}}{{/parcelizeModels}}{{#parcelizeModels}}{{#serializableModel}} : Parcelable, Serializable {{/serializableModel}}{{/parcelizeModels}}
{{#vendorExtensions.x-has-data-class-body}}
{
{{/vendorExtensions.x-has-data-class-body}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,12 @@ README.md
api/openapi.yaml
build.gradle
build.sbt
docs/AllOfSimpleModel.md
docs/Animal.md
docs/AnyTypeTest.md
docs/ArrayOfSameRef.md
docs/Cat.md
docs/Category.md
docs/CircularReference1.md
docs/CircularReference2.md
docs/CircularReference3.md
docs/CodesEnum.md
docs/DefaultApi.md
docs/Dog.md
docs/FakeApi.md
docs/FakeWebhooksSourcesDeletedPostRequest.md
docs/FakeWebhooksSourcesDeletedPostRequestEvent.md
docs/ModelApiResponse.md
docs/OneOfStringOrInt.md
docs/Order.md
docs/Pet.md
docs/PetApi.md
docs/RefRefToPathLevelParameterOneofRefToOneofParameter.md
docs/RefToRefParameterAnyofRefToAnyofParameter.md
docs/SelfReferenceAdditionalProperties.md
docs/SelfReferenceAnyOf.md
docs/SelfReferenceOneOf.md
docs/SimpleModelWithArrayProperty.md
docs/StoreApi.md
docs/StringOrInt.md
docs/Tag.md
docs/User.md
docs/UserApi.md
Expand All @@ -58,8 +36,6 @@ src/main/java/org/openapitools/client/ProgressResponseBody.java
src/main/java/org/openapitools/client/ServerConfiguration.java
src/main/java/org/openapitools/client/ServerVariable.java
src/main/java/org/openapitools/client/StringUtil.java
src/main/java/org/openapitools/client/api/DefaultApi.java
src/main/java/org/openapitools/client/api/FakeApi.java
src/main/java/org/openapitools/client/api/PetApi.java
src/main/java/org/openapitools/client/api/StoreApi.java
src/main/java/org/openapitools/client/api/UserApi.java
Expand All @@ -72,29 +48,9 @@ src/main/java/org/openapitools/client/auth/OAuthFlow.java
src/main/java/org/openapitools/client/auth/OAuthOkHttpClient.java
src/main/java/org/openapitools/client/auth/RetryingOAuth.java
src/main/java/org/openapitools/client/model/AbstractOpenApiSchema.java
src/main/java/org/openapitools/client/model/AllOfSimpleModel.java
src/main/java/org/openapitools/client/model/Animal.java
src/main/java/org/openapitools/client/model/AnyTypeTest.java
src/main/java/org/openapitools/client/model/ArrayOfSameRef.java
src/main/java/org/openapitools/client/model/Cat.java
src/main/java/org/openapitools/client/model/Category.java
src/main/java/org/openapitools/client/model/CircularReference1.java
src/main/java/org/openapitools/client/model/CircularReference2.java
src/main/java/org/openapitools/client/model/CircularReference3.java
src/main/java/org/openapitools/client/model/CodesEnum.java
src/main/java/org/openapitools/client/model/Dog.java
src/main/java/org/openapitools/client/model/FakeWebhooksSourcesDeletedPostRequest.java
src/main/java/org/openapitools/client/model/FakeWebhooksSourcesDeletedPostRequestEvent.java
src/main/java/org/openapitools/client/model/ModelApiResponse.java
src/main/java/org/openapitools/client/model/OneOfStringOrInt.java
src/main/java/org/openapitools/client/model/Order.java
src/main/java/org/openapitools/client/model/Pet.java
src/main/java/org/openapitools/client/model/RefRefToPathLevelParameterOneofRefToOneofParameter.java
src/main/java/org/openapitools/client/model/RefToRefParameterAnyofRefToAnyofParameter.java
src/main/java/org/openapitools/client/model/SelfReferenceAdditionalProperties.java
src/main/java/org/openapitools/client/model/SelfReferenceAnyOf.java
src/main/java/org/openapitools/client/model/SelfReferenceOneOf.java
src/main/java/org/openapitools/client/model/SimpleModelWithArrayProperty.java
src/main/java/org/openapitools/client/model/StringOrInt.java
src/main/java/org/openapitools/client/model/Tag.java
src/main/java/org/openapitools/client/model/User.java
46 changes: 10 additions & 36 deletions samples/client/petstore/java/okhttp-gson-3.1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,26 @@ Please follow the [installation](#installation) instruction and execute the foll
import org.openapitools.client.ApiClient;
import org.openapitools.client.ApiException;
import org.openapitools.client.Configuration;
import org.openapitools.client.auth.*;
import org.openapitools.client.model.*;
import org.openapitools.client.api.FakeApi;
import org.openapitools.client.api.PetApi;

public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("http://petstore.swagger.io/v2");

// Configure OAuth2 access token for authorization: petstore_auth
OAuth petstore_auth = (OAuth) defaultClient.getAuthentication("petstore_auth");
petstore_auth.setAccessToken("YOUR ACCESS TOKEN");

FakeApi apiInstance = new FakeApi(defaultClient);
PetApi apiInstance = new PetApi(defaultClient);
Pet pet = new Pet(); // Pet | Pet object that needs to be added to the store
try {
Object result = apiInstance.fakeInlineSchemaAnyofPath1Get();
Pet result = apiInstance.addPet(pet);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling FakeApi#fakeInlineSchemaAnyofPath1Get");
System.err.println("Exception when calling PetApi#addPet");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
Expand All @@ -113,18 +119,6 @@ All URIs are relative to *http://petstore.swagger.io/v2*

Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*FakeApi* | [**fakeInlineSchemaAnyofPath1Get**](docs/FakeApi.md#fakeInlineSchemaAnyofPath1Get) | **GET** /fake/inline/schema/anyof/path1 |
*FakeApi* | [**fakeInlineSchemaAnyofPath2Get**](docs/FakeApi.md#fakeInlineSchemaAnyofPath2Get) | **GET** /fake/inline/schema/anyof/path2 |
*FakeApi* | [**fakeInlineSchemaAnyofPath3Get**](docs/FakeApi.md#fakeInlineSchemaAnyofPath3Get) | **GET** /fake/inline/schema/anyof/path3 |
*FakeApi* | [**op1**](docs/FakeApi.md#op1) | **POST** /fake/api/changeowner | op1
*FakeApi* | [**op2**](docs/FakeApi.md#op2) | **POST** /fake/api/changename | op2
*FakeApi* | [**op3**](docs/FakeApi.md#op3) | **POST** /fake/api/query/enum | op3
*FakeApi* | [**refToRefParameter**](docs/FakeApi.md#refToRefParameter) | **GET** /ref/ref_to_parameter |
*FakeApi* | [**refToRefParameterAnyof**](docs/FakeApi.md#refToRefParameterAnyof) | **GET** /ref/ref_to_operation_level_parameter_oneof |
*FakeApi* | [**refToRefParameterOneof**](docs/FakeApi.md#refToRefParameterOneof) | **GET** /ref/ref_to_path_level_parameter_oneof |
*FakeApi* | [**responseNoRef**](docs/FakeApi.md#responseNoRef) | **GET** /no_ref |
*FakeApi* | [**responseRefToNoRef**](docs/FakeApi.md#responseRefToNoRef) | **GET** /ref/no_ref |
*FakeApi* | [**responseRefToRef**](docs/FakeApi.md#responseRefToRef) | **GET** /ref/ref |
*PetApi* | [**addPet**](docs/PetApi.md#addPet) | **POST** /pet | Add a new pet to the store
*PetApi* | [**deletePet**](docs/PetApi.md#deletePet) | **DELETE** /pet/{petId} | Deletes a pet
*PetApi* | [**findPetsByStatus**](docs/PetApi.md#findPetsByStatus) | **GET** /pet/findByStatus | Finds Pets by status
Expand All @@ -149,30 +143,10 @@ Class | Method | HTTP request | Description

## Documentation for Models

- [AllOfSimpleModel](docs/AllOfSimpleModel.md)
- [Animal](docs/Animal.md)
- [AnyTypeTest](docs/AnyTypeTest.md)
- [ArrayOfSameRef](docs/ArrayOfSameRef.md)
- [Cat](docs/Cat.md)
- [Category](docs/Category.md)
- [CircularReference1](docs/CircularReference1.md)
- [CircularReference2](docs/CircularReference2.md)
- [CircularReference3](docs/CircularReference3.md)
- [CodesEnum](docs/CodesEnum.md)
- [Dog](docs/Dog.md)
- [FakeWebhooksSourcesDeletedPostRequest](docs/FakeWebhooksSourcesDeletedPostRequest.md)
- [FakeWebhooksSourcesDeletedPostRequestEvent](docs/FakeWebhooksSourcesDeletedPostRequestEvent.md)
- [ModelApiResponse](docs/ModelApiResponse.md)
- [OneOfStringOrInt](docs/OneOfStringOrInt.md)
- [Order](docs/Order.md)
- [Pet](docs/Pet.md)
- [RefRefToPathLevelParameterOneofRefToOneofParameter](docs/RefRefToPathLevelParameterOneofRefToOneofParameter.md)
- [RefToRefParameterAnyofRefToAnyofParameter](docs/RefToRefParameterAnyofRefToAnyofParameter.md)
- [SelfReferenceAdditionalProperties](docs/SelfReferenceAdditionalProperties.md)
- [SelfReferenceAnyOf](docs/SelfReferenceAnyOf.md)
- [SelfReferenceOneOf](docs/SelfReferenceOneOf.md)
- [SimpleModelWithArrayProperty](docs/SimpleModelWithArrayProperty.md)
- [StringOrInt](docs/StringOrInt.md)
- [Tag](docs/Tag.md)
- [User](docs/User.md)

Expand Down
Loading

0 comments on commit 385e3a4

Please sign in to comment.