Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I18N-1323 Update Mojito CLI to use OpenAPI spec for rest calls #201

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
7aaa625
I18N-1323 Update Mojito CLI to use OpenAPI spec for rest calls
DarKhaos Nov 21, 2024
c549187
I18N-1323 Update Mojito CLI to use OpenAPI spec for rest calls
DarKhaos Nov 22, 2024
544298a
I18N-1323 Update Mojito CLI to use OpenAPI spec for rest calls
DarKhaos Nov 23, 2024
5d4d8ff
I18N-1323 Update Mojito CLI to use OpenAPI spec for rest calls
DarKhaos Nov 25, 2024
4c69da0
I18N-1323 Update Mojito CLI to use OpenAPI spec for rest calls
DarKhaos Nov 26, 2024
1c27feb
I18N-1323 Update Mojito CLI to use OpenAPI spec for rest calls
DarKhaos Nov 26, 2024
326f410
I18N-1323 Update Mojito CLI to use OpenAPI spec for rest calls
DarKhaos Nov 26, 2024
2729602
I18N-1323 Update Mojito CLI to use OpenAPI spec for rest calls
DarKhaos Nov 26, 2024
bc24ee7
I18N-1323 Update Mojito CLI to use OpenAPI spec for rest calls
DarKhaos Nov 26, 2024
38f17ed
I18N-1323 Update Mojito CLI to use OpenAPI spec for rest calls
DarKhaos Nov 27, 2024
e6d871c
I18N-1323 Update Mojito CLI to use OpenAPI spec for rest calls
DarKhaos Nov 27, 2024
22e08d2
I18N-1323 Update Mojito CLI to use OpenAPI spec for rest calls
DarKhaos Nov 27, 2024
e187373
I18N-1323 Update Mojito CLI to use OpenAPI spec for rest calls
DarKhaos Nov 27, 2024
38c1c4a
I18N-1323 Update Mojito CLI to use OpenAPI spec for rest calls
DarKhaos Nov 28, 2024
9cc7927
I18N-1323 Update Mojito CLI to use OpenAPI spec for rest calls
DarKhaos Nov 28, 2024
0e9bd87
I18N-1365 - Refactor Mojito CLI to use generated code
DarKhaos Dec 2, 2024
bbce39e
I18N-1323 Update Mojito CLI to use OpenAPI spec for rest calls
DarKhaos Dec 6, 2024
c44ef6d
I18N-1323 Update Mojito CLI to use OpenAPI spec for rest calls
DarKhaos Dec 9, 2024
674c214
I18N-1323 Update Mojito CLI to use OpenAPI spec for rest calls
DarKhaos Dec 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ release.properties
/tmp/
/local/
.vscode/
/webapp/src/main/resources/openapi.*
84 changes: 78 additions & 6 deletions cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
</parent>

<properties>
<io-swagger-codegen-v3>3.0.64</io-swagger-codegen-v3>
<okhttp-version>2.7.5</okhttp-version>
<gson-version>2.11.0</gson-version>
<gson-fire-version>1.9.0</gson-fire-version>
<threetenbp-version>1.7.0</threetenbp-version>
<javax-annotation>1.3.2</javax-annotation>
</properties>

<dependencies>
Expand All @@ -31,21 +37,20 @@
</dependency>

<dependency>
<groupId>com.box.l10n.mojito</groupId>
<artifactId>mojito-webapp</artifactId>
<version>0.111-SNAPSHOT</version>
<scope>test</scope>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>

<dependency>
<groupId>com.box.l10n.mojito</groupId>
<artifactId>mojito-common</artifactId>
<artifactId>mojito-webapp</artifactId>
<version>0.111-SNAPSHOT</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.box.l10n.mojito</groupId>
<artifactId>mojito-restclient</artifactId>
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed restclient dependency

<artifactId>mojito-common</artifactId>
<version>0.111-SNAPSHOT</version>
</dependency>

Expand Down Expand Up @@ -107,6 +112,47 @@
<artifactId>reactor-core</artifactId>
</dependency>

<dependency>
<groupId>io.swagger.codegen.v3</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>${io-swagger-codegen-v3}</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp</groupId>
<artifactId>okhttp</artifactId>
<version>${okhttp-version}</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp</groupId>
<artifactId>logging-interceptor</artifactId>
<version>${okhttp-version}</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp</groupId>
<artifactId>okhttp-urlconnection</artifactId>
<version>${okhttp-version}</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gson-version}</version>
</dependency>
<dependency>
<groupId>io.gsonfire</groupId>
<artifactId>gson-fire</artifactId>
<version>${gson-fire-version}</version>
</dependency>
<dependency>
<groupId>org.threeten</groupId>
<artifactId>threetenbp</artifactId>
<version>${threetenbp-version}</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>${javax-annotation}</version>
</dependency>

