-
Notifications
You must be signed in to change notification settings - Fork 4
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Opět model bych nezmiňoval. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
|
@@ -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 |
---|---|---|
|
@@ -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 | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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). | ||
|
@@ -173,6 +176,7 @@ open class KotlinClientCodegen : org.openapitools.codegen.languages.KotlinClient | |
*/ | ||
override fun processOpts() { | ||
super.processOpts() | ||
processOptsApi() | ||
processOptsInfrastructure() | ||
processOptsAdditionalSupportingFiles() | ||
processOptsAdditional() | ||
|
@@ -327,6 +331,7 @@ open class KotlinClientCodegen : org.openapitools.codegen.languages.KotlinClient | |
* @since 2.0.0 | ||
*/ | ||
private fun initSettings() { | ||
initSettingsApi() | ||
initSettingsInfrastructure() | ||
initSettingsEmptyDataClass() | ||
initSettingsComposedArrayAny() | ||
|
@@ -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 | ||
* | ||
|
@@ -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)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
* | ||
|
There was a problem hiding this comment.
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.