Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into oshmoun-master
Browse files Browse the repository at this point in the history
  • Loading branch information
fa0311 committed Sep 22, 2023
2 parents 5a30c8f + 29033bf commit efc096c
Show file tree
Hide file tree
Showing 2,018 changed files with 55,991 additions and 6,916 deletions.
9 changes: 2 additions & 7 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,13 @@
- [ ] Run the following to [build the project](https://github.com/OpenAPITools/openapi-generator#14---build-projects) and update samples:
```
./mvnw clean package
./bin/generate-samples.sh
./bin/generate-samples.sh ./bin/configs/*.yaml
./bin/utils/export_docs_generators.sh
```
Commit all changed files.
This is important, as CI jobs will verify _all_ generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example `./bin/generate-samples.sh bin/configs/java*`.
For Windows users, please run the script in [Git BASH](https://gitforwindows.org/).
- [ ] In case you are adding a new generator, run the following additional script :
```
./bin/utils/ensure-up-to-date
```
Commit all changed files.
- [ ] File the PR against the [correct branch](https://github.com/OpenAPITools/openapi-generator/wiki/Git-Branches): `master` (7.0.1 - patch release), `7.1.x` (minor release - breaking changes with fallbacks), `8.0.x` (breaking changes without fallbacks)
- [ ] File the PR against the [correct branch](https://github.com/OpenAPITools/openapi-generator/wiki/Git-Branches): `master` (upcoming 7.1.0 minor release - breaking changes with fallbacks), `8.0.x` (breaking changes without fallbacks)
- [ ] If your PR is targeting a particular programming language, @mention the [technical committee](https://github.com/openapitools/openapi-generator/#62---openapi-generator-technical-committee) members, so they are more likely to review the pull request.
4 changes: 3 additions & 1 deletion .github/workflows/samples-dotnet6-client-echo-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ jobs:
(cd http-echo-server && npm install && npm start &)
- name: Build
working-directory: ${{ matrix.sample }}
run: dotnet build Org.OpenAPITools.sln
run: |
dotnet build Org.OpenAPITools.sln
dotnet test Org.OpenAPITools.sln
5 changes: 3 additions & 2 deletions .github/workflows/samples-java-server-jdk8.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ on:
- 'samples/server/petstore/java-vertx-web/**'
- 'samples/server/petstore/java-inflector/**'
- 'samples/server/petstore/java-pkmst/**'
# test in circleci instead
- 'samples/server/petstore/java-undertow/**'
pull_request:
paths:
#- 'samples/server/petstore/java-camel/**'
- 'samples/server/petstore/java-vertx-web/**'
- 'samples/server/petstore/java-inflector/**'
- 'samples/server/petstore/java-pkmst/**'
- 'samples/server/petstore/java-undertow/**'
#- 'samples/server/petstore/java-undertow/**'
jobs:
build:
name: Build Java Server
Expand All @@ -29,7 +30,7 @@ jobs:
- samples/server/petstore/java-vertx-web/
- samples/server/petstore/java-inflector/
- samples/server/petstore/java-pkmst/
- samples/server/petstore/java-undertow/
#- samples/server/petstore/java-undertow/
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v3
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ samples/server/petstore/kotlin-server/ktor/build
samples/server/petstore/kotlin-springboot/build
samples/client/petstore/kotlin*/src/main/kotlin/test/
samples/client/petstore/kotlin*/build/
samples/server/others/kotlin-server/jaxrs-spec/build/

# haskell
.stack-work
Expand Down
2 changes: 1 addition & 1 deletion .java-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.8
11
29 changes: 15 additions & 14 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ install:
- cmd: docker run -d -e SWAGGER_HOST=http://petstore.swagger.io -e SWAGGER_BASE_PATH=/v2 -p 80:8080 swaggerapi/petstore
- ps: Start-Sleep -s 120
- ps: $PSVersionTable.PSVersion
- ps: Install-Module -Name Pester -Force -Scope CurrentUser
- ps: Install-Module -Name Pester -Force -Scope CurrentUser -SkipPublisherCheck
build_script:
- dotnet --info
# build C# aspnetcore 5.0 server
Expand Down
6 changes: 6 additions & 0 deletions bin/configs/go-echo-api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
generatorName: go
outputDir: samples/client/echo_api/go
inputSpec: modules/openapi-generator/src/test/resources/3_0/echo_api.yaml
templateDir: modules/openapi-generator/src/main/resources/go
additionalProperties:
hideGenerationTimestamp: "true"
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
generatorName: java-undertow-server
outputDir: samples/server/petstore/java-undertow
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
templateDir: modules/openapi-generator/src/main/resources/java-undertow-server
additionalProperties:
hideGenerationTimestamp: "true"
6 changes: 6 additions & 0 deletions bin/configs/php-nextgen-echo-api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
generatorName: php-nextgen
outputDir: samples/client/echo_api/php-nextgen
inputSpec: modules/openapi-generator/src/test/resources/3_0/echo_api.yaml
templateDir: modules/openapi-generator/src/main/resources/php-nextgen
additionalProperties:
hideGenerationTimestamp: "true"
2 changes: 1 addition & 1 deletion bin/configs/php-nextgen.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
generatorName: php-nextgen
outputDir: samples/client/petstore/php-nextgen/OpenAPIClient-php
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml
inputSpec: modules/openapi-generator/src/test/resources/3_0/php-nextgen/petstore-with-fake-endpoints-models-for-testing.yaml
templateDir: modules/openapi-generator/src/main/resources/php-nextgen
2 changes: 1 addition & 1 deletion bin/configs/python-flask.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
generatorName: python-flask
outputDir: samples/server/petstore/python-flask
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml
inputSpec: modules/openapi-generator/src/test/resources/2_0/python-flask/petstore.yaml
templateDir: modules/openapi-generator/src/main/resources/python-flask
1 change: 0 additions & 1 deletion docs/generators/kotlin-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|parcelizeModels|toggle "@Parcelize" for generated models| |null|
|returnResponse|Whether generate API interface should return javax.ws.rs.core.Response instead of a deserialized entity. Only useful if interfaceOnly is true. This option is currently supported only when using jaxrs-spec library.| |false|
|serializableModel|boolean - toggle "implements Serializable" for generated models| |null|
|serializationLibrary|What serialization library to use: 'moshi' (default), or 'gson' or 'jackson' or 'kotlinx_serialization'| |moshi|
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |null|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |null|
|sourceFolder|source folder for generated code| |src/main/kotlin|
Expand Down
1 change: 0 additions & 1 deletion docs/generators/kotlin-spring.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|parcelizeModels|toggle "@Parcelize" for generated models| |null|
|reactive|use coroutines for reactive behavior| |false|
|serializableModel|boolean - toggle "implements Serializable" for generated models| |null|
|serializationLibrary|What serialization library to use: 'moshi' (default), or 'gson' or 'jackson' or 'kotlinx_serialization'| |moshi|
|serverPort|configuration the port in which the sever is to run on| |8080|
|serviceImplementation|generate stub service implementations that extends service interfaces. If this is set to true service interfaces will also be generated| |false|
|serviceInterface|generate service interfaces to go alongside controllers. In most cases this option would be used to update an existing project, so not to override implementations. Useful to help facilitate the generation gap pattern| |false|
Expand Down
1 change: 0 additions & 1 deletion docs/generators/kotlin-vertx.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|packageName|Generated artifact package name.| |org.openapitools|
|parcelizeModels|toggle "@Parcelize" for generated models| |null|
|serializableModel|boolean - toggle "implements Serializable" for generated models| |null|
|serializationLibrary|What serialization library to use: 'moshi' (default), or 'gson' or 'jackson' or 'kotlinx_serialization'| |moshi|
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |null|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |null|
|sourceFolder|source folder for generated code| |src/main/kotlin|
Expand Down
2 changes: 1 addition & 1 deletion modules/openapi-generator-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-project</artifactId>
<!-- RELEASE_VERSION -->
<version>7.0.1-SNAPSHOT</version>
<version>7.1.0-SNAPSHOT</version>
<!-- /RELEASE_VERSION -->
<relativePath>../..</relativePath>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion modules/openapi-generator-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<artifactId>openapi-generator-project</artifactId>
<groupId>org.openapitools</groupId>
<!-- RELEASE_VERSION -->
<version>7.0.1-SNAPSHOT</version>
<version>7.1.0-SNAPSHOT</version>
<!-- /RELEASE_VERSION -->
<relativePath>../..</relativePath>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion modules/openapi-generator-gradle-plugin/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# RELEASE_VERSION
openApiGeneratorVersion=7.0.1-SNAPSHOT
openApiGeneratorVersion=7.1.0-SNAPSHOT
# /RELEASE_VERSION

# BEGIN placeholders
Expand Down
2 changes: 1 addition & 1 deletion modules/openapi-generator-gradle-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-project</artifactId>
<!-- RELEASE_VERSION -->
<version>7.0.1-SNAPSHOT</version>
<version>7.1.0-SNAPSHOT</version>
<!-- /RELEASE_VERSION -->
<relativePath>../..</relativePath>
</parent>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# RELEASE_VERSION
openApiGeneratorVersion=7.0.1-SNAPSHOT
openApiGeneratorVersion=7.1.0-SNAPSHOT
# /RELEASE_VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ class OpenApiGeneratorPlugin : Plugin<Project> {
schemaMappings.set(generate.schemaMappings)
inlineSchemaNameMappings.set(generate.inlineSchemaNameMappings)
inlineSchemaOptions.set(generate.inlineSchemaOptions)
nameMappings.set(generate.nameMappings)
modelNameMappings.set(generate.modelNameMappings)
parameterNameMappings.set(generate.parameterNameMappings)
openapiNormalizer.set(generate.openapiNormalizer)
invokerPackage.set(generate.invokerPackage)
groupId.set(generate.groupId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,5 @@ open class OpenApiGeneratorValidateExtension(project: Project) {
/**
* Whether to offer recommendations related to the validated specification document.
*/
val recommend = project.objects.property<Boolean?>()

init {
applyDefaults()
}

@Suppress("MemberVisibilityCanBePrivate")
fun applyDefaults() = recommend.set(true)
val recommend = project.objects.property<Boolean>().convention(true)
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ open class GenerateTask @Inject constructor(private val objectFactory: ObjectFac
* Local root folder with spec files
*/
@Optional
@get:InputFile
@get:InputDirectory
@PathSensitive(PathSensitivity.RELATIVE)
val inputSpecRootDirectory = project.objects.property<String>();

Expand Down Expand Up @@ -585,10 +585,22 @@ open class GenerateTask @Inject constructor(private val objectFactory: ObjectFac
@Suppress("unused")
@TaskAction
fun doWork() {
inputSpecRootDirectory.ifNotEmpty { inputSpecRootDirectoryValue -> {
inputSpec.set(MergedSpecBuilder(inputSpecRootDirectoryValue, mergedFileName.get()).buildMergedSpec())
logger.info("Merge input spec would be used - {}", inputSpec.get())
}}
var resolvedInputSpec = ""

inputSpec.ifNotEmpty { value ->
resolvedInputSpec = value
}

remoteInputSpec.ifNotEmpty { value ->
resolvedInputSpec = value
}

inputSpecRootDirectory.ifNotEmpty { inputSpecRootDirectoryValue ->
run {
resolvedInputSpec = MergedSpecBuilder(inputSpecRootDirectoryValue, mergedFileName.getOrElse("merged")).buildMergedSpec()
logger.info("Merge input spec would be used - {}", resolvedInputSpec)
}
}

cleanupOutput.ifNotEmpty { cleanup ->
if (cleanup) {
Expand Down Expand Up @@ -655,6 +667,8 @@ open class GenerateTask @Inject constructor(private val objectFactory: ObjectFac
logger.warn("Both inputSpec and remoteInputSpec is specified. The remoteInputSpec will take priority over inputSpec.")
}

configurator.setInputSpec(resolvedInputSpec)

// now override with any specified parameters
verbose.ifNotEmpty { value ->
configurator.setVerbose(value)
Expand All @@ -668,14 +682,6 @@ open class GenerateTask @Inject constructor(private val objectFactory: ObjectFac
configurator.setSkipOverwrite(value ?: false)
}

inputSpec.ifNotEmpty { value ->
configurator.setInputSpec(value)
}

remoteInputSpec.ifNotEmpty { value ->
configurator.setInputSpec(value)
}

generatorName.ifNotEmpty { value ->
configurator.setGeneratorName(value)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ open class ValidateTask : DefaultTask() {

@Optional
@Input
val recommend = project.objects.property<Boolean?>()
val recommend = project.objects.property<Boolean>().convention(true)

@get:Internal
@set:Option(option = "input", description = "The input specification.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.TaskOutcome
import org.testng.annotations.Test
import java.io.File
import java.nio.file.Files.createDirectory
import java.nio.file.Files.createTempDirectory
import java.nio.file.Paths
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertTrue
Expand Down Expand Up @@ -88,6 +90,75 @@ class GenerateTaskDslTest : TestBase() {
)
}

@Test
fun `openApiGenerate should create an expected file structure from root directory config`() {
val projectFiles = mapOf(
"spec.yaml" to javaClass.classLoader.getResourceAsStream("specs/petstore-v3.0.yaml"),
"spec-2.yaml" to javaClass.classLoader.getResourceAsStream("specs/petstore-v3.1.yaml")
)

// Arrange
val buildContents = """
plugins {
id 'org.openapi.generator'
}
openApiGenerate {
generatorName = "kotlin"
inputSpecRootDirectory = file("specs").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()
val tempContractDirectory: File = createDirectory(Paths.get("${temp.path}/specs")).toFile()

File(temp, "build.gradle").writeText(buildContents)
projectFiles.forEach { entry ->
val target = File(tempContractDirectory, entry.key)
entry.value?.copyTo(target.outputStream())
}

// Act
val result = GradleRunner.create()
.withProjectDir(temp)
.withArguments("openApiGenerate", "--stacktrace")
.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/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/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: $f")
}

assertEquals(
TaskOutcome.SUCCESS, result.task(":openApiGenerate")?.outcome,
"Expected a successful run, but found ${result.task(":openApiGenerate")?.outcome}"
)
}

@Test
fun `openApiGenerate should create an expected file structure from DSL config`() {
// Arrange
Expand Down
Loading

0 comments on commit efc096c

Please sign in to comment.