Skip to content

Commit

Permalink
fix(cli): add apiVersion and kind to the generated CRDs (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
shinebayar-g authored Dec 20, 2024
1 parent 3f09532 commit db4e4e5
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,21 @@ async function main() {
const crds = yaml.parseAllDocuments(fs.readFileSync(yamlSavePath, 'utf-8'));
for (const c of crds) {
const crd: CRD = c.toJS();
for (const version of crd.spec.versions) {
if (version.schema?.openAPIV3Schema) {
const className = `${crd.spec.names.kind}${version.name}`;
const i = await compile(version.schema.openAPIV3Schema, `${className}Args`, {
bannerComment: '',
additionalProperties: false,
format: false,
});
for (const crdVersion of crd.spec.versions) {
if (crdVersion.schema?.openAPIV3Schema) {
const className = `${crd.spec.names.kind}${crdVersion.name}`;
const compiledInterface = await compile(
crdVersion.schema.openAPIV3Schema,
`${className}Args`,
{
bannerComment: '',
additionalProperties: false,
format: false,
},
);
const sourceFile = project.createSourceFile(
path.join('crds', `${className}.ts`),
i,
compiledInterface,
{
overwrite: true,
},
Expand Down Expand Up @@ -115,6 +119,16 @@ async function main() {
extends: isNamespaced ? 'NamespacedApiObject' : 'ApiObject',
isExported: true,
properties: [
{
name: 'apiVersion',
initializer: `'${crd.spec.group}/${crdVersion.name}'`,
isReadonly: true,
},
{
name: 'kind',
initializer: `'${crd.spec.names.kind}'`,
isReadonly: true,
},
{
name: 'metadata',
type: isNamespaced ? 'NamespacedObjectMetav1' : 'ObjectMetav1',
Expand Down

0 comments on commit db4e4e5

Please sign in to comment.