Skip to content

Commit 62d0e3a

Browse files
authored
[kotlin-spring] fix BigDecimal default value failed to compile (#17956)
1 parent 34a386c commit 62d0e3a

File tree

22 files changed

+605
-2
lines changed

22 files changed

+605
-2
lines changed

.github/workflows/samples-kotlin-server.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jobs:
2727
sample:
2828
# server
2929
- samples/server/petstore/kotlin-springboot
30+
- samples/server/petstore/kotlin-springboot-bigdecimal-default
3031
- samples/server/petstore/kotlin-springboot-delegate
3132
- samples/server/petstore/kotlin-springboot-modelMutable
3233
- samples/server/petstore/kotlin-springboot-reactive
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
generatorName: kotlin-spring
2+
outputDir: samples/server/petstore/kotlin-springboot-bigdecimal-default
3+
library: spring-boot
4+
inputSpec: modules/openapi-generator/src/test/resources/3_0/issue_14584_bigdecimal_default.yaml
5+
templateDir: modules/openapi-generator/src/main/resources/kotlin-spring

modules/openapi-generator/src/main/resources/kotlin-spring/dataClassOptVar.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
@Schema({{#example}}example = "{{#lambdaRemoveLineBreak}}{{#lambdaEscapeInNormalString}}{{{.}}}{{/lambdaEscapeInNormalString}}{{/lambdaRemoveLineBreak}}", {{/example}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}description = "{{{description}}}"){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}}
33
@ApiModelProperty({{#example}}example = "{{#lambdaRemoveLineBreak}}{{#lambdaEscapeInNormalString}}{{{.}}}{{/lambdaEscapeInNormalString}}{{/lambdaRemoveLineBreak}}", {{/example}}{{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}value = "{{{description}}}"){{/swagger1AnnotationLibrary}}{{#deprecated}}
44
@Deprecated(message = ""){{/deprecated}}
5-
@get:JsonProperty("{{{baseName}}}"){{#isInherited}} override{{/isInherited}} {{>modelMutable}} {{{name}}}: {{#isEnum}}{{#isArray}}{{baseType}}<{{/isArray}}{{classname}}.{{{nameInCamelCase}}}{{#isArray}}>{{/isArray}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}? = {{{defaultValue}}}{{^defaultValue}}null{{/defaultValue}}
5+
@get:JsonProperty("{{{baseName}}}"){{#isInherited}} override{{/isInherited}} {{>modelMutable}} {{{name}}}: {{#isEnum}}{{#isArray}}{{baseType}}<{{/isArray}}{{classname}}.{{{nameInCamelCase}}}{{#isArray}}>{{/isArray}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}? = {{^defaultValue}}null{{/defaultValue}}{{#defaultValue}}{{^isNumber}}{{{defaultValue}}}{{/isNumber}}{{#isNumber}}{{{dataType}}}("{{{defaultValue}}}"){{/isNumber}}{{/defaultValue}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{{#useBeanValidation}}{{>beanValidation}}{{>beanValidationModel}}{{/useBeanValidation}}{{#swagger2AnnotationLibrary}}
22
@Schema({{#example}}example = "{{#lambdaRemoveLineBreak}}{{#lambdaEscapeInNormalString}}{{{.}}}{{/lambdaEscapeInNormalString}}{{/lambdaRemoveLineBreak}}", {{/example}}required = true, {{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}description = "{{{description}}}"){{/swagger2AnnotationLibrary}}{{#swagger1AnnotationLibrary}}
33
@ApiModelProperty({{#example}}example = "{{#lambdaRemoveLineBreak}}{{#lambdaEscapeInNormalString}}{{{.}}}{{/lambdaEscapeInNormalString}}{{/lambdaRemoveLineBreak}}", {{/example}}required = true, {{#isReadOnly}}readOnly = {{{isReadOnly}}}, {{/isReadOnly}}value = "{{{description}}}"){{/swagger1AnnotationLibrary}}
4-
@get:JsonProperty("{{{baseName}}}", required = true){{#isInherited}} override{{/isInherited}} {{>modelMutable}} {{{name}}}: {{#isEnum}}{{#isArray}}{{baseType}}<{{/isArray}}{{classname}}.{{{nameInCamelCase}}}{{#isArray}}>{{/isArray}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{#isNullable}}?{{/isNullable}}{{#defaultValue}} = {{{.}}}{{/defaultValue}}
4+
@get:JsonProperty("{{{baseName}}}", required = true){{#isInherited}} override{{/isInherited}} {{>modelMutable}} {{{name}}}: {{#isEnum}}{{#isArray}}{{baseType}}<{{/isArray}}{{classname}}.{{{nameInCamelCase}}}{{#isArray}}>{{/isArray}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{#isNullable}}?{{/isNullable}}{{#defaultValue}} = {{^isNumber}}{{{defaultValue}}}{{/isNumber}}{{#isNumber}}{{{dataType}}}("{{{defaultValue}}}"){{/isNumber}}{{/defaultValue}}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
openapi: 3.0.0
2+
info:
3+
version: 1.0.0
4+
title: Demo
5+
paths:
6+
'/test':
7+
post:
8+
requestBody:
9+
content:
10+
application/json:
11+
schema:
12+
$ref: "#/components/schemas/Apa"
13+
required: true
14+
responses:
15+
200:
16+
description: Successful operation
17+
18+
components:
19+
schemas:
20+
Apa:
21+
type: object
22+
required:
23+
- bepa
24+
- cepa
25+
properties:
26+
bepa:
27+
type: number
28+
format: long
29+
default: 0
30+
cepa:
31+
type: number
32+
default: 6.28318
33+
depa:
34+
type: number
35+
default: 71
36+
epa:
37+
type: number
38+
nullable: false
39+
default: -71
40+
fepa:
41+
type: number
42+
nullable: true
43+
deprecated: true
44+
default: 100
45+
gepa:
46+
type: number
47+
nullable: true
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# OpenAPI Generator Ignore
2+
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
3+
4+
# Use this file to prevent files from being overwritten by the generator.
5+
# The patterns follow closely to .gitignore or .dockerignore.
6+
7+
# As an example, the C# client generator defines ApiClient.cs.
8+
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
9+
#ApiClient.cs
10+
11+
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
12+
#foo/*/qux
13+
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
14+
15+
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
16+
#foo/**/qux
17+
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
18+
19+
# You can also negate patterns with an exclamation (!).
20+
# For example, you can ignore all files in a docs folder with the file extension .md:
21+
#docs/*.md
22+
# Then explicitly reverse the ignore rule for a single file:
23+
#!docs/README.md
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
README.md
2+
build.gradle.kts
3+
pom.xml
4+
settings.gradle
5+
src/main/kotlin/org/openapitools/Application.kt
6+
src/main/kotlin/org/openapitools/HomeController.kt
7+
src/main/kotlin/org/openapitools/SpringDocConfiguration.kt
8+
src/main/kotlin/org/openapitools/api/ApiUtil.kt
9+
src/main/kotlin/org/openapitools/api/Exceptions.kt
10+
src/main/kotlin/org/openapitools/api/TestApiController.kt
11+
src/main/kotlin/org/openapitools/model/Apa.kt
12+
src/main/resources/application.yaml
13+
src/main/resources/openapi.yaml
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.4.0-SNAPSHOT
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# demo
2+
3+
This Kotlin based [Spring Boot](https://spring.io/projects/spring-boot) application has been generated using the [OpenAPI Generator](https://github.com/OpenAPITools/openapi-generator).
4+
5+
## Getting Started
6+
7+
This document assumes you have either maven or gradle available, either via the wrapper or otherwise. This does not come with a gradle / maven wrapper checked in.
8+
9+
By default a [`pom.xml`](pom.xml) file will be generated. If you specified `gradleBuildFile=true` when generating this project, a `build.gradle.kts` will also be generated. Note this uses [Gradle Kotlin DSL](https://github.com/gradle/kotlin-dsl).
10+
11+
To build the project using maven, run:
12+
```bash
13+
mvn package && java -jar target/openapi-spring-1.0.0.jar
14+
```
15+
16+
To build the project using gradle, run:
17+
```bash
18+
gradle build && java -jar build/libs/openapi-spring-1.0.0.jar
19+
```
20+
21+
If all builds successfully, the server should run on [http://localhost:8080/](http://localhost:8080/)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
2+
3+
buildscript {
4+
repositories {
5+
mavenCentral()
6+
}
7+
dependencies {
8+
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.6.7")
9+
}
10+
}
11+
12+
group = "org.openapitools"
13+
version = "1.0.0"
14+
15+
repositories {
16+
mavenCentral()
17+
}
18+
19+
tasks.withType<KotlinCompile> {
20+
kotlinOptions.jvmTarget = "1.8"
21+
}
22+
23+
plugins {
24+
val kotlinVersion = "1.6.21"
25+
id("org.jetbrains.kotlin.jvm") version kotlinVersion
26+
id("org.jetbrains.kotlin.plugin.jpa") version kotlinVersion
27+
id("org.jetbrains.kotlin.plugin.spring") version kotlinVersion
28+
id("org.springframework.boot") version "2.6.7"
29+
id("io.spring.dependency-management") version "1.0.11.RELEASE"
30+
}
31+
32+
dependencies {
33+
compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
34+
compile("org.jetbrains.kotlin:kotlin-reflect")
35+
compile("org.springframework.boot:spring-boot-starter-web")
36+
compile("org.springdoc:springdoc-openapi-ui:1.6.8")
37+
38+
compile("com.google.code.findbugs:jsr305:3.0.2")
39+
compile("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml")
40+
compile("com.fasterxml.jackson.dataformat:jackson-dataformat-xml")
41+
compile("com.fasterxml.jackson.datatype:jackson-datatype-jsr310")
42+
compile("com.fasterxml.jackson.module:jackson-module-kotlin")
43+
compile("jakarta.validation:jakarta.validation-api")
44+
compile("jakarta.annotation:jakarta.annotation-api:2.1.0")
45+
46+
testCompile("org.jetbrains.kotlin:kotlin-test-junit5")
47+
testCompile("org.springframework.boot:spring-boot-starter-test") {
48+
exclude(module = "junit")
49+
}
50+
}

0 commit comments

Comments
 (0)