on 2024 Feb 23 5:19 AM
Hi community,
I'm attempting to use the Cloud SDK's OpenAPI Client in a CAP Java project, but I'm unable to access the generated API client. The structure of my project is as follows:
The OpenAPI Client has been generated with the following setting in pom.xml.
<plugin>
<groupId>com.sap.cloud.sdk.datamodel</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>${cloud.sdk.version}</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<phase>generate-sources</phase>
</execution>
</executions>
<configuration>
<inputSpec>${project.basedir}/api-specs/AuthorizationAPI.yaml</inputSpec>
<outputDirectory>${project.basedir}/openapi</outputDirectory>
<apiPackage>customer.cap_openapi.generated.authorization.api</apiPackage>
<modelPackage>customer.cap_openapi.generated.authorization.model</modelPackage>
<apiMaturity>released</apiMaturity>
</configuration>
</plugin> Here's the source for the CAP event handler:
package customer.cap_openapi.handlers;
import org.springframework.stereotype.Component;
import com.sap.cds.services.handler.annotations.On;
import com.sap.cds.services.handler.annotations.ServiceName;
import com.sap.cloud.sdk.cloudplatform.connectivity.DestinationAccessor;
import com.sap.cloud.sdk.cloudplatform.connectivity.HttpDestination;
import customer.cap_openapi.generated.authorization.api.RoleCollectionsApi;
import cds.gen.authorizationservice.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component
@ServiceName(AuthorizationService_.CDS_NAME)
class AuthorizationServiceHandler {
Logger logger = LoggerFactory.getLogger(AuthorizationServiceHandler.class);
@On(event = GetRoleCollectionsContext.CDS_NAME)
public void getRoleCollections(GetRoleCollectionsContext context) {
logger.info("getRoleCollection handler");
HttpDestination destination = DestinationAccessor.getDestination("xsuaa").asHttp();
// RoleCollectionsApi rolecollectionApi = new RoleCollectionsApi(destination);
}
}I'm encountering the error "The import customer.cap_openapi.generated cannot be resolved". Is the srv/openapi directory the appropriate place to generate the OpenAPI Client? How can I make the Open API client accessible from the event handler source?
The code for the project is available in the following Git repository: https://github.com/miyasuta/cap-openapi/tree/generate_client
Request clarification before answering.
The issue has been resolved with the following output directory:
<outputDirectory>${project.basedir}/src/gen/java</outputDirectory>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 18 | |
| 7 | |
| 6 | |
| 6 | |
| 6 | |
| 4 | |
| 3 | |
| 3 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.