Skip to content

Commit

Permalink
chore(CamelCatalog): Add Catalog index typings
Browse files Browse the repository at this point in the history
fix: #5
  • Loading branch information
lordrip committed May 22, 2024
1 parent ed74d48 commit 8c490a7
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 35 deletions.
28 changes: 28 additions & 0 deletions packages/camel-catalog/kaoto-camel-catalog-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,34 @@
</mojoDependencies>
</configuration>
</plugin>
<plugin>
<groupId>cz.habarta.typescript-generator</groupId>
<artifactId>typescript-generator-maven-plugin</artifactId>
<version>3.2.1263</version>
<executions>
<execution>
<id>generate</id>
<phase>process-classes</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<jsonLibrary>jackson2</jsonLibrary>
<generateNpmPackageJson>false</generateNpmPackageJson>
<outputKind>module</outputKind>
<outputFileType>declarationFile</outputFileType>
<generateJaxrsApplicationInterface>true</generateJaxrsApplicationInterface>
<classesFromAutomaticJaxrsApplication>true</classesFromAutomaticJaxrsApplication>
<restNamespacing>perResource</restNamespacing>

<outputFile>../dist/types/catalog-index.d.ts</outputFile>
<classPatterns>
<classPattern>io.kaoto.camelcatalog.Index</classPattern>
</classPatterns>
</configuration>
</plugin>
</plugins>
</build>
</project>
6 changes: 3 additions & 3 deletions packages/camel-catalog/src/json-schema-to-typescript.mts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import index from '../dist/index.json' assert { type: 'json' };
const ensureTypesFolder = async () => {
const typesFolder = resolve('./dist/types');

await rimraf(typesFolder);
await mkdir(typesFolder);
await rimraf(typesFolder, { filter: (path) => !path.includes('catalog-index.d.ts') });
await mkdir(typesFolder, { recursive: true });
};

/** Function to compile a JSON schema file to a TypeScript file */
Expand Down Expand Up @@ -50,7 +50,7 @@ const addTitleToDefinitions = (schema: JSONSchema) => {
async function main() {
await ensureTypesFolder();

const exportedFiles: string[] = [];
const exportedFiles: string[] = ['catalog-index'];

console.log('---');
const targetSchemaNames = [
Expand Down
44 changes: 16 additions & 28 deletions packages/ui/src/models/camel-catalog-index.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,24 @@
import { Entry, Index } from '@kaoto/camel-catalog/types';
import { ICamelComponentDefinition } from './camel-components-catalog';
import { ICamelProcessorDefinition } from './camel-processors-catalog';
import { ICamelLanguageDefinition } from './camel-languages-catalog';
import { ICamelDataformatDefinition } from './camel-dataformats-catalog';
import { ICamelLanguageDefinition } from './camel-languages-catalog';
import { ICamelLoadBalancerDefinition } from './camel-loadbalancers-catalog';
import { ICamelProcessorDefinition } from './camel-processors-catalog';
import { CatalogKind } from './catalog-kind';
import { IKameletDefinition } from './kamelets-catalog';
import { ICamelLoadBalancerDefinition } from './camel-loadbalancers-catalog';

export interface CamelCatalogIndex {
catalogs: Catalogs;
schemas: Record<string, SchemaEntry>;
}

export interface Catalogs {
models: CatalogEntry;
components: CatalogEntry;
languages: CatalogEntry;
dataformats: CatalogEntry;
kamelets: CatalogEntry;
kameletBoundaries: CatalogEntry;
patterns: CatalogEntry;
entities: CatalogEntry;
loadbalancers: CatalogEntry;
}

export interface CatalogEntry {
name: string;
version: string;
file: string;
}

export interface SchemaEntry extends CatalogEntry {
description: string;
export interface CamelCatalogIndex extends Omit<Index, 'catalogs'> {
catalogs: {
models: Entry;
components: Entry;
languages: Entry;
dataformats: Entry;
kamelets: Entry;
kameletBoundaries: Entry;
patterns: Entry;
entities: Entry;
loadbalancers: Entry;
};
}

export type ComponentsCatalogTypes =
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/src/utils/catalog-schema-loader.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SchemaEntry } from '../models';
import { Entry } from '@kaoto/camel-catalog/types';
import { CatalogSchemaLoader } from './catalog-schema-loader';

describe('CatalogSchemaLoader', () => {
Expand Down Expand Up @@ -38,7 +38,7 @@ describe('CatalogSchemaLoader', () => {
});

describe('getSchemasFiles', () => {
const schemasEntries: Record<string, SchemaEntry> = {
const schemasEntries: Record<string, Entry> = {
rest: {
description: 'description-1',
file: 'file-1.json',
Expand Down
5 changes: 3 additions & 2 deletions packages/ui/src/utils/catalog-schema-loader.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { KaotoSchemaDefinition, SchemaEntry } from '../models';
import { Entry } from '@kaoto/camel-catalog/types';
import { KaotoSchemaDefinition } from '../models';

export class CatalogSchemaLoader {
/** The `.` is required to support relative routes in GitHub pages */
Expand All @@ -12,7 +13,7 @@ export class CatalogSchemaLoader {
return { body, uri: response.url };
}

static getSchemasFiles(basePath: string, schemaFiles: Record<string, SchemaEntry>): Promise<KaotoSchemaDefinition>[] {
static getSchemasFiles(basePath: string, schemaFiles: Record<string, Entry>): Promise<KaotoSchemaDefinition>[] {
return Object.entries(schemaFiles).map(async ([name, schemaDef]) => {
const fetchedSchema = await this.fetchFile(`${basePath}/${schemaDef.file}`);
const tags = [];
Expand Down

0 comments on commit 8c490a7

Please sign in to comment.