Skip to content

Commit

Permalink
remove operation id prefix (#873) (#880)
Browse files Browse the repository at this point in the history
Co-authored-by: yuhaibohotmail <48646226+yuhaibohotmail@users.noreply.github.com>
  • Loading branch information
github-actions[bot] and yuhaibohotmail authored Nov 29, 2024
1 parent b4d52c0 commit 10be4d3
Show file tree
Hide file tree
Showing 10 changed files with 264 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public enum ConfigName {
USE_FIELD_NAME_IN_PART_FILENAME("use-field-name-in-part-filename"),
ADDITIONAL_PROPERTIES_AS_ATTRIBUTE("additional-properties-as-attribute"),
ADDITIONAL_REQUEST_ARGS("additional-request-args"),
REMOVE_OPERATION_ID_PREFIX("remove-operation-id-prefix"),
BEAN_VALIDATION("use-bean-validation");

private final String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,11 @@ public class SpecItemConfig extends CommonItemConfig {
*/
@ConfigItem(name = "model-name-prefix")
public Optional<String> modelNamePrefix;

/**
* Remove operation id prefix
*/
@ConfigItem(name = "remove-operation-id-prefix")
public Optional<String> removeOperationIdPrefix;

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.INPUT_BASE_DIR;
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.MODEL_NAME_PREFIX;
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.MODEL_NAME_SUFFIX;
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.REMOVE_OPERATION_ID_PREFIX;
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.TEMPLATE_BASE_DIR;
import static io.quarkiverse.openapi.generator.deployment.CodegenConfig.ConfigName.VALIDATE_SPEC;

Expand Down Expand Up @@ -228,6 +229,9 @@ protected void generate(OpenApiGeneratorOptions options) {
getModelNamePrefix(config, openApiFilePath)
.ifPresent(generator::withModelNamePrefix);

getRemoveOperationIdPrefix(config, openApiFilePath)
.ifPresent(generator::withRemoveOperationIdPrefix);

getValues(config, openApiFilePath, CodegenConfig.ConfigName.MUTINY, Boolean.class)
.ifPresent(generator::withMutiny);

Expand Down Expand Up @@ -350,6 +354,11 @@ private Optional<String> getModelNamePrefix(final Config config, final Path open
.getOptionalValue(getSpecConfigName(MODEL_NAME_PREFIX, openApiFilePath), String.class);
}

private Optional<Boolean> getRemoveOperationIdPrefix(final Config config, final Path openApiFilePath) {
return config
.getOptionalValue(getSpecConfigName(REMOVE_OPERATION_ID_PREFIX, openApiFilePath), Boolean.class);
}

private Optional<String> getInputBaseDirRelativeToModule(final Path sourceDir, final Config config) {
return config.getOptionalValue(getGlobalConfigName(INPUT_BASE_DIR), String.class).map(baseDir -> {
int srcIndex = sourceDir.toString().lastIndexOf("src");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,11 @@ public OpenApiClientGeneratorWrapper withModelNameSuffix(final String modelNameS
return this;
}

public OpenApiClientGeneratorWrapper withRemoveOperationIdPrefix(final Boolean removeOperationIdPrefix) {
this.configurator.setRemoveOperationIdPrefix(removeOperationIdPrefix);
return this;
}

public OpenApiClientGeneratorWrapper withModelNamePrefix(final String modelNamePrefix) {
this.configurator.setModelNamePrefix(modelNamePrefix);
return this;
Expand Down
1 change: 1 addition & 0 deletions client/integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<module>part-filename</module>
<module>polymorphism</module>
<module>return-response</module>
<module>remove-operationid-prefix</module>
<module>security</module>
<module>simple</module>
<module>skip-validation</module>
Expand Down
91 changes: 91 additions & 0 deletions client/integration-tests/remove-operationid-prefix/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.quarkiverse.openapi.generator</groupId>
<artifactId>quarkus-openapi-generator-integration-tests</artifactId>
<version>3.0.0-SNAPSHOT</version>
</parent>

<artifactId>quarkus-openapi-generator-it-remove-operationid-prefix</artifactId>
<name>Quarkus - Openapi Generator - Integration Tests - Client - remove operation id prefix</name>
<description>Example project for general usage with remove operation id prefix</description>

<dependencies>
<dependency>
<groupId>io.quarkiverse.openapi.generator</groupId>
<artifactId>quarkus-openapi-generator</artifactId>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>build</goal>
<goal>generate-code</goal>
<goal>generate-code-tests</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>native-image</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>${native.surefire.skip}</skipTests>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<systemPropertyVariables>
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<quarkus.package.type>native</quarkus.package.type>
</properties>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
---
openapi: 3.0.3
info:
title: code-with-quarkus API
version: 1.0.0-SNAPSHOT
servers:
- url: http://localhost:8080
description: Auto generated value
- url: http://0.0.0.0:8080
description: Auto generated value
paths:
/users:
get:
tags:
- User Resource
description: Find All
operationId: UserResource_findAll
responses:
"200":
description: OK
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/User"
post:
tags:
- User Resource
description: Add
operationId: UserResource_add
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/User"
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/User"
/users/{id}:
get:
tags:
- User Resource
description: Find
operationId: UserResource_find
parameters:
- name: id
in: path
required: true
schema:
format: int32
type: integer
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/User"
put:
tags:
- User Resource
description: Update
operationId: UserResource_update
parameters:
- name: id
in: path
required: true
schema:
format: int32
type: integer
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/User"
responses:
"204":
description: No Content
delete:
tags:
- User Resource
description: Delete
operationId: UserResource_delete
parameters:
- name: id
in: path
required: true
schema:
format: int32
type: integer
responses:
"204":
description: No Content
components:
schemas:
User:
type: object
properties:
id:
format: int32
type: integer
name:
type: string
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
quarkus.rest-client.quarkus_simple_openapi_yaml.url=http://localhost:8080
quarkus.openapi-generator.codegen.spec.openapi_remove_operation_id_prefix_yaml.remove-operation-id-prefix=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package io.quarkiverse.openapi.generator.it;

import static org.assertj.core.api.Assertions.assertThatCode;

import org.junit.jupiter.api.Test;

import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
public class RemoveOperationIdPrefixTest {

String apiClassName = "org.openapi.quarkus.openapi_remove_operation_id_prefix_yaml.api.UserResourceApi";
String modelClassName = "org.openapi.quarkus.openapi_remove_operation_id_prefix_yaml.model.User";

@Test
void apiIsBeingGenerated() {
assertThatCode(() -> Class.forName(apiClassName).getMethod("find", Integer.class))
.doesNotThrowAnyException();

assertThatCode(() -> Class.forName(apiClassName).getMethod("findAll"))
.doesNotThrowAnyException();

assertThatCode(() -> Class.forName(apiClassName).getMethod("add", Class.forName(modelClassName)))
.doesNotThrowAnyException();

assertThatCode(() -> Class.forName(apiClassName).getMethod("update", Integer.class, Class.forName(modelClassName)))
.doesNotThrowAnyException();

assertThatCode(() -> Class.forName(apiClassName).getMethod("delete", Integer.class))
.doesNotThrowAnyException();

}
}
7 changes: 7 additions & 0 deletions docs/modules/ROOT/pages/includes/getting-started.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ quarkus.openapi-generator.codegen.spec.petstore_json.model-name-suffix=CustomMod
quarkus.openapi-generator.codegen.spec.petstore_json.model-name-prefix=CustomModelPrefix
----

You can remove operationId prefix (e.g. User_findAll=> findAll). To do that, you must define the following properties:

[source,properties]
----
quarkus.openapi-generator.codegen.spec.petstore_json.remove-operation-id-prefix=true
----

The same way you can add any additional annotations to the generated api files with `additional-api-type-annotations`. Given you want to include Foo and Bar annotations, you must define additional-api-type-annotations as:

[source,properties]
Expand Down

0 comments on commit 10be4d3

Please sign in to comment.