Skip to content

Commit

Permalink
Preserve record accessor method names, build test data with JDK 17
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Edgar <[email protected]>
  • Loading branch information
MikeEdgar committed Nov 22, 2023
1 parent 3e5b167 commit c5d137e
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,14 @@ private static TypeResolver updateTypeResolvers(AnnotationScannerContext context
*/
static String propertyName(MethodInfo method) {
final String methodName = method.name();
final ClassInfo declaringClass = method.declaringClass();

if (declaringClass.isRecord() && declaringClass.recordComponent(methodName) != null) {
// This is a record and the method name is generated (or overridden) and
// matches the record component name. Do not modify further.
return methodName;
}

final int nameStart = methodNamePrefix(method).length();
final String propertyName;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.fasterxml.jackson.annotation.JsonUnwrapped;

import io.smallrye.openapi.api.constants.OpenApiConstants;
import io.smallrye.openapi.testdata.java.NonBean;
import test.io.smallrye.openapi.runtime.scanner.dataobject.SingleAnnotatedConstructorArgument;

class StandaloneSchemaScanTest extends IndexScannerTestBase {
Expand Down Expand Up @@ -822,4 +823,21 @@ class Bean {
printToConsole(result);
assertJsonEquals("components.schemas.parameterized-type-schema-config.json", result);
}

@Test
@SuppressWarnings("unused")
void testRecordWithPojoPrefixedRecordComponents() throws IOException, JSONException {
@Schema(name = "Bean")
class Bean {
NonBean record;
}

Index index = indexOf(NonBean.class, Bean.class);
OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner(emptyConfig(), index);

OpenAPI result = scanner.scan();

printToConsole(result);
assertJsonEquals("components.schemas.prefixed-record-component-names.json", result);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"openapi" : "3.0.3",
"components" : {
"schemas" : {
"Bean" : {
"type" : "object",
"properties" : {
"record" : {
"$ref" : "#/components/schemas/NonBean"
}
}
},
"NonBean" : {
"type" : "object",
"properties" : {
"isBoolean" : {
"type" : "boolean"
},
"getString" : {
"type" : "string"
},
"setInteger" : {
"format" : "int32",
"type" : "integer"
}
}
}
}
}
}
63 changes: 62 additions & 1 deletion testsuite/data/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@

<properties>
<kotlin.version>1.9.20</kotlin.version>
<maven.compiler.release>11</maven.compiler.release>
<java.version>17</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<maven.compiler.release>${java.version}</maven.compiler.release>
<version.mvn-jlink-wrapper>1.1.1</version.mvn-jlink-wrapper>
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
<quarkus.platform.version>3.5.3</quarkus.platform.version>
Expand Down Expand Up @@ -220,4 +224,61 @@
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>build-with-downloaded-jdk17</id>
<activation>
<jdk>(,17)</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>com.igormaznitsa</groupId>
<artifactId>mvn-jlink-wrapper</artifactId>
<version>${version.mvn-jlink-wrapper}</version>
<executions>
<execution>
<id>download-jdk</id>
<goals>
<goal>cache-jdk</goal>
</goals>
<configuration>
<jdkCachePath>${project.basedir}/jdk-cache</jdkCachePath>
<jdkPathProperty>custom-jdk-path</jdkPathProperty>
<provider>ADOPT</provider>
<providerConfig>
<release>${java.version}</release>
<arch>x64</arch> <!-- TODO select automatically, but how? -->
</providerConfig>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-compile</id>
<configuration>
<executable>${custom-jdk-path}/bin/javac</executable>
<fork>true</fork>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<javadocExecutable>${custom-jdk-path}/bin/javadoc</javadocExecutable>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.smallrye.openapi.testdata.java;

public record NonBean(
boolean isBoolean,
String getString,
int setInteger) {
}

0 comments on commit c5d137e

Please sign in to comment.