Skip to content

Commit

Permalink
Merge branch 'master' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslagoni authored Jan 30, 2024
2 parents bd01eb6 + a91b3d0 commit 6d9c2c8
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export const PlaygroundContextProvider: React.FC<{ children: React.ReactNode; }>
tsMarshalling: false,
tsModelType: 'class',
tsEnumType: 'enum',
tsMapType: 'map',
tsModuleSystem: 'CJS',
tsIncludeDescriptions: false,
tsIncludeExampleFunction: false,
Expand Down
3 changes: 3 additions & 0 deletions modelina-website/src/components/playground/Playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ const Playground: React.FC<ModelinaPlaygroundProps> = (props) => {
if (query.tsEnumType !== undefined) {
setConfig({ ...config, tsEnumType: query.tsEnumType as any });
}
if (query.tsMapType !== undefined) {
setConfig({ ...config, tsMapType: query.tsMapType as any });
}
if (query.tsIncludeDescriptions !== undefined) {
setConfig({ ...config, tsIncludeDescriptions: query.tsIncludeDescriptions === 'true' });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ const TypeScriptGeneratorOptions: React.FC<TypeScriptGeneratorOptionsProps> = ({
setNewConfig && setNewConfig('tsEnumType', enumType);
};

const onChangeMapType = (mapType: string) => {
setNewConfig && setNewConfig('tsMapType', mapType);
};

const onChangeIncludeJsonBinPack = (event: React.ChangeEvent<HTMLInputElement>) => {
if (setNewConfig) {
const shouldIncludeMarshalling = context?.tsMarshalling === false && event.target.checked === true;
Expand Down Expand Up @@ -101,6 +105,30 @@ const TypeScriptGeneratorOptions: React.FC<TypeScriptGeneratorOptionsProps> = ({
/>
</label>
</li>
<li className="flex gap-1 items-center">
<InfoModal text='TypeScript map type: ' >
<p>
It indicates which type should be rendered for some map type. Its value can be either map, indexedObject, or record.
<br /> <br />
The default value is map.
</p>
</InfoModal>
<label className="flex flex-grow gap-1 items-center py-2 justify-between cursor-pointer">
<span className="mt-1 max-w-2xl text-sm text-gray-500">
TypeScript map type
</span>
<Select
options={[
{ value: 'indexedObject', text: 'Indexed Object' },
{ value: 'map', text: 'Map' },
{ value: 'record', text: 'Record' }
]}
value={context?.tsMapType}
onChange={onChangeMapType}
className="shadow-outline-blue cursor-pointer"
/>
</label>
</li>
<li className="flex gap-1 items-center">
<InfoModal text='TypeScript module system: ' >
<p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ export function getTypeScriptGeneratorCode(
optionString.push(`enumType: '${generatorOptions.tsEnumType}'`);
}

if (generatorOptions.tsMapType) {
optionString.push(`mapType: '${generatorOptions.tsMapType}'`);
}

if (generatorOptions.tsIncludeDescriptions === true) {
optionStringPresets.push(`{
preset: TS_DESCRIPTION_PRESET,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ export async function getTypeScriptModels(
options.enumType = generatorOptions.tsEnumType as any;
}

if (generatorOptions.tsMapType) {
options.mapType = generatorOptions.tsMapType as any;
}

if (generatorOptions.showTypeMappingExample) {
options.typeMapping = {
Integer: ({ dependencyManager }) => {
Expand Down
2 changes: 2 additions & 0 deletions modelina-website/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface ModelinaTypeScriptOptions extends ModelinaGeneralOptions {
tsMarshalling: boolean;
tsModelType: 'class' | 'interface' | undefined;
tsEnumType: 'union' | 'enum' | undefined;
tsMapType: 'indexedObject' | 'map' | 'record' | undefined;
tsModuleSystem: 'ESM' | 'CJS' | undefined;
tsIncludeDescriptions: boolean;
tsIncludeJsonBinPack: boolean;
Expand Down Expand Up @@ -162,6 +163,7 @@ export interface ModelinaTypeScriptQueryOptions {
tsMarshalling?: string;
tsModelType?: string;
tsEnumType?: string;
tsMapType?: string;
tsIncludeDescriptions?: string;
tsIncludeJsonBinPack?: string;
tsIncludeExampleFunction?: string;
Expand Down

0 comments on commit 6d9c2c8

Please sign in to comment.