forked from box/mojito
-
Notifications
You must be signed in to change notification settings - Fork 3
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
DarKhaos
wants to merge
19
commits into
master
Choose a base branch
from
I18N-1323
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 c549187
I18N-1323 Update Mojito CLI to use OpenAPI spec for rest calls
DarKhaos 544298a
I18N-1323 Update Mojito CLI to use OpenAPI spec for rest calls
DarKhaos 5d4d8ff
I18N-1323 Update Mojito CLI to use OpenAPI spec for rest calls
DarKhaos 4c69da0
I18N-1323 Update Mojito CLI to use OpenAPI spec for rest calls
DarKhaos 1c27feb
I18N-1323 Update Mojito CLI to use OpenAPI spec for rest calls
DarKhaos 326f410
I18N-1323 Update Mojito CLI to use OpenAPI spec for rest calls
DarKhaos 2729602
I18N-1323 Update Mojito CLI to use OpenAPI spec for rest calls
DarKhaos bc24ee7
I18N-1323 Update Mojito CLI to use OpenAPI spec for rest calls
DarKhaos 38f17ed
I18N-1323 Update Mojito CLI to use OpenAPI spec for rest calls
DarKhaos e6d871c
I18N-1323 Update Mojito CLI to use OpenAPI spec for rest calls
DarKhaos 22e08d2
I18N-1323 Update Mojito CLI to use OpenAPI spec for rest calls
DarKhaos e187373
I18N-1323 Update Mojito CLI to use OpenAPI spec for rest calls
DarKhaos 38c1c4a
I18N-1323 Update Mojito CLI to use OpenAPI spec for rest calls
DarKhaos 9cc7927
I18N-1323 Update Mojito CLI to use OpenAPI spec for rest calls
DarKhaos 0e9bd87
I18N-1365 - Refactor Mojito CLI to use generated code
DarKhaos bbce39e
I18N-1323 Update Mojito CLI to use OpenAPI spec for rest calls
DarKhaos c44ef6d
I18N-1323 Update Mojito CLI to use OpenAPI spec for rest calls
DarKhaos 674c214
I18N-1323 Update Mojito CLI to use OpenAPI spec for rest calls
DarKhaos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,3 +33,4 @@ release.properties | |
/tmp/ | ||
/local/ | ||
.vscode/ | ||
/webapp/src/main/resources/openapi.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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> | ||
|
@@ -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> | ||
<artifactId>mojito-common</artifactId> | ||
<version>0.111-SNAPSHOT</version> | ||
</dependency> | ||
|
||
|
@@ -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> | ||
|
@@ -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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
|
21 changes: 21 additions & 0 deletions
21
cli/src/main/java/com/box/l10n/mojito/cli/apiclient/AiChecksWsApiProxy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
cli/src/main/java/com/box/l10n/mojito/cli/apiclient/AiPromptWsApiProxy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
109 changes: 109 additions & 0 deletions
109
cli/src/main/java/com/box/l10n/mojito/cli/apiclient/AssetWsApiProxy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
cli/src/main/java/com/box/l10n/mojito/cli/apiclient/AuthenticatedApiClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed restclient dependency