Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New property generateApi #28

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Change Log
## 2.2.4 (TBD)

### Added:
- (Kotlin) Add a new parameter `generateApi` you can enable/disable to generate API with infrastructure.
If you set it to false, only model classes will be generated.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you set it to false api classes will not be generated. Model to nijak neovlivňuje. Pokud bys pak měl i proměnnou na model tak tohle už nebude pravda protože generateApi != generateModel.

- Support for Kotlin Multiplatform `kotlinx.datetime` date library

## 2.2.3 (2020-08-31)
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ configure<SwaggerCodeGenConfig> {
"enumPropertyNaming" to "UPPERCASE",
"modelNameSuffix" to "Dto",
"apiNameSuffix" to "Service",
"generateApi" to true,
"generateInfrastructure" to false,
"emptyDataClasses" to false,
"composedArrayAsAny" to true,
Expand Down Expand Up @@ -82,7 +83,8 @@ configure<SwaggerCodeGenConfig> {
- `templateEngine` - Currently this generator is supporting only `mustache`. Support of `handlebars` is in a progress.
- `dateLibrary` - By this property you can set date library used to serialize dates and times.
- `enumPropertyNaming` - By this property you can change enum property naming style. ("camelCase", "PascalCase", "snake_case", "original", "UPPERCASE")
- `generateInfrastructure` - By this property you can enable to generate API infrastructure.
- `generateApi` - By this property you can enable/disable to generate API with infrastructure. If you set to false, only a model classes will be generated.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opět model bych nezmiňoval.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technicky by to asi měl být i enum. API_INFRA, API, NOTHING. :) Ale nevím jestli se dají enumy poslílat přes tuhle konfiguraci.

- `generateInfrastructure` - By this property you can enable to generate API infrastructure. If property `generateApi=false`, then this property is ignored.
- `collectionType` - By this property cou can change collection type.
- `emptyDataClasses` - By this property you can enable empty data classes being generated. (Note: it should not pass Kotlin compilation.)
- `generateAliasAsModel` - By this property you can generate alias (array, map) as model.
Expand All @@ -106,4 +108,4 @@ If your OpenApi contains some specific objects for parsing JSON, .... You need a
```kotlin
implementation("com.squareup.moshi:moshi-kotlin:1.9.2")
implementation("com.squareup.moshi:moshi-adapters:1.9.2")
```
```
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import cz.eman.swagger.codegen.language.COMPOSED_VARS_NOT_REQUIRED
import cz.eman.swagger.codegen.language.COMPOSED_VARS_NOT_REQUIRED_DESCRIPTION
import cz.eman.swagger.codegen.language.EMPTY_DATA_CLASS
import cz.eman.swagger.codegen.language.EMPTY_DATA_CLASS_DESCRIPTION
import cz.eman.swagger.codegen.language.GENERATE_API
import cz.eman.swagger.codegen.language.GENERATE_API_DESCRIPTION
import cz.eman.swagger.codegen.language.GENERATE_INFRASTRUCTURE_API
import cz.eman.swagger.codegen.language.GENERATE_INFRASTRUCTURE_API_DESCRIPTION
import cz.eman.swagger.codegen.language.GENERATE_PRIMITIVE_TYPE_ALIAS
Expand Down Expand Up @@ -59,7 +61,8 @@ import java.io.File
*
* Additional generator options:
* - `dateLibrary` - By this property you can set date library used to serialize dates and times.
* - `generateInfrastructure` - By this property you can enable to generate API infrastructure.
* - `generateApi` - By this property you can enable/disable to generate API with infrastructure. If you set to false, only a model classes will be generated. Default is true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opět model.

* - `generateInfrastructure` - By this property you can enable to generate API infrastructure. If property `generateApi=false`, then this property is ignored.
* - `collectionType` - By this property cou can change collection type.
* - `emptyDataClasses` - By this property you can enable empty data classes being generated. (Note: it should not pass Kotlin compilation.)
* - `composedArrayAsAny` - By this property array of composed is changed to array of object (kotlin.Any).
Expand Down Expand Up @@ -173,6 +176,7 @@ open class KotlinClientCodegen : org.openapitools.codegen.languages.KotlinClient
*/
override fun processOpts() {
super.processOpts()
processOptsApi()
processOptsInfrastructure()
processOptsAdditionalSupportingFiles()
processOptsAdditional()
Expand Down Expand Up @@ -327,6 +331,7 @@ open class KotlinClientCodegen : org.openapitools.codegen.languages.KotlinClient
* @since 2.0.0
*/
private fun initSettings() {
initSettingsApi()
initSettingsInfrastructure()
initSettingsEmptyDataClass()
initSettingsComposedArrayAny()
Expand Down Expand Up @@ -354,6 +359,22 @@ open class KotlinClientCodegen : org.openapitools.codegen.languages.KotlinClient
cliOptions.add(infrastructureCli)
}

/**
* Settings used to generate api with infrastructure or without both of them.
*
* @since 2.2.4
*/
private fun initSettingsApi() {
val apiCli = CliOption(GENERATE_API, GENERATE_API_DESCRIPTION)
val infraOptions = HashMap<String, String>()
infraOptions[GenerateApiType.API.value] = "Generate API"
infraOptions[EndpointsCommands.INGORE_ENDPOINT_STARTING_SLASH.value] =
REMOVE_ENDPOINT_STARTING_SLASH_DESCRIPTION
apiCli.enum = infraOptions

cliOptions.add(apiCli)
}

/**
* Adds all headers options to this generator
*
Expand Down Expand Up @@ -502,6 +523,28 @@ open class KotlinClientCodegen : org.openapitools.codegen.languages.KotlinClient
}
}

/**
* Processes options for API generated classes. Removes all API template files from the generation isf this
* option is set to false (do not generate API). For more information see [initSettingsInfrastructure].
*
* @since 2.2.4
*/
private fun processOptsApi() {
var generateApi = true
if (additionalProperties.containsKey(GENERATE_API)) {
generateApi = convertPropertyToBooleanAndWriteBack(GENERATE_API)
}

if (!generateApi) {
apiDocTemplateFiles.clear()
apiTemplateFiles.clear()
if (additionalProperties.containsKey(GENERATE_API)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Asi nechápu ale není tahle kontrola zbytečná? To máš obražené v tom generateApi = řádku.

additionalProperties[GENERATE_INFRASTRUCTURE_API] = false
// The processOptsInfrastructure() function should be called after thsi function
}
}
}

/**
* Adds additional supporting files like Readme, build.gradle or settings.gradle.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ package cz.eman.swagger.codegen.language
const val GENERATE_INFRASTRUCTURE_API = "generateInfrastructure"
const val GENERATE_INFRASTRUCTURE_API_DESCRIPTION = "Option to add infrastructure package"

const val GENERATE_API = "generateApi"
const val GENERATE_API_DESCRIPTION = "Option to add api generated classes"

const val EMPTY_DATA_CLASS = "emptyDataClasses"
const val EMPTY_DATA_CLASS_DESCRIPTION = "Option to allow empty data classes (default: false)."

Expand Down Expand Up @@ -36,4 +39,4 @@ const val REMOVE_MINUS_TEXT_FROM_HEADER_DESCRIPTION = "Remove minus text from he

const val REMOVE_ENDPOINT_STARTING_SLASH = "ignoreEndpointStartingSlash"
const val REMOVE_ENDPOINT_STARTING_SLASH_DESCRIPTION =
"Remove/Ignore a starting slash from an endpoint definition if it is present."
"Remove/Ignore a starting slash from an endpoint definition if it is present."