Skip to content

Commit

Permalink
fixed constr for empty arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
leonlai257 committed Dec 10, 2024
1 parent 91f3fa3 commit 3d86e4a
Showing 1 changed file with 36 additions and 37 deletions.
73 changes: 36 additions & 37 deletions vscode-extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,16 @@ export function activate(context: vscode.ExtensionContext) {

definitionTypes.push(type.title);

if (type.fields && type.fields.length > 0) {
const fields = type.fields;
if (!imports.includes(`ConStr${index}`)) {
imports.push(`ConStr${index}`);
}

if (!imports.includes(`ConStr${index}`)) {
imports.push(`ConStr${index}`);
}
let fieldSnippet = [
`export type ${type.title} = ConStr${index}<[`,
];

let fieldSnippet = [
`export type ${type.title} = ConStr${index}<[`,
];
if (type.fields && type.fields.length > 0) {
const fields = type.fields;

fields.forEach((field: any, index: number) => {
const ref = field.$ref.split("/");
Expand Down Expand Up @@ -135,14 +135,13 @@ export function activate(context: vscode.ExtensionContext) {
`${mappedType}, // ${field.title}: ${fieldType}`
);
});

fieldSnippet.push(`]>;`);

definitionSnippet = [
...definitionSnippet,
...fieldSnippet,
];
}
fieldSnippet.push(`]>;`);

definitionSnippet = [
...definitionSnippet,
...fieldSnippet,
];
});

if (definitionSnippet.length > 0) {
Expand Down Expand Up @@ -256,16 +255,16 @@ export function activate(context: vscode.ExtensionContext) {

definitionTypes.push(type.title);

if (type.fields && type.fields.length > 0) {
const fields = type.fields;
if (!imports.includes(`MConStr${index}`)) {
imports.push(`MConStr${index}`);
}

if (!imports.includes(`MConStr${index}`)) {
imports.push(`MConStr${index}`);
}
let fieldSnippet = [
`export type M${type.title} = MConStr${index}<[`,
];

let fieldSnippet = [
`export type M${type.title} = MConStr${index}<[`,
];
if (type.fields) {
const fields = type.fields;

fields.forEach((field: any) => {
const ref = field.$ref.split("/");
Expand Down Expand Up @@ -311,25 +310,25 @@ export function activate(context: vscode.ExtensionContext) {
`${mappedType}, // ${field.title}: ${fieldType}`
);
});
}

fieldSnippet.push(`]>;`);
fieldSnippet.push(`]>;`);

definitionSnippet = [
...definitionSnippet,
...fieldSnippet,
];
}
definitionSnippet = [
...definitionSnippet,
...fieldSnippet,
];
});

if (definitionSnippet.length > 0) {
if (anyOf.length > 1) {
definitionSnippet = [
`export type M${title} = ${MTypes.join(" | ")};`,
"",
...definitionSnippet,
];
}
if (anyOf.length > 1) {
definitionSnippet = [
`export type M${title} = ${MTypes.join(" | ")};`,
"",
...definitionSnippet,
];
}

if (definitionSnippet.length > 0) {
fullSnippet = [...fullSnippet, "", ...definitionSnippet];
}
}
Expand Down

0 comments on commit 3d86e4a

Please sign in to comment.