Skip to content

Commit

Permalink
fix(code): Use YAML 1.1 for serializing
Browse files Browse the repository at this point in the history
Currently, Kaoto serialize to YAML using YAML 1.2.

This creates an edge for the Rest component since one of its parameters
(`bindingMode`) accepts an `off` value which ultimately gets serialized as it is,
causing to be interpreted as `false`.

This commit change the YAML serializing schema to 1.1 so `off` gets serialized as `"off"`
avoiding this issue.

fix: #971
  • Loading branch information
lordrip authored and lhein committed Apr 2, 2024
1 parent de74640 commit 272e659
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
20 changes: 18 additions & 2 deletions packages/ui/src/hooks/entities.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { act, renderHook } from '@testing-library/react';
import { CamelResource, SourceSchemaType } from '../models/camel';
import { CamelRouteVisualEntity } from '../models/visualization/flows';
import { camelRouteJson, camelRouteYaml } from '../stubs/camel-route';
import { EventNotifier } from '../utils';
import { camelRouteYaml_1_1_original, camelRouteYaml_1_1_updated } from '../stubs/camel-route-yaml-1.1';
import { EventNotifier, setValue } from '../utils';
import { useEntities } from './entities';

describe('useEntities', () => {
Expand Down Expand Up @@ -42,9 +43,24 @@ describe('useEntities', () => {
expect(result.current.visualEntities).toEqual([new CamelRouteVisualEntity(camelRouteJson.route)]);
});

it('should notifiy subscribers when the entities are updated', () => {
it('should serialize using YAML 1.1', () => {
const notifierSpy = jest.spyOn(eventNotifier, 'next');
const { result } = renderHook(() => useEntities());

act(() => {
eventNotifier.next('code:updated', camelRouteYaml_1_1_original);
});

act(() => {
setValue(result.current.visualEntities[0], 'route.from.parameters.bindingMode', 'off');
result.current.updateSourceCodeFromEntities();
});

expect(notifierSpy).toHaveBeenCalledWith('entities:updated', camelRouteYaml_1_1_updated);
});

it('should notifiy subscribers when the entities are updated', () => {
const notifierSpy = jest.spyOn(eventNotifier, 'next');
const { result } = renderHook(() => useEntities());

act(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/hooks/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const useEntities = (): EntitiesContextResult => {
}, [eventNotifier]);

const updateSourceCodeFromEntities = useCallback(() => {
const code = stringify(camelResource, { sortMapEntries: camelResource.sortFn }) || '';
const code = stringify(camelResource, { sortMapEntries: camelResource.sortFn, schema: 'yaml-1.1' }) || '';
eventNotifier.next('entities:updated', code);
}, [camelResource, eventNotifier]);

Expand Down
21 changes: 21 additions & 0 deletions packages/ui/src/stubs/camel-route-yaml-1.1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export const camelRouteYaml_1_1_original = `
- route:
id: route-3376
from:
id: from-3505
uri: rest:post:/newCustomer
parameters:
host: localhost
steps: []
`;

export const camelRouteYaml_1_1_updated = `- route:
id: route-3376
from:
id: from-3505
uri: rest:post:/newCustomer
parameters:
bindingMode: "off"
host: localhost
steps: []
`;

0 comments on commit 272e659

Please sign in to comment.