Skip to content

chore: set default generator options #385

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

Merged
merged 8 commits into from
Apr 20, 2022
Merged

Conversation

shortcuts
Copy link
Member

@shortcuts shortcuts commented Apr 19, 2022

🧭 What and Why

🎟 JIRA Ticket: https://algolia.atlassian.net/browse/APIC-431

Changes included:

This PR aims at removing hardcoded options by leveraging the custom generators.

  • Remove bash post-gen scripts logic
    • Handled in the custom generator
  • Remove some custom properties set in the openapitools.json config
    • Handled in the custom generator
  • Remove some models that are not used anymore 🤔
  • Move removeExistingModel.ts to its own file
  • Added new pre-gen function: setDefaultGeneratorOptions
    • It sets default common options to all generator keys, this could be improved and even moved to custom generators, but it would introduce much more changes

I'm not sure why the deleted files were not deleted before, maybe the codegen does not push them

🧪 Test

CI :D

(Please double check your clients in case I messed up)

@shortcuts shortcuts requested review from damcou and millotp April 19, 2022 09:37
@shortcuts shortcuts self-assigned this Apr 19, 2022
@netlify
Copy link

netlify bot commented Apr 19, 2022

Deploy Preview for api-clients-automation canceled.

Name Link
🔨 Latest commit 09e02be
🔍 Latest deploy log https://app.netlify.com/sites/api-clients-automation/deploys/625ee4a1c111e300089cad23

@algolia-bot
Copy link
Collaborator

algolia-bot commented Apr 19, 2022

✗ The generated branch has been deleted.

If the PR has been merged, you can check the generated code on the main branch.

Comment on lines 235 to 239
// set default options of the generator for every clients
additionalProperties.put("java8", true);
additionalProperties.put("sourceFolder", "algoliasearch-core");
setDateLibrary("java8");
setSourceFolder("algoliasearch-core");
Copy link
Member Author

Choose a reason for hiding this comment

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

Here we set to both the additionalProperties and the generator because those variables are used in the templates

String clientName = "";
if (language.equals("javascript")) {
// do not capitalize the first part
clientName = clientParts[0].toLowerCase();
Copy link
Member Author

Choose a reason for hiding this comment

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

I've only added the toLowerCase part here

throw new Error(`Generator not found: ${key}`);
}

const hostsOptions = await getHostsOptions({ client, key });
Copy link
Member Author

Choose a reason for hiding this comment

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

Leveraging the custom gen for this part could be a good next step

Copy link
Collaborator

@millotp millotp left a comment

Choose a reason for hiding this comment

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

Nice cleanup ! soon we won't need openapitools.json !

@@ -1,8 +1,7 @@
# OpenAPI Generator Ignore
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this file useful anymore ? if it's empty we can remove it

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope, I've kept it as an escape hatch if we want to remove something without touching the generator but it can be removed

Copy link
Member Author

Choose a reason for hiding this comment

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

I just tried to remove it but it keeps coming back 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

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

I couldn't remove it either, I just added it to .gitignore

Copy link
Member Author

Choose a reason for hiding this comment

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

yep I guess I'll have to do the same

}
}

return clientName;
Copy link
Collaborator

Choose a reason for hiding this comment

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

The client name should still include the + "Api", or + apiNameSuffix here, otherwise the name of the function is false

Copy link
Collaborator

Choose a reason for hiding this comment

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

Or you can have another method that returns that, and createClientName should just add the suffix

Copy link
Member Author

Choose a reason for hiding this comment

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

I think the name is still relevant, it runs the client name for a certain language, do you have better name ideas?

super.processOpts();

// set default options of the generator for every clients
String client = additionalProperties.get("client").toString();
Copy link
Collaborator

Choose a reason for hiding this comment

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

By moving this code to postProcessOperationsWithModels like in the java generator you can have access to the client name, without adding it to openapitools.json

Copy link
Member Author

Choose a reason for hiding this comment

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

Even better with this change!! Good point

"gitUserId": "algolia",
"glob": "specs/bundled/search.yml",
"templateDir": "#{cwd}/templates/java/",
"generatorName": "algolia-java",
Copy link
Collaborator

Choose a reason for hiding this comment

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

the generator name could be guessed from the language directly in generate.ts, if we assume we always have a custom generator.

Copy link
Member Author

Choose a reason for hiding this comment

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

I did not made this assumption as, even if it will mostly be the case, first iterations of adding a client could not require it

"gitHost": "algolia",
"gitUserId": "algolia",
"glob": "specs/bundled/search.yml",
"templateDir": "#{cwd}/templates/java/",
Copy link
Collaborator

Choose a reason for hiding this comment

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

templateDir can be guessed in the generator directly, as we already now the language.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah actually there's a lot more that can be done on that side, I've went with the minimal implementation as it was to iterate on #386, but I can add the logic to this PR if you want.

@shortcuts shortcuts enabled auto-merge (squash) April 19, 2022 16:30
@shortcuts shortcuts requested a review from millotp April 20, 2022 08:08
Copy link
Collaborator

@millotp millotp left a comment

Choose a reason for hiding this comment

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

Looking good !


additionalProperties.put("apiName", apiName);
additionalProperties.put("capitalizedApiName", Utils.capitalize(apiName));
additionalProperties.put("userAgent", Utils.capitalize(spec));
Copy link
Collaborator

Choose a reason for hiding this comment

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

that's a weird name for user agent, and are you sure it's always correct ? I can't remember what pathPrefix is for query-suggestions

Copy link
Member Author

Choose a reason for hiding this comment

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

It was weird to me too, the pathPrefix is the tag used in the spec, with the case for the current language, so here it's querySuggestions, then we capitalize it to QuerySuggestions 🤔

gitUserId: 'algolia',
glob: `specs/bundled/${client}.yml`,
templateDir: `#{cwd}/templates/${language}/`,
generatorName: AVAILABLE_CUSTOM_GEN.includes(language)
Copy link
Collaborator

Choose a reason for hiding this comment

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

If this data is accessible here it's also accessible in the generate.ts file where we actually use the generatorName, you can skip the openapitools.json part.
Because we require so much logic now in the custom gen that it's mandatory to have one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants