Skip to content

Commit

Permalink
fix: update according to comments
Browse files Browse the repository at this point in the history
  • Loading branch information
SLdragon committed Sep 21, 2023
1 parent d1190d9 commit af5c87f
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/fx-core/src/common/spec-parser/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function checkParameters(paramObject: OpenAPIV3.ParameterObject[]): Check
const schema = param.schema as OpenAPIV3.SchemaObject;

if (param.in === "header" || param.in === "cookie") {
if (param.required && schema.default === undefined) {
if (isRequiredDefaultParam(param, schema)) {
paramResult.isValid = false;
}
continue;
Expand All @@ -58,14 +58,14 @@ export function checkParameters(paramObject: OpenAPIV3.ParameterObject[]): Check
schema.type !== "number" &&
schema.type !== "integer"
) {
if (param.required && schema.default === undefined) {
if (isRequiredDefaultParam(param, schema)) {
paramResult.isValid = false;
}
continue;
}

if (param.in === "query" || param.in === "path") {
if (param.required && schema.default === undefined) {
if (isRequiredDefaultParam(param, schema)) {
paramResult.requiredNum = paramResult.requiredNum + 1;
} else {
paramResult.optionalNum = paramResult.optionalNum + 1;
Expand All @@ -76,6 +76,13 @@ export function checkParameters(paramObject: OpenAPIV3.ParameterObject[]): Check
return paramResult;
}

export function isRequiredDefaultParam(
param: OpenAPIV3.ParameterObject,
schema: OpenAPIV3.SchemaObject
): boolean | undefined {
return param.required && schema.default === undefined;
}

export function checkPostBody(
schema: OpenAPIV3.SchemaObject,
isRequired = false
Expand Down

0 comments on commit af5c87f

Please sign in to comment.