openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[REQ][Java] useRecords beyond Spring: shared logic and the java client

Open Sekator778 opened this issue 1 month ago • 5 comments

#10490 asks for Java models as records. useRecords for Spring is on master for 7.27.0, with allOf open in #25492. I'd like to offer the same option in the java client: restclient, webclient and native first, okhttp-gson last, one library per PR.

flowchart LR
  H["record decision in one helper"] --> S["spring: on master"]
  H --> J["java client: library by library"]

The first PR only moves that decision out of SpringCodegen, and regenerating the samples must change no file; the other Java generators never reach it. Gson is untried, and if this doesn't fit, useRecords stays Spring-only. @martin-mfg @KannaKim @Zomzog, go or no-go before I start?

Sekator778 avatar Oct 31 '26 18:10 Sekator778

This sounds like a good update to me. Do you have any thought on this @wing328

KannaKim avatar Oct 31 '26 21:10 KannaKim

A small improvement: Add java 17 support to JavaFileAssert. This can be done by upgrading javaparser-core to 3.28.2. in JavaFileAssert:

public static ParserConfiguration JAVA_17 = new ParserConfiguration().setLanguageLevel(ParserConfiguration.LanguageLevel.JAVA_17);

    public static JavaFileAssert assertThat(ParserConfiguration parserConfiguration, final Path path) {
        ParserConfiguration oldParserConfiguration = StaticJavaParser.getParserConfiguration();
        try {
            StaticJavaParser.setConfiguration(parserConfiguration);
            return new JavaFileAssert(StaticJavaParser.parse(path));
        } catch (IOException | ParseProblemException e) {
            throw new RuntimeException("Exception while reading file: " + path, e);
        } finally {
            StaticJavaParser.setConfiguration(oldParserConfiguration);
        }
    }

    public JavaFileAssert isRecord() {
        Assertions.assertThat(actual.getType(0).asClassOrInterfaceDeclaration())
                .withFailMessage("Expected type %s to be a record", actual.getType(0).getName().asString())
                .extracting(ClassOrInterfaceDeclaration::isRecordDeclaration)
                .isEqualTo(true);
        return this;
    }

jpfinne avatar Nov 01 '26 12:11 jpfinne

@wing328 KannaKim, from the Java and Spring committees, supports this above. Should I go ahead with the shared logic and the java client, one library per PR with default output unchanged, or keep records Spring-only?

Sekator778 avatar Nov 12 '26 11:11 Sekator778

@wing328 thanks for merging #25501 and #25641. Should I go ahead with records beyond Spring: the shared logic in AbstractJavaCodegen, then the java client one library per PR, default output unchanged? #25492, the allOf step for Spring records, is ready for review as well.

Sekator778 avatar Dec 02 '26 11:12 Sekator778

Should I go ahead with records beyond Spring: the shared logic in AbstractJavaCodegen, then the java client one library per PR, default output unchanged?

yes please

wing328 avatar Dec 02 '26 12:12 wing328