diff --git a/modules/openapi-generator-gradle-plugin/bin/main/org/openapitools/generator/gradle/plugin/OpenApiGeneratorPlugin.kt b/modules/openapi-generator-gradle-plugin/bin/main/org/openapitools/generator/gradle/plugin/OpenApiGeneratorPlugin.kt deleted file mode 100644 index b4a2089c11bb..000000000000 --- a/modules/openapi-generator-gradle-plugin/bin/main/org/openapitools/generator/gradle/plugin/OpenApiGeneratorPlugin.kt +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech) - * - * 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 - * - * http://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. - */ - -package org.openapitools.generator.gradle.plugin - -import org.gradle.api.Plugin -import org.gradle.api.Project -import org.gradle.kotlin.dsl.invoke -import org.openapitools.generator.gradle.plugin.extensions.OpenApiGeneratorGenerateExtension -import org.openapitools.generator.gradle.plugin.extensions.OpenApiGeneratorMetaExtension -import org.openapitools.generator.gradle.plugin.extensions.OpenApiGeneratorValidateExtension -import org.openapitools.generator.gradle.plugin.tasks.GenerateTask -import org.openapitools.generator.gradle.plugin.tasks.GeneratorsTask -import org.openapitools.generator.gradle.plugin.tasks.MetaTask -import org.openapitools.generator.gradle.plugin.tasks.ValidateTask - -/** - * A plugin providing common Open API Generator use cases. - * - * @author Jim Schubert - */ -@Suppress("unused") -class OpenApiGeneratorPlugin : Plugin { - override fun apply(project: Project) { - project.run { - val meta = extensions.create( - "openApiMeta", - OpenApiGeneratorMetaExtension::class.java, - project - ) - - val validate = extensions.create( - "openApiValidate", - OpenApiGeneratorValidateExtension::class.java, - project - ) - - val generate = extensions.create( - "openApiGenerate", - OpenApiGeneratorGenerateExtension::class.java, - project - ) - - generate.outputDir.set("$buildDir/generate-resources/main") - - tasks { - "openApiGenerators"(GeneratorsTask::class) { - group = pluginGroup - description = "Lists generators available via Open API Generators." - } - "openApiMeta"(MetaTask::class) { - group = pluginGroup - description = "Generates a new generator to be consumed via Open API Generator." - - generatorName.set(meta.generatorName) - packageName.set(meta.packageName) - outputFolder.set(meta.outputFolder) - } - "openApiValidate"(ValidateTask::class) { - group = pluginGroup - description = "Validates an Open API 2.0 or 3.x specification document." - - inputSpec.set(validate.inputSpec) - } - "openApiGenerate"(GenerateTask::class) { - group = pluginGroup - description = "Generate code via Open API Tools Generator for Open API 2.0 or 3.x specification documents." - - verbose.set(generate.verbose) - validateSpec.set(generate.validateSpec) - generatorName.set(generate.generatorName) - outputDir.set(generate.outputDir) - inputSpec.set(generate.inputSpec) - templateDir.set(generate.templateDir) - auth.set(generate.auth) - systemProperties.set(generate.systemProperties) - configFile.set(generate.configFile) - skipOverwrite.set(generate.skipOverwrite) - apiPackage.set(generate.apiPackage) - modelPackage.set(generate.modelPackage) - modelNamePrefix.set(generate.modelNamePrefix) - modelNameSuffix.set(generate.modelNameSuffix) - instantiationTypes.set(generate.instantiationTypes) - typeMappings.set(generate.typeMappings) - additionalProperties.set(generate.additionalProperties) - languageSpecificPrimitives.set(generate.languageSpecificPrimitives) - importMappings.set(generate.importMappings) - invokerPackage.set(generate.invokerPackage) - groupId.set(generate.groupId) - id.set(generate.id) - version.set(generate.version) - library.set(generate.library) - gitUserId.set(generate.gitUserId) - gitRepoId.set(generate.gitRepoId) - releaseNote.set(generate.releaseNote) - httpUserAgent.set(generate.httpUserAgent) - reservedWordsMappings.set(generate.reservedWordsMappings) - ignoreFileOverride.set(generate.ignoreFileOverride) - removeOperationIdPrefix.set(generate.removeOperationIdPrefix) - apiFilesConstrainedTo.set(generate.apiFilesConstrainedTo) - modelFilesConstrainedTo.set(generate.modelFilesConstrainedTo) - supportingFilesConstrainedTo.set(generate.supportingFilesConstrainedTo) - generateModelTests.set(generate.generateModelTests) - generateModelDocumentation.set(generate.generateModelDocumentation) - generateApiTests.set(generate.generateApiTests) - generateApiDocumentation.set(generate.generateApiDocumentation) - withXml.set(generate.withXml) - configOptions.set(generate.configOptions) - } - } - } - } - - companion object { - const val pluginGroup = "OpenAPI Tools" - } -} - diff --git a/modules/openapi-generator-gradle-plugin/bin/main/org/openapitools/generator/gradle/plugin/extensions/OpenApiGeneratorGenerateExtension.kt b/modules/openapi-generator-gradle-plugin/bin/main/org/openapitools/generator/gradle/plugin/extensions/OpenApiGeneratorGenerateExtension.kt deleted file mode 100644 index fa7726542ccb..000000000000 --- a/modules/openapi-generator-gradle-plugin/bin/main/org/openapitools/generator/gradle/plugin/extensions/OpenApiGeneratorGenerateExtension.kt +++ /dev/null @@ -1,286 +0,0 @@ -/* - * Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech) - * - * 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 - * - * http://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. - */ - -package org.openapitools.generator.gradle.plugin.extensions - -import org.gradle.api.Project -import org.gradle.kotlin.dsl.listProperty -import org.gradle.kotlin.dsl.property - -/** - * Gradle project level extension object definition for the generate task - * - * @author Jim Schubert - */ -open class OpenApiGeneratorGenerateExtension(project: Project) { - - /** - * The verbosity of generation - */ - val verbose = project.objects.property() - - /** - * Whether or not an input specification should be validated upon generation. - */ - val validateSpec = project.objects.property() - - /** - * The name of the generator which will handle codegen. (see "openApiGenerators" task) - */ - val generatorName = project.objects.property() - - /** - * The output target directory into which code will be generated. - */ - val outputDir = project.objects.property() - - /** - * The Open API 2.0/3.x specification location. - */ - val inputSpec = project.objects.property() - - /** - * The template directory holding a custom template. - */ - val templateDir = project.objects.property() - - /** - * Adds authorization headers when fetching the OpenAPI definitions remotely. - * Pass in a URL-encoded string of name:header with a comma separating multiple values - */ - val auth = project.objects.property() - - /** - * Sets specified system properties. - */ - val systemProperties = project.objects.property>() - - /** - * Path to json configuration file. - * File content should be in a json format { "optionKey":"optionValue", "optionKey1":"optionValue1"...} - * Supported options can be different for each language. Run config-help -g {generator name} command for language specific config options. - */ - val configFile = project.objects.property() - - /** - * Specifies if the existing files should be overwritten during the generation. - */ - val skipOverwrite = project.objects.property() - - /** - * Package for generated api classes - */ - val apiPackage = project.objects.property() - - /** - * Package for generated models - */ - val modelPackage = project.objects.property() - - /** - * Prefix that will be prepended to all model names. Default is the empty string. - */ - val modelNamePrefix = project.objects.property() - - /** - * Suffix that will be appended to all model names. Default is the empty string. - */ - val modelNameSuffix = project.objects.property() - - /** - * Sets instantiation type mappings. - */ - val instantiationTypes = project.objects.property>() - - /** - * Sets mappings between OpenAPI spec types and generated code types. - */ - val typeMappings = project.objects.property>() - - /** - * Sets additional properties that can be referenced by the mustache templates. - */ - val additionalProperties = project.objects.property>() - - /** - * Specifies additional language specific primitive types in the format of type1,type2,type3,type3. For example: String,boolean,Boolean,Double. - */ - val languageSpecificPrimitives = project.objects.listProperty() - - /** - * Specifies mappings between a given class and the import that should be used for that class. - */ - val importMappings = project.objects.property>() - - /** - * Root package for generated code. - */ - val invokerPackage = project.objects.property() - - /** - * GroupId in generated pom.xml/build.gradle or other build script. Language-specific conversions occur in non-jvm generators. - */ - val groupId = project.objects.property() - - /** - * ArtifactId in generated pom.xml/build.gradle or other build script. Language-specific conversions occur in non-jvm generators. - */ - val id = project.objects.property() - - /** - * Artifact version in generated pom.xml/build.gradle or other build script. Language-specific conversions occur in non-jvm generators. - */ - val version = project.objects.property() - - /** - * Reference the library template (sub-template) of a generator. - */ - val library = project.objects.property() - - /** - * Git user ID, e.g. openapitools. - */ - val gitUserId = project.objects.property() - - /** - * Git repo ID, e.g. openapi-generator. - */ - val gitRepoId = project.objects.property() - - /** - * Release note, default to 'Minor update'. - */ - val releaseNote = project.objects.property() - - /** - * HTTP user agent, e.g. codegen_csharp_api_client, default to 'OpenAPI-Generator/{packageVersion}}/{language}' - */ - val httpUserAgent = project.objects.property() - - /** - * Specifies how a reserved name should be escaped to. Otherwise, the default _ is used. - */ - val reservedWordsMappings = project.objects.property>() - - /** - * Specifies an override location for the .openapi-generator-ignore file. Most useful on initial generation. - */ - val ignoreFileOverride = project.objects.property() - - /** - * Remove prefix of operationId, e.g. config_getId => getId - */ - val removeOperationIdPrefix = project.objects.property() - - /** - * Defines which API-related files should be generated. This allows you to create a subset of generated files (or none at all). - * - * NOTE: Configuring any one of [apiFilesConstrainedTo], [modelFilesConstrainedTo], or [supportingFilesConstrainedTo] results - * in others being disabled. That is, OpenAPI Generator considers any one of these to define a subset of generation. - * For more control over generation of individual files, configure an ignore file and refer to it via [ignoreFileOverride]. - */ - val apiFilesConstrainedTo = project.objects.listProperty() - - /** - * Defines which model-related files should be generated. This allows you to create a subset of generated files (or none at all). - * - * NOTE: Configuring any one of [apiFilesConstrainedTo], [modelFilesConstrainedTo], or [supportingFilesConstrainedTo] results - * in others being disabled. That is, OpenAPI Generator considers any one of these to define a subset of generation. - * For more control over generation of individual files, configure an ignore file and refer to it via [ignoreFileOverride]. - */ - val modelFilesConstrainedTo = project.objects.listProperty() - - /** - * Defines which supporting files should be generated. This allows you to create a subset of generated files (or none at all). - * - * Supporting files are those related to projects/frameworks which may be modified - * by consumers. - * - * NOTE: Configuring any one of [apiFilesConstrainedTo], [modelFilesConstrainedTo], or [supportingFilesConstrainedTo] results - * in others being disabled. That is, OpenAPI Generator considers any one of these to define a subset of generation. - * For more control over generation of individual files, configure an ignore file and refer to it via [ignoreFileOverride]. - */ - val supportingFilesConstrainedTo = project.objects.listProperty() - - /** - * Defines whether or not model-related _test_ files should be generated. - * - * This option enables/disables generation of ALL model-related _test_ files. - * - * For more control over generation of individual files, configure an ignore file and - * refer to it via [ignoreFileOverride]. - */ - val generateModelTests = project.objects.property() - - /** - * Defines whether or not model-related _documentation_ files should be generated. - * - * This option enables/disables generation of ALL model-related _documentation_ files. - * - * For more control over generation of individual files, configure an ignore file and - * refer to it via [ignoreFileOverride]. - */ - val generateModelDocumentation = project.objects.property() - - /** - * Defines whether or not api-related _test_ files should be generated. - * - * This option enables/disables generation of ALL api-related _test_ files. - * - * For more control over generation of individual files, configure an ignore file and - * refer to it via [ignoreFileOverride]. - */ - val generateApiTests = project.objects.property() - - /** - * Defines whether or not api-related _documentation_ files should be generated. - * - * This option enables/disables generation of ALL api-related _documentation_ files. - * - * For more control over generation of individual files, configure an ignore file and - * refer to it via [ignoreFileOverride]. - */ - val generateApiDocumentation = project.objects.property() - - /** - * A special-case setting which configures some generators with XML support. In some cases, - * this forces json OR xml, so the default here is false. - */ - val withXml = project.objects.property() - - /** - * A map of options specific to a generator. - */ - val configOptions = project.objects.property>() - - init { - applyDefaults() - } - - @Suppress("MemberVisibilityCanBePrivate") - fun applyDefaults(){ - releaseNote.set("Minor update") - modelNamePrefix.set("") - modelNameSuffix.set("") - generateModelTests.set(true) - generateModelDocumentation.set(true) - generateApiTests.set(true) - generateApiDocumentation.set(true) - withXml.set(false) - configOptions.set(mapOf()) - validateSpec.set(true) - } -} \ No newline at end of file diff --git a/modules/openapi-generator-gradle-plugin/bin/main/org/openapitools/generator/gradle/plugin/extensions/OpenApiGeneratorMetaExtension.kt b/modules/openapi-generator-gradle-plugin/bin/main/org/openapitools/generator/gradle/plugin/extensions/OpenApiGeneratorMetaExtension.kt deleted file mode 100644 index 94d298a31b88..000000000000 --- a/modules/openapi-generator-gradle-plugin/bin/main/org/openapitools/generator/gradle/plugin/extensions/OpenApiGeneratorMetaExtension.kt +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech) - * - * 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 - * - * http://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. - */ - -package org.openapitools.generator.gradle.plugin.extensions - -import org.gradle.api.Project -import org.gradle.kotlin.dsl.property - -/** - * Gradle project level extension object definition for the meta-generator task - * - * @author Jim Schubert - */ -open class OpenApiGeneratorMetaExtension(project: Project) { - /** - * The human-readable generator name of the newly created template generator. - */ - val generatorName = project.objects.property() - - /** - * The packageName generatorName to put the main class into (defaults to org.openapitools.codegen) - */ - val packageName = project.objects.property() - - /** - * Where to write the generated files (current dir by default). - */ - val outputFolder = project.objects.property() - - init { - generatorName.set("default") - packageName.set("org.openapitools.codegen") - outputFolder.set("") - } -} \ No newline at end of file diff --git a/modules/openapi-generator-gradle-plugin/bin/main/org/openapitools/generator/gradle/plugin/extensions/OpenApiGeneratorValidateExtension.kt b/modules/openapi-generator-gradle-plugin/bin/main/org/openapitools/generator/gradle/plugin/extensions/OpenApiGeneratorValidateExtension.kt deleted file mode 100644 index 3b4a1853b941..000000000000 --- a/modules/openapi-generator-gradle-plugin/bin/main/org/openapitools/generator/gradle/plugin/extensions/OpenApiGeneratorValidateExtension.kt +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech) - * - * 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 - * - * http://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. - */ - -package org.openapitools.generator.gradle.plugin.extensions - -import org.gradle.api.Project -import org.gradle.kotlin.dsl.property - -/** - * Gradle project level extension object definition for the generators task - * - * @author Jim Schubert - */ -open class OpenApiGeneratorValidateExtension(project: Project) { - /** - * The input specification to validate. Supports all formats supported by the Parser. - */ - val inputSpec = project.objects.property() -} \ No newline at end of file diff --git a/modules/openapi-generator-gradle-plugin/bin/main/org/openapitools/generator/gradle/plugin/tasks/GenerateTask.kt b/modules/openapi-generator-gradle-plugin/bin/main/org/openapitools/generator/gradle/plugin/tasks/GenerateTask.kt deleted file mode 100644 index 1982dd3dc256..000000000000 --- a/modules/openapi-generator-gradle-plugin/bin/main/org/openapitools/generator/gradle/plugin/tasks/GenerateTask.kt +++ /dev/null @@ -1,549 +0,0 @@ -/* - * Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech) - * - * 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 - * - * http://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. - */ - -package org.openapitools.generator.gradle.plugin.tasks - -import org.gradle.api.DefaultTask -import org.gradle.api.GradleException -import org.gradle.api.provider.Property -import org.gradle.api.tasks.Internal -import org.gradle.api.tasks.TaskAction -import org.gradle.internal.logging.text.StyledTextOutput -import org.gradle.internal.logging.text.StyledTextOutputFactory -import org.gradle.kotlin.dsl.listProperty -import org.gradle.kotlin.dsl.property -import org.openapitools.codegen.CodegenConstants -import org.openapitools.codegen.DefaultGenerator -import org.openapitools.codegen.config.CodegenConfigurator -import org.openapitools.codegen.config.GeneratorProperties - - -/** - * A task which generates the desired code. - * - * Example (CLI): - * - * ./gradlew -q openApiGenerate - * - * @author Jim Schubert - */ -open class GenerateTask : DefaultTask() { - - /** - * The verbosity of generation - */ - @get:Internal - val verbose = project.objects.property() - - /** - * Whether or not an input specification should be validated upon generation. - */ - @get:Internal - val validateSpec = project.objects.property() - - /** - * The name of the generator which will handle codegen. (see "openApiGenerators" task) - */ - @get:Internal - val generatorName = project.objects.property() - - /** - * The output target directory into which code will be generated. - */ - @get:Internal - val outputDir = project.objects.property() - - /** - * The Open API 2.0/3.x specification location. - */ - @get:Internal - val inputSpec = project.objects.property() - - /** - * The template directory holding a custom template. - */ - @get:Internal - val templateDir = project.objects.property() - - /** - * Adds authorization headers when fetching the OpenAPI definitions remotely. - * Pass in a URL-encoded string of name:header with a comma separating multiple values - */ - @get:Internal - val auth = project.objects.property() - - /** - * Sets specified system properties. - */ - @get:Internal - val systemProperties = project.objects.property>() - - /** - * Path to json configuration file. - * File content should be in a json format { "optionKey":"optionValue", "optionKey1":"optionValue1"...} - * Supported options can be different for each language. Run config-help -g {generator name} command for language specific config options. - */ - @get:Internal - val configFile = project.objects.property() - - /** - * Specifies if the existing files should be overwritten during the generation. - */ - @get:Internal - val skipOverwrite = project.objects.property() - - /** - * Package for generated api classes - */ - @get:Internal - val apiPackage = project.objects.property() - - /** - * Package for generated models - */ - @get:Internal - val modelPackage = project.objects.property() - - /** - * Prefix that will be prepended to all model names. Default is the empty string. - */ - @get:Internal - val modelNamePrefix = project.objects.property() - - /** - * Suffix that will be appended to all model names. Default is the empty string. - */ - @get:Internal - val modelNameSuffix = project.objects.property() - - /** - * Sets instantiation type mappings. - */ - @get:Internal - val instantiationTypes = project.objects.property>() - - /** - * Sets mappings between OpenAPI spec types and generated code types. - */ - @get:Internal - val typeMappings = project.objects.property>() - - /** - * Sets additional properties that can be referenced by the mustache templates in the format of name=value,name=value. - * You can also have multiple occurrences of this option. - */ - @get:Internal - val additionalProperties = project.objects.property>() - - /** - * Specifies additional language specific primitive types in the format of type1,type2,type3,type3. For example: String,boolean,Boolean,Double. - */ - @get:Internal - val languageSpecificPrimitives = project.objects.listProperty() - - /** - * Specifies mappings between a given class and the import that should be used for that class. - */ - @get:Internal - val importMappings = project.objects.property>() - - /** - * Root package for generated code. - */ - @get:Internal - val invokerPackage = project.objects.property() - - /** - * GroupId in generated pom.xml/build.gradle or other build script. Language-specific conversions occur in non-jvm generators. - */ - @get:Internal - val groupId = project.objects.property() - - /** - * ArtifactId in generated pom.xml/build.gradle or other build script. Language-specific conversions occur in non-jvm generators. - */ - @get:Internal - val id = project.objects.property() - - /** - * Artifact version in generated pom.xml/build.gradle or other build script. Language-specific conversions occur in non-jvm generators. - */ - @get:Internal - val version = project.objects.property() - - /** - * Reference the library template (sub-template) of a generator. - */ - @get:Internal - val library = project.objects.property() - - /** - * Git user ID, e.g. openapitools. - */ - @get:Internal - val gitUserId = project.objects.property() - - /** - * Git repo ID, e.g. openapi-generator. - */ - @get:Internal - val gitRepoId = project.objects.property() - - /** - * Release note, default to 'Minor update'. - */ - @get:Internal - val releaseNote = project.objects.property() - - /** - * HTTP user agent, e.g. codegen_csharp_api_client, default to 'OpenAPI-Generator/{packageVersion}}/{language}' - */ - @get:Internal - val httpUserAgent = project.objects.property() - - /** - * Specifies how a reserved name should be escaped to. - */ - @get:Internal - val reservedWordsMappings = project.objects.property>() - - /** - * Specifies an override location for the .openapi-generator-ignore file. Most useful on initial generation. - */ - @get:Internal - val ignoreFileOverride = project.objects.property() - - /** - * Remove prefix of operationId, e.g. config_getId => getId - */ - @get:Internal - val removeOperationIdPrefix = project.objects.property() - - /** - * Defines which API-related files should be generated. This allows you to create a subset of generated files (or none at all). - * - * This option enables/disables generation of ALL api-related files. - * - * NOTE: Configuring any one of [apiFilesConstrainedTo], [modelFilesConstrainedTo], or [supportingFilesConstrainedTo] results - * in others being disabled. That is, OpenAPI Generator considers any one of these to define a subset of generation. - * For more control over generation of individual files, configure an ignore file and refer to it via [ignoreFileOverride]. - */ - @get:Internal - val apiFilesConstrainedTo = project.objects.listProperty() - - /** - * Defines which model-related files should be generated. This allows you to create a subset of generated files (or none at all). - * - * NOTE: Configuring any one of [apiFilesConstrainedTo], [modelFilesConstrainedTo], or [supportingFilesConstrainedTo] results - * in others being disabled. That is, OpenAPI Generator considers any one of these to define a subset of generation. - * For more control over generation of individual files, configure an ignore file and refer to it via [ignoreFileOverride]. - */ - @get:Internal - val modelFilesConstrainedTo = project.objects.listProperty() - - /** - * Defines which supporting files should be generated. This allows you to create a subset of generated files (or none at all). - * - * Supporting files are those related to projects/frameworks which may be modified - * by consumers. - * - * NOTE: Configuring any one of [apiFilesConstrainedTo], [modelFilesConstrainedTo], or [supportingFilesConstrainedTo] results - * in others being disabled. That is, OpenAPI Generator considers any one of these to define a subset of generation. - * For more control over generation of individual files, configure an ignore file and refer to it via [ignoreFileOverride]. - */ - @get:Internal - val supportingFilesConstrainedTo = project.objects.listProperty() - - /** - * Defines whether or not model-related _test_ files should be generated. - * - * This option enables/disables generation of ALL model-related _test_ files. - * - * For more control over generation of individual files, configure an ignore file and - * refer to it via [ignoreFileOverride]. - */ - @get:Internal - val generateModelTests = project.objects.property() - - /** - * Defines whether or not model-related _documentation_ files should be generated. - * - * This option enables/disables generation of ALL model-related _documentation_ files. - * - * For more control over generation of individual files, configure an ignore file and - * refer to it via [ignoreFileOverride]. - */ - @get:Internal - val generateModelDocumentation = project.objects.property() - - /** - * Defines whether or not api-related _test_ files should be generated. - * - * This option enables/disables generation of ALL api-related _test_ files. - * - * For more control over generation of individual files, configure an ignore file and - * refer to it via [ignoreFileOverride]. - */ - @get:Internal - val generateApiTests = project.objects.property() - - /** - * Defines whether or not api-related _documentation_ files should be generated. - * - * This option enables/disables generation of ALL api-related _documentation_ files. - * - * For more control over generation of individual files, configure an ignore file and - * refer to it via [ignoreFileOverride]. - */ - @get:Internal - val generateApiDocumentation = project.objects.property() - - /** - * A special-case setting which configures some generators with XML support. In some cases, - * this forces json OR xml, so the default here is false. - */ - @get:Internal - val withXml = project.objects.property() - - /** - * A dynamic map of options specific to a generator. - */ - @get:Internal - val configOptions = project.objects.property>() - - private val originalEnvironmentVariables = mutableMapOf() - - private fun Property.ifNotEmpty(block: Property.(T) -> Unit) { - if (isPresent) { - val item: T? = get() - if (item != null) { - when (get()) { - is String -> if ((get() as String).isNotEmpty()) { - block(get()) - } - is String? -> if (true == (get() as String?)?.isNotEmpty()) { - block(get()) - } - else -> block(get()) - } - } - } - } - - @Suppress("unused") - @TaskAction - fun doWork() { - val configurator: CodegenConfigurator = if (configFile.isPresent) { - CodegenConfigurator.fromFile(configFile.get()) - } else CodegenConfigurator() - - try { - if (systemProperties.isPresent) { - systemProperties.get().forEach { (key, value) -> - // GeneratorProperties.setProperty returns the original value for a key, or null. - // Cache the original value or null…we will late put the properties back in their original state. - originalEnvironmentVariables[key] = GeneratorProperties.setProperty(key, value) - configurator.addSystemProperty(key, value) - } - } - - if (supportingFilesConstrainedTo.isPresent && supportingFilesConstrainedTo.get().isNotEmpty()) { - GeneratorProperties.setProperty(CodegenConstants.SUPPORTING_FILES, supportingFilesConstrainedTo.get().joinToString(",")) - } else { - GeneratorProperties.clearProperty(CodegenConstants.SUPPORTING_FILES) - } - - if (modelFilesConstrainedTo.isPresent && modelFilesConstrainedTo.get().isNotEmpty()) { - GeneratorProperties.setProperty(CodegenConstants.MODELS, modelFilesConstrainedTo.get().joinToString(",")) - } else { - GeneratorProperties.clearProperty(CodegenConstants.MODELS) - } - - if (apiFilesConstrainedTo.isPresent && apiFilesConstrainedTo.get().isNotEmpty()) { - GeneratorProperties.setProperty(CodegenConstants.APIS, apiFilesConstrainedTo.get().joinToString(",")) - } else { - GeneratorProperties.clearProperty(CodegenConstants.APIS) - } - - GeneratorProperties.setProperty(CodegenConstants.API_DOCS, generateApiDocumentation.get().toString()) - GeneratorProperties.setProperty(CodegenConstants.MODEL_DOCS, generateModelDocumentation.get().toString()) - GeneratorProperties.setProperty(CodegenConstants.MODEL_TESTS, generateModelTests.get().toString()) - GeneratorProperties.setProperty(CodegenConstants.API_TESTS, generateApiTests.get().toString()) - GeneratorProperties.setProperty(CodegenConstants.WITH_XML, withXml.get().toString()) - - // now override with any specified parameters - verbose.ifNotEmpty { value -> - configurator.isVerbose = value - } - - validateSpec.ifNotEmpty { value -> - configurator.isValidateSpec = value - } - - skipOverwrite.ifNotEmpty { value -> - configurator.isSkipOverwrite = value ?: false - } - - inputSpec.ifNotEmpty { value -> - configurator.inputSpec = value - } - - generatorName.ifNotEmpty { value -> - configurator.generatorName = value - } - - outputDir.ifNotEmpty { value -> - configurator.outputDir = value - } - - auth.ifNotEmpty { value -> - configurator.auth = value - } - - templateDir.ifNotEmpty { value -> - configurator.templateDir = value - } - - apiPackage.ifNotEmpty { value -> - configurator.apiPackage = value - } - - modelPackage.ifNotEmpty { value -> - configurator.modelPackage = value - } - - modelNamePrefix.ifNotEmpty { value -> - configurator.modelNamePrefix = value - } - - modelNameSuffix.ifNotEmpty { value -> - configurator.modelNameSuffix = value - } - - invokerPackage.ifNotEmpty { value -> - configurator.invokerPackage = value - } - - groupId.ifNotEmpty { value -> - configurator.groupId = value - } - - id.ifNotEmpty { value -> - configurator.artifactId = value - } - - version.ifNotEmpty { value -> - configurator.artifactVersion = value - } - - library.ifNotEmpty { value -> - configurator.library = value - } - - gitUserId.ifNotEmpty { value -> - configurator.gitUserId = value - } - - gitRepoId.ifNotEmpty { value -> - configurator.gitRepoId = value - } - - releaseNote.ifNotEmpty { value -> - configurator.releaseNote = value - } - - httpUserAgent.ifNotEmpty { value -> - configurator.httpUserAgent = value - } - - ignoreFileOverride.ifNotEmpty { value -> - configurator.ignoreFileOverride = value - } - - removeOperationIdPrefix.ifNotEmpty { value -> - configurator.removeOperationIdPrefix = value!! - } - - if (systemProperties.isPresent) { - systemProperties.get().forEach { entry -> - configurator.addSystemProperty(entry.key, entry.value) - } - } - - if (instantiationTypes.isPresent) { - instantiationTypes.get().forEach { entry -> - configurator.addInstantiationType(entry.key, entry.value) - } - } - - if (importMappings.isPresent) { - importMappings.get().forEach { entry -> - configurator.addImportMapping(entry.key, entry.value) - } - } - - if (typeMappings.isPresent) { - typeMappings.get().forEach { entry -> - configurator.addTypeMapping(entry.key, entry.value) - } - } - - if (additionalProperties.isPresent) { - additionalProperties.get().forEach { entry -> - configurator.addAdditionalProperty(entry.key, entry.value) - } - } - - if (languageSpecificPrimitives.isPresent) { - languageSpecificPrimitives.get().forEach { - configurator.addLanguageSpecificPrimitive(it) - } - } - - if (reservedWordsMappings.isPresent) { - reservedWordsMappings.get().forEach { entry -> - configurator.addAdditionalReservedWordMapping(entry.key, entry.value) - } - } - - val clientOptInput = configurator.toClientOptInput() - val codgenConfig = clientOptInput.config - - if (configOptions.isPresent) { - val userSpecifiedConfigOptions = configOptions.get() - codgenConfig.cliOptions().forEach { - if (userSpecifiedConfigOptions.containsKey(it.opt)) { - clientOptInput.config.additionalProperties()[it.opt] = userSpecifiedConfigOptions[it.opt] - } - } - } - - try { - val out = services.get(StyledTextOutputFactory::class.java).create("openapi") - out.withStyle(StyledTextOutput.Style.Success) - - DefaultGenerator().opts(clientOptInput).generate() - - out.println("Successfully generated code to ${configurator.outputDir}") - } catch (e: RuntimeException) { - throw GradleException("Code generation failed.", e) - } - } finally { - // Reset all modified system properties back to their original state - GeneratorProperties.reset() - } - } -} diff --git a/modules/openapi-generator-gradle-plugin/bin/main/org/openapitools/generator/gradle/plugin/tasks/GeneratorsTask.kt b/modules/openapi-generator-gradle-plugin/bin/main/org/openapitools/generator/gradle/plugin/tasks/GeneratorsTask.kt deleted file mode 100644 index 08e821b83a53..000000000000 --- a/modules/openapi-generator-gradle-plugin/bin/main/org/openapitools/generator/gradle/plugin/tasks/GeneratorsTask.kt +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech) - * - * 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 - * - * http://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. - */ - -package org.openapitools.generator.gradle.plugin.tasks - -import org.gradle.api.DefaultTask -import org.gradle.api.tasks.TaskAction -import org.gradle.internal.logging.text.StyledTextOutput -import org.gradle.internal.logging.text.StyledTextOutputFactory -import org.openapitools.codegen.CodegenConfigLoader -import org.openapitools.codegen.CodegenType - -/** - * A task which lists out the generators available in OpenAPI Generator - * - * Example (CLI): - * - * ./gradlew -q openApiGenerators - * - * @author Jim Schubert - */ -open class GeneratorsTask : DefaultTask() { - @Suppress("unused") - @TaskAction - fun doWork() { - val generators = CodegenConfigLoader.getAll() - - val out = services.get(StyledTextOutputFactory::class.java).create("openapi") - - StringBuilder().apply { - val types = CodegenType.values() - - append("The following generators are available:") - - append(System.lineSeparator()) - append(System.lineSeparator()) - - for (type in types) { - append(type.name).append(" generators:") - append(System.lineSeparator()) - - generators.filter { it.tag == type } - .sortedBy { it.name } - .forEach({ generator -> - append(" - ") - append(generator.name) - append(System.lineSeparator()) - }) - - append(System.lineSeparator()) - append(System.lineSeparator()) - } - - out.withStyle(StyledTextOutput.Style.Success) - out.formatln("%s%n", toString()) - } - } -} \ No newline at end of file diff --git a/modules/openapi-generator-gradle-plugin/bin/main/org/openapitools/generator/gradle/plugin/tasks/MetaTask.kt b/modules/openapi-generator-gradle-plugin/bin/main/org/openapitools/generator/gradle/plugin/tasks/MetaTask.kt deleted file mode 100644 index 7d11f4d8b6cc..000000000000 --- a/modules/openapi-generator-gradle-plugin/bin/main/org/openapitools/generator/gradle/plugin/tasks/MetaTask.kt +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech) - * - * 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 - * - * http://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. - */ - -package org.openapitools.generator.gradle.plugin.tasks - -import com.samskivert.mustache.Mustache -import org.gradle.api.DefaultTask -import org.gradle.api.GradleException -import org.gradle.api.tasks.Internal -import org.gradle.api.tasks.TaskAction -import org.gradle.internal.logging.text.StyledTextOutput -import org.gradle.internal.logging.text.StyledTextOutputFactory -import org.gradle.kotlin.dsl.property -import org.openapitools.codegen.CodegenConfig -import org.openapitools.codegen.CodegenConstants -import org.openapitools.codegen.DefaultGenerator -import org.openapitools.codegen.SupportingFile -import java.io.File -import java.io.IOException -import java.nio.charset.Charset - -/** - * A task which generates a new generator (meta). Useful for redistributable generator packages. - * - * @author Jim Schubert - */ -open class MetaTask : DefaultTask() { - - @get:Internal - val generatorName = project.objects.property() - - @get:Internal - val packageName = project.objects.property() - - @get:Internal - val outputFolder = project.objects.property() - - @Suppress("unused") - @TaskAction - fun doWork() { - - val packageToPath = packageName.get().replace(".", File.separator) - val dir = File(outputFolder.get()) - val klass = "${generatorName.get().titleCasedTextOnly()}Generator" - - val templateResourceDir = generatorName.get().hyphenatedTextOnly() - - val out = services.get(StyledTextOutputFactory::class.java).create("openapi") - - out.withStyle(StyledTextOutput.Style.Info) - - logger.debug("package: {}", packageName.get()) - logger.debug("dir: {}", dir.absolutePath) - logger.debug("generator class: {}", klass) - - val supportingFiles = listOf( - SupportingFile("pom.mustache", "", "pom.xml"), - SupportingFile("generatorClass.mustache", dir("src", "main", "java", packageToPath), "$klass.java"), - SupportingFile("README.mustache", "", "README.md"), - SupportingFile("api.template", dir("src", "main", "resources", templateResourceDir), "api.mustache"), - SupportingFile("model.template", dir("src", "main", "resources", templateResourceDir), "model.mustache"), - SupportingFile("myFile.template", dir("src", "main", "resources", templateResourceDir), "myFile.mustache"), - SupportingFile("services.mustache", dir("src", "main", "resources", "META-INF", "services"), CodegenConfig::class.java.canonicalName)) - - val currentVersion = CodegenConstants::class.java.`package`.implementationVersion - - val data = mapOf("generatorPackage" to packageToPath, - "generatorClass" to klass, - "name" to templateResourceDir, - "fullyQualifiedGeneratorClass" to "${packageName.get()}.$klass", - "openapiGeneratorVersion" to currentVersion) - - val generator = DefaultGenerator() - supportingFiles.map { - try { - val destinationFolder = File(File(dir.absolutePath), it.folder) - destinationFolder.mkdirs() - val outputFile = File(destinationFolder, it.destinationFilename) - - val template = generator.readTemplate(File("codegen", it.templateFile).path) - var formatted = template - - if (it.templateFile.endsWith(".mustache")) { - formatted = Mustache.compiler() - .withLoader(loader(generator)) - .defaultValue("") - .compile(template).execute(data) - } - - outputFile.writeText(formatted, Charset.forName("UTF8")) - - out.formatln("Wrote file to %s", outputFile.absolutePath) - - // TODO: register outputs - // return outputFile - } catch (e: IOException) { - logger.error(e.message) - throw GradleException("Can't generate project", e) - } - } - out.withStyle(StyledTextOutput.Style.Success) - out.formatln("Created generator %s", klass) - } - - private fun loader(generator: DefaultGenerator): Mustache.TemplateLoader { - return Mustache.TemplateLoader { name -> - generator.getTemplateReader("codegen${File.separator}$name.mustache") - } - } - - private fun String.titleCasedTextOnly(): String = - this.split(Regex("[^a-zA-Z0-9]")).joinToString(separator = "", transform = String::capitalize) - - private fun String.hyphenatedTextOnly(): String = - this.split(Regex("[^a-zA-Z0-9]")).joinToString(separator = "-", transform = String::toLowerCase) - - private fun dir(vararg parts: String): String = - parts.joinToString(separator = File.separator) -} diff --git a/modules/openapi-generator-gradle-plugin/bin/main/org/openapitools/generator/gradle/plugin/tasks/ValidateTask.kt b/modules/openapi-generator-gradle-plugin/bin/main/org/openapitools/generator/gradle/plugin/tasks/ValidateTask.kt deleted file mode 100644 index 0956ba22c265..000000000000 --- a/modules/openapi-generator-gradle-plugin/bin/main/org/openapitools/generator/gradle/plugin/tasks/ValidateTask.kt +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech) - * - * 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 - * - * http://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. - */ - -package org.openapitools.generator.gradle.plugin.tasks - -import io.swagger.parser.OpenAPIParser -import org.gradle.api.DefaultTask -import org.gradle.api.GradleException -import org.gradle.api.tasks.Internal -import org.gradle.api.tasks.TaskAction -import org.gradle.api.tasks.options.Option -import org.gradle.internal.logging.text.StyledTextOutput -import org.gradle.internal.logging.text.StyledTextOutputFactory -import org.gradle.kotlin.dsl.property - -/** - * A generator which validates an Open API spec. This task outputs a list of validation issues and errors. - * - * Example: - * cli: - * - * ./gradlew openApiValidate --input=/path/to/file - * - * build.gradle: - * - * openApiMeta { - * inputSpec = "path/to/spec.yaml" - * } - * - * @author Jim Schubert - */ -open class ValidateTask : DefaultTask() { - @get:Internal - var inputSpec = project.objects.property() - - @Suppress("unused") - @get:Internal - @set:Option(option = "input", description = "The input specification.") - var input: String? = null - set(value) { - inputSpec.set(value) - } - - @Suppress("unused") - @TaskAction - fun doWork() { - val spec = inputSpec.get() - logger.quiet("Validating spec $spec") - val result = OpenAPIParser().readLocation(spec, null, null) - val messages = result.messages.toSet() - val out = services.get(StyledTextOutputFactory::class.java).create("openapi") - - if (messages.isNotEmpty()) { - - out.withStyle(StyledTextOutput.Style.Error) - out.println("\nSpec is invalid.\nIssues:\n") - - messages.forEach { - out.withStyle(StyledTextOutput.Style.Error) - out.println("\t$it\n") - } - - throw GradleException("Validation failed.") - } else { - out.withStyle(StyledTextOutput.Style.Success) - out.println("Spec is valid.") - } - } -} \ No newline at end of file diff --git a/modules/openapi-generator-gradle-plugin/bin/test/GenerateTaskDslTest.kt b/modules/openapi-generator-gradle-plugin/bin/test/GenerateTaskDslTest.kt deleted file mode 100644 index c2a6e0244207..000000000000 --- a/modules/openapi-generator-gradle-plugin/bin/test/GenerateTaskDslTest.kt +++ /dev/null @@ -1,71 +0,0 @@ -package org.openapitools.generator.gradle.plugin - -import org.gradle.testkit.runner.GradleRunner -import org.gradle.testkit.runner.TaskOutcome -import org.testng.annotations.Test -import java.io.File -import kotlin.test.assertEquals -import kotlin.test.assertTrue - -class GenerateTaskDslTest : TestBase() { - override var temp: File = createTempDir(javaClass.simpleName) - - private val defaultBuildGradle = """ - plugins { - id 'org.openapi.generator' - } - openApiGenerate { - generatorName = "kotlin" - inputSpec = file("spec.yaml").absolutePath - outputDir = file("build/kotlin").absolutePath - apiPackage = "org.openapitools.example.api" - invokerPackage = "org.openapitools.example.invoker" - modelPackage = "org.openapitools.example.model" - configOptions = [ - dateLibrary: "java8" - ] - } - """.trimIndent() - - @Test - fun `openApiGenerate should create an expected file structure from DSL config`() { - // Arrange - val projectFiles = mapOf( - "spec.yaml" to javaClass.classLoader.getResourceAsStream("specs/petstore-v3.0.yaml") - ) - withProject(defaultBuildGradle, projectFiles) - - // Act - val result = GradleRunner.create() - .withProjectDir(temp) - .withArguments("openApiGenerate") - .withPluginClasspath() - .build() - - // Assert - assertTrue(result.output.contains("Successfully generated code to"), "User friendly generate notice is missing.") - - listOf( - "build/kotlin/.openapi-generator-ignore", - "build/kotlin/docs/PetsApi.md", - "build/kotlin/docs/Pets.md", - "build/kotlin/docs/Error.md", - "build/kotlin/docs/Pet.md", - "build/kotlin/README.md", - "build/kotlin/build.gradle", - "build/kotlin/.openapi-generator/VERSION", - "build/kotlin/settings.gradle", - "build/kotlin/src/main/kotlin/org/openapitools/example/model/Pets.kt", - "build/kotlin/src/main/kotlin/org/openapitools/example/model/Pet.kt", - "build/kotlin/src/main/kotlin/org/openapitools/example/model/Error.kt", - "build/kotlin/src/main/kotlin/org/openapitools/example/api/PetsApi.kt", - "build/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt" - ).map { - val f = File(temp, it) - assertTrue(f.exists() && f.isFile, "An expected file was not generated when invoking the generation.") - } - - assertEquals(TaskOutcome.SUCCESS, result.task(":openApiGenerate")?.outcome, - "Expected a successful run, but found ${result.task(":openApiGenerate")?.outcome}") - } -} \ No newline at end of file diff --git a/modules/openapi-generator-gradle-plugin/bin/test/GeneratorsTaskDslTest.kt b/modules/openapi-generator-gradle-plugin/bin/test/GeneratorsTaskDslTest.kt deleted file mode 100644 index f3373fd657e1..000000000000 --- a/modules/openapi-generator-gradle-plugin/bin/test/GeneratorsTaskDslTest.kt +++ /dev/null @@ -1,38 +0,0 @@ -package org.openapitools.generator.gradle.plugin - -import org.gradle.testkit.runner.GradleRunner -import org.gradle.testkit.runner.TaskOutcome -import org.testng.annotations.Test -import java.io.File -import kotlin.test.assertEquals -import kotlin.test.assertTrue - -class GeneratorsTaskDslTest : TestBase() { - override var temp: File = createTempDir(javaClass.simpleName) - - @Test - fun `openApiGenerators should list generators available to the user`() { - // Arrange - withProject(""" - | plugins { - | id 'org.openapi.generator' - | } - """.trimMargin()) - - // Act - val result = GradleRunner.create() - .withProjectDir(temp) - .withArguments("openApiGenerators") - .withPluginClasspath() - .build() - - // Assert - assertTrue(result.output.contains("The following generators are available:"), "User friendly generator notice is missing.") - assertTrue(result.output.contains("CLIENT generators:"), "Expected client generator header is missing.") - assertTrue(result.output.contains("android"), "Spot-checking listed client generators is missing a client generator.") - assertTrue(result.output.contains("SERVER generators:"), "Expected server generator header is missing.") - assertTrue(result.output.contains("kotlin-server"), "Spot-checking listed server generators is missing a server generator.") - assertEquals(TaskOutcome.SUCCESS, result.task(":openApiGenerators")?.outcome, - "Expected a successful run, but found ${result.task(":openApiGenerators")?.outcome}") - } -} \ No newline at end of file diff --git a/modules/openapi-generator-gradle-plugin/bin/test/MetaTaskDslTest.kt b/modules/openapi-generator-gradle-plugin/bin/test/MetaTaskDslTest.kt deleted file mode 100644 index fe857d1b94a8..000000000000 --- a/modules/openapi-generator-gradle-plugin/bin/test/MetaTaskDslTest.kt +++ /dev/null @@ -1,58 +0,0 @@ -package org.openapitools.generator.gradle.plugin - -import org.gradle.testkit.runner.GradleRunner -import org.gradle.testkit.runner.TaskOutcome -import org.testng.annotations.Test -import java.io.File -import kotlin.test.assertEquals -import kotlin.test.assertTrue - -class MetaTaskDslTest : TestBase() { - override var temp: File = createTempDir(javaClass.simpleName) - - @Test - fun `openApiMeta should generate desired project contents`() { - // Arrange - val buildDirReplacement = "\$buildDir/meta" - withProject(""" - | plugins { - | id 'org.openapi.generator' - | } - | - | openApiMeta { - | generatorName = "Sample" - | packageName = "org.openapitools.example" - | outputFolder = "$buildDirReplacement".toString() - | } - """.trimMargin()) - - // Act - val result = GradleRunner.create() - .withProjectDir(temp) - .withArguments("openApiMeta") - .withPluginClasspath() - .build() - - // Assert - assertTrue(result.output.contains("Wrote file to"), "User friendly write notice is missing.") - - // To avoid any OS-specific output causing issues with our stdout comparisons, only compare on expected filenames. - listOf( - "SampleGenerator.java", - "README.md", - "api.mustache", - "model.mustache", - "myFile.mustache", - "org.openapitools.codegen.CodegenConfig", - "pom.xml" - ).map { - assertTrue(result.output.contains(it), "Expected $it to be listed in gradle stdout.") - } - - assertEquals( - TaskOutcome.SUCCESS, - result.task(":openApiMeta")?.outcome, - "Expected a successful run, but found ${result.task(":openApiMeta")?.outcome}" - ) - } -} \ No newline at end of file diff --git a/modules/openapi-generator-gradle-plugin/bin/test/TestBase.kt b/modules/openapi-generator-gradle-plugin/bin/test/TestBase.kt deleted file mode 100644 index 47a1bfba9ec9..000000000000 --- a/modules/openapi-generator-gradle-plugin/bin/test/TestBase.kt +++ /dev/null @@ -1,34 +0,0 @@ -package org.openapitools.generator.gradle.plugin - -import org.testng.annotations.AfterMethod -import org.testng.annotations.BeforeMethod -import java.io.File -import java.io.InputStream - -abstract class TestBase { - protected open lateinit var temp: File - - @BeforeMethod - protected fun before() { - temp = createTempDir(javaClass.simpleName) - temp.deleteOnExit() - } - - @AfterMethod - protected fun after(){ - temp.deleteRecursively() - } - - protected fun withProject( - buildContents: String, - projectFiles: Map = mapOf() - ) { - val buildFile = File(temp,"build.gradle") - buildFile.writeText(buildContents) - - projectFiles.forEach { entry -> - val target = File(temp, entry.key) - entry.value.copyTo(target.outputStream()) - } - } -} \ No newline at end of file diff --git a/modules/openapi-generator-gradle-plugin/bin/test/ValidateTaskDslTest.kt b/modules/openapi-generator-gradle-plugin/bin/test/ValidateTaskDslTest.kt deleted file mode 100644 index acc066c98da3..000000000000 --- a/modules/openapi-generator-gradle-plugin/bin/test/ValidateTaskDslTest.kt +++ /dev/null @@ -1,99 +0,0 @@ -package org.openapitools.generator.gradle.plugin - -import org.gradle.testkit.runner.GradleRunner -import org.gradle.testkit.runner.TaskOutcome.FAILED -import org.gradle.testkit.runner.TaskOutcome.SUCCESS -import org.testng.annotations.Test -import java.io.File -import kotlin.test.assertEquals -import kotlin.test.assertTrue - -class ValidateTaskDslTest : TestBase() { - override var temp: File = createTempDir(javaClass.simpleName) - - @Test - fun `openApiValidate should fail on non-file spec`() { - // Arrange - withProject(""" - | plugins { - | id 'org.openapi.generator' - | } - | - | openApiValidate { - | inputSpec = "some_location" - | } - """.trimMargin()) - - // Act - val result = GradleRunner.create() - .withProjectDir(temp) - .withArguments("openApiValidate") - .withPluginClasspath() - .buildAndFail() - - // Assert - assertTrue(result.output.contains("unable to read location `some_location`"), "Unexpected/no message presented to the user for a spec pointing to an invalid URI.") - assertEquals(FAILED, result.task(":openApiValidate")?.outcome, - "Expected a failed run, but found ${result.task(":openApiValidate")?.outcome}") - } - - @Test - fun `openApiValidate should succeed on valid spec`() { - // Arrange - val projectFiles = mapOf( - "spec.yaml" to javaClass.classLoader.getResourceAsStream("specs/petstore-v3.0.yaml") - ) - - withProject(""" - | plugins { - | id 'org.openapi.generator' - | } - | - | openApiValidate { - | inputSpec = file("spec.yaml").absolutePath - | } - """.trimMargin(), projectFiles) - - // Act - val result = GradleRunner.create() - .withProjectDir(temp) - .withArguments("openApiValidate") - .withPluginClasspath() - .build() - - // Assert - assertTrue(result.output.contains("Spec is valid."), "Unexpected/no message presented to the user for a valid spec.") - assertEquals(SUCCESS, result.task(":openApiValidate")?.outcome, - "Expected a successful run, but found ${result.task(":openApiValidate")?.outcome}") - } - - @Test - fun `openApiValidate should fail on invalid spec`() { - // Arrange - val projectFiles = mapOf( - "spec.yaml" to javaClass.classLoader.getResourceAsStream("specs/petstore-v3.0-invalid.yaml") - ) - withProject(""" - | plugins { - | id 'org.openapi.generator' - | } - | - | openApiValidate { - | inputSpec = file('spec.yaml').absolutePath - | } - """.trimMargin(), projectFiles) - - // Act - val result = GradleRunner.create() - .withProjectDir(temp) - .withArguments("openApiValidate") - .withPluginClasspath() - .buildAndFail() - - // Assert - assertTrue(result.output.contains("Spec is invalid."), "Unexpected/no message presented to the user for an invalid spec.") - assertEquals(FAILED, result.task(":openApiValidate")?.outcome, - "Expected a failed run, but found ${result.task(":openApiValidate")?.outcome}") - } - -} \ No newline at end of file diff --git a/modules/openapi-generator-gradle-plugin/bin/test/specs/petstore-v3.0-invalid.yaml b/modules/openapi-generator-gradle-plugin/bin/test/specs/petstore-v3.0-invalid.yaml deleted file mode 100644 index 0f5c6fc29829..000000000000 --- a/modules/openapi-generator-gradle-plugin/bin/test/specs/petstore-v3.0-invalid.yaml +++ /dev/null @@ -1,103 +0,0 @@ -openapi: "3.0.0" -servers: - - url: http://petstore.swagger.io/v1 -paths: - /pets: - get: - summary: List all pets - operationId: listPets - tags: - - pets - parameters: - - name: limit - in: query - description: How many items to return at one time (max 100) - required: false - schema: - type: integer - format: int32 - responses: - '200': - description: A paged array of pets - headers: - x-next: - description: A link to the next page of responses - schema: - type: string - content: - application/json: - schema: - $ref: "#/components/schemas/Pets" - default: - description: unexpected error - content: - application/json: - schema: - $ref: "#/components/schemas/Error" - post: - summary: Create a pet - tags: - - pets - responses: - '201': - description: Null response - default: - description: unexpected error - content: - application/json: - schema: - $ref: "#/components/schemas/Error" - /pets/{petId}: - get: - summary: Info for a specific pet - operationId: showPetById - tags: - - pets - parameters: - - name: petId - in: path - required: true - description: The id of the pet to retrieve - schema: - type: string - responses: - '200': - description: Expected response to a valid request - content: - application/json: - schema: - $ref: "#/components/schemas/Pets" - default: - description: unexpected error - content: - application/json: - schema: - $ref: "#/components/schemas/Error" -components: - schemas: - Pet: - required: - - id - - name - properties: - id: - type: integer - format: int64 - name: - type: string - tag: - type: string - Pets: - type: array - items: - $ref: "#/components/schemas/Pet" - Error: - required: - - code - - message - properties: - code: - type: integer - format: int32 - message: - type: string diff --git a/modules/openapi-generator-gradle-plugin/bin/test/specs/petstore-v3.0.yaml b/modules/openapi-generator-gradle-plugin/bin/test/specs/petstore-v3.0.yaml deleted file mode 100644 index 264dbeabff12..000000000000 --- a/modules/openapi-generator-gradle-plugin/bin/test/specs/petstore-v3.0.yaml +++ /dev/null @@ -1,109 +0,0 @@ -openapi: "3.0.0" -info: - version: 1.0.0 - title: Swagger Petstore - license: - name: MIT -servers: - - url: http://petstore.swagger.io/v1 -paths: - /pets: - get: - summary: List all pets - operationId: listPets - tags: - - pets - parameters: - - name: limit - in: query - description: How many items to return at one time (max 100) - required: false - schema: - type: integer - format: int32 - responses: - '200': - description: A paged array of pets - headers: - x-next: - description: A link to the next page of responses - schema: - type: string - content: - application/json: - schema: - $ref: "#/components/schemas/Pets" - default: - description: unexpected error - content: - application/json: - schema: - $ref: "#/components/schemas/Error" - post: - summary: Create a pet - operationId: createPets - tags: - - pets - responses: - '201': - description: Null response - default: - description: unexpected error - content: - application/json: - schema: - $ref: "#/components/schemas/Error" - /pets/{petId}: - get: - summary: Info for a specific pet - operationId: showPetById - tags: - - pets - parameters: - - name: petId - in: path - required: true - description: The id of the pet to retrieve - schema: - type: string - responses: - '200': - description: Expected response to a valid request - content: - application/json: - schema: - $ref: "#/components/schemas/Pets" - default: - description: unexpected error - content: - application/json: - schema: - $ref: "#/components/schemas/Error" -components: - schemas: - Pet: - required: - - id - - name - properties: - id: - type: integer - format: int64 - name: - type: string - tag: - type: string - Pets: - type: array - items: - $ref: "#/components/schemas/Pet" - Error: - required: - - code - - message - properties: - code: - type: integer - format: int32 - message: - type: string diff --git a/modules/openapi-generator-gradle-plugin/build.gradle b/modules/openapi-generator-gradle-plugin/build.gradle index 5f09ef12209c..42be781a4de7 100644 --- a/modules/openapi-generator-gradle-plugin/build.gradle +++ b/modules/openapi-generator-gradle-plugin/build.gradle @@ -181,3 +181,5 @@ compileTestKotlin { jvmTarget = "1.8" } } + +uploadArchives.dependsOn 'check' diff --git a/modules/openapi-generator-gradle-plugin/src/test/kotlin/GenerateTaskDslTest.kt b/modules/openapi-generator-gradle-plugin/src/test/kotlin/GenerateTaskDslTest.kt index c2a6e0244207..076e544ddcec 100644 --- a/modules/openapi-generator-gradle-plugin/src/test/kotlin/GenerateTaskDslTest.kt +++ b/modules/openapi-generator-gradle-plugin/src/test/kotlin/GenerateTaskDslTest.kt @@ -48,14 +48,12 @@ class GenerateTaskDslTest : TestBase() { listOf( "build/kotlin/.openapi-generator-ignore", "build/kotlin/docs/PetsApi.md", - "build/kotlin/docs/Pets.md", "build/kotlin/docs/Error.md", "build/kotlin/docs/Pet.md", "build/kotlin/README.md", "build/kotlin/build.gradle", "build/kotlin/.openapi-generator/VERSION", "build/kotlin/settings.gradle", - "build/kotlin/src/main/kotlin/org/openapitools/example/model/Pets.kt", "build/kotlin/src/main/kotlin/org/openapitools/example/model/Pet.kt", "build/kotlin/src/main/kotlin/org/openapitools/example/model/Error.kt", "build/kotlin/src/main/kotlin/org/openapitools/example/api/PetsApi.kt",