-
Notifications
You must be signed in to change notification settings - Fork 21
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
Conversation
✅ Deploy Preview for api-clients-automation canceled.
|
✗ The generated branch has been deleted.If the PR has been merged, you can check the generated code on the |
// set default options of the generator for every clients | ||
additionalProperties.put("java8", true); | ||
additionalProperties.put("sourceFolder", "algoliasearch-core"); | ||
setDateLibrary("java8"); | ||
setSourceFolder("algoliasearch-core"); |
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.
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(); |
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.
I've only added the toLowerCase
part here
throw new Error(`Generator not found: ${key}`); | ||
} | ||
|
||
const hostsOptions = await getHostsOptions({ client, key }); |
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.
Leveraging the custom gen for this part could be a good next step
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.
Nice cleanup ! soon we won't need openapitools.json
!
@@ -1,8 +1,7 @@ | |||
# OpenAPI Generator Ignore |
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.
is this file useful anymore ? if it's empty we can remove it
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.
Nope, I've kept it as an escape hatch if we want to remove something without touching the generator but it can be removed
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.
I just tried to remove it but it keeps coming back 🤔
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.
I couldn't remove it either, I just added it to .gitignore
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.
yep I guess I'll have to do the same
} | ||
} | ||
|
||
return clientName; |
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.
The client name should still include the + "Api"
, or + apiNameSuffix
here, otherwise the name of the function is false
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.
Or you can have another method that returns that, and createClientName
should just add the suffix
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.
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(); |
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.
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
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.
Even better with this change!! Good point
"gitUserId": "algolia", | ||
"glob": "specs/bundled/search.yml", | ||
"templateDir": "#{cwd}/templates/java/", | ||
"generatorName": "algolia-java", |
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.
the generator name could be guessed from the language directly in generate.ts
, if we assume we always have a custom generator.
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.
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/", |
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.
templateDir
can be guessed in the generator directly, as we already now the language.
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.
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.
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.
Looking good !
|
||
additionalProperties.put("apiName", apiName); | ||
additionalProperties.put("capitalizedApiName", Utils.capitalize(apiName)); | ||
additionalProperties.put("userAgent", Utils.capitalize(spec)); |
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.
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
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.
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) |
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.
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.
🧭 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.
post-gen
scripts logicopenapitools.json
configremoveExistingModel.ts
to its own filepre-gen
function:setDefaultGeneratorOptions
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)