Skip to content

Commit

Permalink
feat(java): use lowercase for model package (#789)
Browse files Browse the repository at this point in the history
  • Loading branch information
millotp authored Jul 6, 2022
1 parent c1ea2f1 commit d6ba122
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.openapitools.codegen.*;
import org.openapitools.codegen.languages.JavaClientCodegen;
import org.openapitools.codegen.model.ModelsMap;
import org.openapitools.codegen.utils.ModelUtils;

@SuppressWarnings("unchecked")
public class AlgoliaJavaGenerator extends JavaClientCodegen {
Expand All @@ -24,7 +23,7 @@ public void processOpts() {
String client = (String) additionalProperties.get("client");
setSourceFolder("algoliasearch-core/src/main/java");
setGroupId("com.algolia");
setModelPackage("com.algolia.model." + Utils.camelize(client));
setModelPackage("com.algolia.model." + Utils.camelize(client).toLowerCase());
additionalProperties.put("invokerPackage", "com.algolia");
setApiPackage("com.algolia.api");
setApiNameSuffix(Utils.API_SUFFIX);
Expand Down Expand Up @@ -102,15 +101,6 @@ public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs)
return models;
}

@Override
public String toDefaultValue(Schema schema) {
// Replace the {} from openapi with new Object()
if (ModelUtils.isObjectSchema(schema) && schema.getDefault() != null) {
return "new Object()";
}
return super.toDefaultValue(schema);
}

@Override
public String toEnumVarName(String value, String datatype) {
if ("String".equals(datatype)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ public void addSupportingFiles(List<SupportingFile> supportingFiles) {
@Override
public void addDataToBundle(Map<String, Object> bundle) throws GeneratorException {
bundle.put("packageVersion", Utils.getClientConfigField("java", "packageVersion"));
bundle.put("import", Utils.camelize(this.client));
bundle.put("import", Utils.camelize(this.client).toLowerCase());
}
}
6 changes: 3 additions & 3 deletions scripts/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { createSpinner } from './oraLog';
import { generateOpenapitools, removeExistingCodegen } from './pre-gen';
import type { Generator } from './types';

async function preGen(gen: Generator, verbose?: boolean): Promise<void> {
await removeExistingCodegen(gen, verbose);
async function preGen(gen: Generator): Promise<void> {
await removeExistingCodegen(gen);
}

async function generateClient(
Expand Down Expand Up @@ -48,7 +48,7 @@ export async function generate(

for (const gen of generators) {
const spinner = createSpinner(`pre-gen ${gen.key}`, verbose).start();
await preGen(gen, verbose);
await preGen(gen);

spinner.text = `generating ${gen.key}`;
await generateClient(gen, verbose);
Expand Down
65 changes: 32 additions & 33 deletions scripts/pre-gen/removeExistingCodegen.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import fsp from 'fs/promises';
import path from 'path';

import { createClientName, run, toAbsolutePath } from '../common';
import { createClientName, toAbsolutePath } from '../common';
import { getLanguageApiFolder, getLanguageModelFolder } from '../config';
import type { Generator } from '../types';

/**
* Remove `model` folder for the current language and client.
*/
export async function removeExistingCodegen(
{ language, client, output }: Generator,
verbose?: boolean
): Promise<void> {
export async function removeExistingCodegen({
language,
client,
output,
}: Generator): Promise<void> {
const baseModelFolder = getLanguageModelFolder(language);
const baseApiFolder = getLanguageApiFolder(language);
const clientName = createClientName(client, language);
Expand All @@ -20,7 +22,17 @@ export async function removeExistingCodegen(

switch (language) {
case 'java':
clientModel = client;
if (client === 'query-suggestions') {
// eslint-disable-next-line no-warning-comments
// TODO: temporary solution, remove in next PR
await fsp.rm(
toAbsolutePath(
path.resolve('..', output, baseModelFolder, 'querySuggestions')
),
{ force: true, recursive: true }
);
}
clientModel = client.replace('-', '');
clientApi = `${clientName}*.java`;
break;
case 'php':
Expand All @@ -30,44 +42,31 @@ export async function removeExistingCodegen(
case 'javascript':
// We want to also delete the nested `lite` client or folders that only exists in JS
if (clientName === 'algoliasearch') {
await run(
`rm -rf ${toAbsolutePath(path.resolve('..', output, 'lite'))}`,
{
verbose,
}
);
await fsp.rm(toAbsolutePath(path.resolve('..', output, 'lite')), {
force: true,
recursive: true,
});
}

// Delete `builds` folder
await run(
`rm -rf ${toAbsolutePath(path.resolve('..', output, 'builds'))}`,
{
verbose,
}
);

await fsp.rm(toAbsolutePath(path.resolve('..', output, 'builds')), {
force: true,
recursive: true,
});
break;
default:
break;
}

// Delete client model folder/file
await run(
`rm -rf ${toAbsolutePath(
path.resolve('..', output, baseModelFolder, clientModel)
)}`,
{
verbose,
}
await fsp.rm(
toAbsolutePath(path.resolve('..', output, baseModelFolder, clientModel)),
{ force: true, recursive: true }
);

// Delete client api folder/file
await run(
`rm -rf ${toAbsolutePath(
path.resolve('..', output, baseApiFolder, clientApi)
)}`,
{
verbose,
}
await fsp.rm(
toAbsolutePath(path.resolve('..', output, baseApiFolder, clientApi)),
{ force: true, recursive: true }
);
}
2 changes: 1 addition & 1 deletion scripts/release/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export async function cloneRepository({

const gitHubUrl = getGitHubUrl(lang, { token: githubToken });
const tempGitDir = path.resolve(tempDir, lang);
await run(`rm -rf ${tempGitDir}`);
await fsp.rm(tempGitDir, { force: true, recursive: true });
await run(
`git clone --depth 1 --branch ${targetBranch} ${gitHubUrl} ${tempGitDir}`
);
Expand Down

0 comments on commit d6ba122

Please sign in to comment.