</dependencies>

<build>
Expand Down Expand Up @@ -208,6 +254,32 @@
</configuration>
<version>7.0.0</version>
</plugin>
<plugin>
<groupId>io.swagger.codegen.v3</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.parent.basedir}/webapp/src/main/resources/openapi.json</inputSpec>
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It points to the file generated in the webapp module

<language>java</language>
<generateApiTests>false</generateApiTests>
<generateModelTests>false</generateModelTests>
<generateApiDocumentation>false</generateApiDocumentation>
<generateModelDocumentation>false</generateModelDocumentation>
<configOptions>
<dateLibrary>java8</dateLibrary>
<java8>true</java8>
</configOptions>
<apiPackage>${parent.groupId}.cli.apiclient</apiPackage>
<modelPackage>${parent.groupId}.cli.model</modelPackage>
<invokerPackage>${parent.groupId}.cli.apiclient</invokerPackage>
</configuration>
</execution>
</executions>
</plugin>
</plugins>

</build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.box.l10n.mojito.cli.apiclient;

import com.box.l10n.mojito.cli.model.AICheckRequest;
import com.box.l10n.mojito.cli.model.AICheckResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AiChecksWsApiProxy extends AiChecksWsApi {
/** logger */
static Logger logger = LoggerFactory.getLogger(AiChecksWsApiProxy.class);

public AiChecksWsApiProxy(ApiClient apiClient) {
super(apiClient);
}

@Override
public AICheckResponse executeAIChecks(AICheckRequest body) throws ApiException {
logger.debug("Received request to execute AI checks");
return super.executeAIChecks(body);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.box.l10n.mojito.cli.apiclient;

import com.box.l10n.mojito.cli.model.AIPromptContextMessageCreateRequest;
import com.box.l10n.mojito.cli.model.AIPromptCreateRequest;
import com.box.l10n.mojito.cli.model.AITranslationLocalePromptOverridesRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AiPromptWsApiProxy extends AiPromptWsApi {
/** logger */
static Logger logger = LoggerFactory.getLogger(AssetWsApiProxy.class);

public AiPromptWsApiProxy(ApiClient apiClient) {
super(apiClient);
}

@Override
public String deleteRepositoryLocalePromptOverrides(
AITranslationLocalePromptOverridesRequest body) throws ApiException {
logger.debug("Received request to delete repository locale prompt overrides");
return super.deleteRepositoryLocalePromptOverrides(body);
}

@Override
public String createOrUpdateRepositoryLocalePromptOverrides(
AITranslationLocalePromptOverridesRequest body) throws ApiException {
logger.debug("Received request to create or update repository locale prompt overrides");
return super.createOrUpdateRepositoryLocalePromptOverrides(body);
}

@Override
public void addPromptToRepository(Long promptId, String repositoryName, String promptType)
throws ApiException {
logger.debug("Received request to add prompt id {} to {} repository", promptId, repositoryName);
super.addPromptToRepository(promptId, repositoryName, promptType);
}

@Override
public Long createPrompt(AIPromptCreateRequest body) throws ApiException {
logger.debug("Received request to create prompt");
return super.createPrompt(body);
}

@Override
public Long createPromptMessage(AIPromptContextMessageCreateRequest body) throws ApiException {
logger.debug("Received request to create prompt context message");
return super.createPromptMessage(body);
}

@Override
public void deletePrompt(Long promptId) throws ApiException {
logger.debug("Received request to delete prompt id {}", promptId);
super.deletePrompt(promptId);
}

@Override
public void deletePromptMessage(Long contextMessageId) throws ApiException {
logger.debug("Received request to delete prompt message id {}", contextMessageId);
super.deletePromptMessage(contextMessageId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package com.box.l10n.mojito.cli.apiclient;

import com.box.l10n.mojito.cli.command.CommandException;
import com.box.l10n.mojito.cli.model.AssetAssetSummary;
import com.box.l10n.mojito.cli.model.ImportLocalizedAssetBody;
import com.box.l10n.mojito.cli.model.LocalizedAssetBody;
import com.box.l10n.mojito.cli.model.MultiLocalizedAssetBody;
import com.box.l10n.mojito.cli.model.PollableTask;
import com.box.l10n.mojito.cli.model.XliffExportBody;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.Assert;

public class AssetWsApiProxy extends AssetWsApi {

/** logger */
static Logger logger = LoggerFactory.getLogger(AssetWsApiProxy.class);

public static final String OUTPUT_BCP47_TAG = "en-x-pseudo";

public AssetWsApiProxy(ApiClient apiClient) {
super(apiClient);
}

public AssetAssetSummary getAssetByPathAndRepositoryId(String path, Long repositoryId)
throws CommandException, ApiException {
Assert.notNull(path, "path must not be null");
Assert.notNull(repositoryId, "repository must not be null");

List<AssetAssetSummary> assets = this.getAssets(repositoryId, path, null, null, null);
if (!assets.isEmpty()) {
return assets.getFirst();
} else {
throw new CommandException(
"Could not find asset with path = [" + path + "] at repo id [" + repositoryId + "]");
}
}

@Override
public LocalizedAssetBody getLocalizedAssetForContent(
LocalizedAssetBody body, Long assetId, Long localeId) throws ApiException {
logger.debug(
"Getting localized asset with asset id = {}, locale id = {}, outputBcp47tag: {}",
assetId,
localeId,
body.getOutputBcp47tag());
return super.getLocalizedAssetForContent(body, assetId, localeId);
}

@Override
public ImportLocalizedAssetBody importLocalizedAsset(
ImportLocalizedAssetBody body, Long assetId, Long localeId) throws ApiException {
logger.debug("Import localized asset with asset id = {}, locale id = {}", assetId, localeId);
return super.importLocalizedAsset(body, assetId, localeId);
}

@Override
public PollableTask getLocalizedAssetForContentParallel(
MultiLocalizedAssetBody body, Long assetId) throws ApiException {
logger.debug("Getting localized assets with asset id = {}", assetId);
return super.getLocalizedAssetForContentParallel(body, assetId);
}

@Override
public PollableTask getLocalizedAssetForContentAsync(LocalizedAssetBody body, Long assetId)
throws ApiException {
logger.debug(
"Getting localized asset with asset id = {}, locale id = {}, outputBcp47tag: {}",
assetId,
body.getLocaleId(),
body.getOutputBcp47tag());
return super.getLocalizedAssetForContentAsync(body, assetId);
}

@Override
public List<Long> getAssetIds(Long repositoryId, Boolean deleted, Boolean virtual, Long branchId)
throws ApiException {
Assert.notNull(repositoryId, "The repositoryId must not be null");
return super.getAssetIds(repositoryId, deleted, virtual, branchId);
}

@Override
public PollableTask deleteAssetsOfBranches(List<Long> body, Long branchId) throws ApiException {
logger.debug("Deleting assets by asset ids = {} or branch id: {}", body.toString(), branchId);
return super.deleteAssetsOfBranches(body, branchId);
}

@Override
public List<AssetAssetSummary> getAssets(
Long repositoryId, String path, Boolean deleted, Boolean virtual, Long branchId)
throws ApiException {
logger.debug("Get assets by path = {} repo id = {} deleted = {}", path, repositoryId, deleted);
return super.getAssets(repositoryId, path, deleted, virtual, branchId);
}

@Override
public XliffExportBody xliffExportAsync(XliffExportBody body, String bcp47tag, Long assetId)
throws ApiException {
logger.debug("Export asset id: {} for locale: {}", assetId, bcp47tag);
return super.xliffExportAsync(body, bcp47tag, assetId);
}

@Override
public XliffExportBody xliffExport(Long assetId, Long tmXliffId) throws ApiException {
logger.debug("Get exported xliff for asset id: {} for tm xliff id: {}", assetId, tmXliffId);
return super.xliffExport(assetId, tmXliffId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.box.l10n.mojito.cli.apiclient;

import com.box.l10n.mojito.cli.console.ConsoleWriter;
import com.box.l10n.mojito.cli.credentialprovider.CredentialProvider;
import com.squareup.okhttp.OkHttpClient;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class AuthenticatedApiClient extends ApiClient {

@Autowired CredentialProvider credentialProvider;

@Autowired ConsoleWriter consoleWriter;

@PostConstruct
public void init() {
this.setHttpClient(this.getOkHttpClient());
}

private OkHttpClient getOkHttpClient() {
OkHttpClient httpClient = new OkHttpClient();
httpClient
.interceptors()
.add(
new AuthenticatedApiInterceptor(
this.getBasePath(), this.credentialProvider, this.consoleWriter));
return httpClient;
}
}
Loading
Loading