-
Notifications
You must be signed in to change notification settings - Fork 14
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
feat(clients): retrieve hosts from spec file #111
Conversation
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 !
clients/algoliasearch-client-javascript/client-insights/src/insightsApi.ts
Outdated
Show resolved
Hide resolved
c2313ca
to
c03732f
Compare
@@ -1,7 +1,7 @@ | |||
{ | |||
"$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json", | |||
"generator-cli": { | |||
"version": "5.3.0", | |||
"version": "5.4.0", |
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 upgraded when trying inlined options, it was not successful but let's upgrade it anyway
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.
Impressive !
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.
Beautiful !
scripts/pre-gen/setHostsOptions.ts
Outdated
|
||
function setHostsOptions(): void { | ||
const openapitoolsPath = path.join(__dirname, '../../openapitools.json'); | ||
const openapitools = JSON.parse(readFileSync(openapitoolsPath, 'utf-8')); |
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.
You can import this one to have the types
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 done this first but tsc will compile the json file, which changes the path reference etc. In the end, this solution was easier
{{/hasRegionalHost}} | ||
{{#hasRegionalHost}} | ||
public getDefaultHosts(region{{#fallbackToAliasHost}}?{{/fallbackToAliasHost}}: {{#isDeHost}}'de'{{/isDeHost}}{{#isEuHost}}'eu'{{/isEuHost}} | 'us'): Host[] { | ||
{{#fallbackToAliasHost}}const regionHost = region ? `.${region}.` : '.';{{/fallbackToAliasHost}} |
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.
Small detail but I would put one point in the final url and just ${region}.
here
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 found a way to make it extra clear, by splitting .
I find it confusing so I've kept everything at the same spot
scripts/pre-gen/setHostsOptions.ts
Outdated
}; | ||
|
||
writeFileSync(openapitoolsPath, JSON.stringify(openapitools, null, 2)); | ||
writeFile(openapitoolsPath, JSON.stringify(openapitools, null, 2)); |
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.
missing await
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.
👀
options.hasRegionalHost = true; | ||
additionalProperties.hasRegionalHost = true; | ||
|
||
if (!additionalProperties.fallbackToAliasHost) { |
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.
technical ts right here !
928f7e5
to
8e14899
Compare
8e14899
to
b91b9c8
Compare
Opened issue for URL on Current workarounds: using |
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 had no idea URL was not part of classic node !
🧭 What and Why
🎟 JIRA Ticket: https://algolia.atlassian.net/browse/APIC-293
This PR aims at removing manual definition of the
additionalProperties
in ouropenapitools.json
config file.We now retrieve options related to the
region
/hosts
from the specs (which is not yet doable via the generator: OpenAPITools/openapi-generator#590 - source code).Unsuccessful workarounds
servers
in generator: open issueChanges included:
'de' | 'us'
should be accepted.sources
which was outdatedinsights
,analytics
, andabtesting
now correctly fallbacks to their host alias.openapitools.json
file for thehosts
/region
related variables before generating the client.🧪 Test
CI :D