Skip to content

Commit

Permalink
chore: prettier format
Browse files Browse the repository at this point in the history
  • Loading branch information
kosa3 committed Sep 30, 2024
1 parent 2c57e25 commit 2f26095
Showing 1 changed file with 31 additions and 15 deletions.
46 changes: 31 additions & 15 deletions packages/core/src/getters/res-req-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,45 +416,61 @@ const resolveSchemaPropertiesToFormData = ({
if (itemSchema.type === 'object' || itemSchema.type === 'array') {
valueStr = 'JSON.stringify(value)';
} else if (
itemSchema.type === 'number' || itemSchema.type?.includes('number') ||
itemSchema.type === 'integer' || itemSchema.type?.includes('integer') ||
itemSchema.type === 'boolean' || itemSchema.type?.includes('boolean')
itemSchema.type === 'number' ||
itemSchema.type?.includes('number') ||
itemSchema.type === 'integer' ||
itemSchema.type?.includes('integer') ||
itemSchema.type === 'boolean' ||
itemSchema.type?.includes('boolean')
) {
valueStr = 'value.toString()';
}
}
formDataValue = `${valueKey}.forEach(value => ${variableName}.append('${key}', ${valueStr}));\n`;
} else if (
property.type === 'number' || property.type?.includes('number') ||
property.type === 'integer' || property.type?.includes('integer') ||
property.type === 'boolean' || property.type?.includes('boolean')
property.type === 'number' ||
property.type?.includes('number') ||
property.type === 'integer' ||
property.type?.includes('integer') ||
property.type === 'boolean' ||
property.type?.includes('boolean')
) {
formDataValue = `${variableName}.append('${key}', ${nonOptionalValueKey}.toString())\n`;
} else {
formDataValue = `${variableName}.append('${key}', ${nonOptionalValueKey})\n`;
}

let existSubSchemaNullable = false
let existSubSchemaNullable = false;
if (property.allOf || property.anyOf || property.oneOf) {
const combine = property.allOf || property.anyOf || property.oneOf;
const subSchema = combine?.map((c) => resolveObject({schema: c, combined: true, context: context}))
if (subSchema?.some(schema => {
return ['number', 'integer', 'boolean'].includes(schema.type)
})) {
const subSchema = combine?.map((c) =>
resolveObject({ schema: c, combined: true, context: context }),
);
if (
subSchema?.some((schema) => {
return ['number', 'integer', 'boolean'].includes(schema.type);
})
) {
formDataValue = `${variableName}.append('${key}', ${nonOptionalValueKey}.toString())\n`;
}

if (subSchema?.some(schema => {
return schema.type === 'null'
})) {
if (
subSchema?.some((schema) => {
return schema.type === 'null';
})
) {
existSubSchemaNullable = true;
}
}

const isRequired =
schema.required?.includes(key) && !isRequestBodyOptional;

if (property.nullable || property.type?.includes('null') || existSubSchemaNullable) {
if (
property.nullable ||
property.type?.includes('null') ||
existSubSchemaNullable
) {
if (isRequired) {
return acc + `if(${valueKey} !== null) {\n ${formDataValue} }\n`;
}
Expand Down

0 comments on commit 2f26095

Please sign in to comment.