-
Notifications
You must be signed in to change notification settings - Fork 15
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
Invalid typescript code generated when crd property is hyphenated/pascal case (-) e.g auto-scaler
#101
Comments
A temporary work around if you're using typescript. You could probably adapt to other languages function main() {
sh.exec(`crd2pulumi --nodejsPath ${outDir} ${tempCrdDir}/* --force`);
const typesPaths = path.join(outDir, 'types');
const fileMatcher = '*ts';
sh.exec(`find ${typesPaths} -name "${fileMatcher}"`, { silent: true })
.trim()
.split('\n')
.forEach(path => {
const data = fs.readFileSync(path, 'utf8');
const sanitized = sanitizePulumiTypeDefinitions({ data })
fs.writeFileSync(path, sanitized, 'utf8');
})
}
export function sanitizePulumiTypeDefinitions({ data }: { data: string; }): string {
const replacer = (origChar: string) => origChar.split("-").join('');
return data
// Wrap quote around the key with `?` coming after the quota e.g
// auto-scaler?: pulumi.Input<inputs.pingcap.v1alpha1.TidbClusterStatusAuto-ScalerArgs>;
// to
// "auto-scaler"?: pulumi.Input<inputs.pingcap.v1alpha1.TidbClusterStatusAuto-ScalerArgs>;
.replace(/([a-z]+-.*[a-z]-*)(\?)?:/g, '"$1"$2:')
// Remove the hyphen in the value here e.g
// "auto-scaler"?: pulumi.Input<inputs.pingcap.v1alpha1.TidbClusterStatusAuto-ScalerArgs>;
// to
// "auto-scaler"?: pulumi.Input<inputs.pingcap.v1alpha1.TidbClusterStatusAutoScalerArgs>;
.replace(/(:.*)(-)(.*;)/g, replacer)
// Removes hyphen from interface definition e.g
// export interface TidbClusterStatusAuto-ScalerArgs {
// to
// export interface TidbClusterStatusAutoScalerArgs {
.replace(/(interface.*)(-)(.*{)/g, replacer);
} |
Pulumi includes hyphen in the type when a crd property has hyphen: Can remove after this resolved: pulumi/crd2pulumi#101
Same thing seems to happen with Dotnet for the RabbitMQ charts. I get this code generated:
|
This has been quite annoying, I've been running some gnarly |
|
Added to epic https://github.com/pulumi/home/issues/3431 |
Dupe of #43. |
What happened?
When you generate crd code, the first property (auto-scaler) has issues because there is a hyphen(-) .
auto-scaler
should either be stringified or camelized i.e "auto-scaler" or autoScaler. Also, hyphen(-) should be removed from the value i.eTidbClusterStatusAutoScalerArgs
Steps to reproduce
Generate Crd from this:
The behaviour seems to be coming from this part of the crd if you search
auto-scaler
:https://raw.githubusercontent.com/pingcap/tidb-operator/v1.3.8/manifests/crd.yaml
Expected Behavior
The property should be quoted when it has hyphen i.e "auto-scaler" and the value type(i.e
TidbClusterStatusAutoScalerArgs
andTidbClusterStatusAutoScalerArgs
) should remove the hyphen(-) when concatenating to create the nameActual Behavior
This is an invalid typescript being generated. The property with a hyphen is not being quoted i.e "auto-scaler" and the hyphen(-) is also not removed from the value type which is also an invalid typescript i.e
.TidbClusterStatusAuto-ScalerArgs
andTidbClusterStatusAuto-ScalerArgs
Output of
pulumi about
Additional context
No response
Contributing
Vote on this issue by adding a 👍 reaction.
To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).
The text was updated successfully, but these errors were encountered: