Skip to content

Commit

Permalink
fix(generator): Set cookie parameters as optional to handle browser m…
Browse files Browse the repository at this point in the history
…anaged cookies (Embraser01#17)
  • Loading branch information
Embraser01 authored Dec 14, 2021
1 parent 415b83a commit 8263d04
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/typoas-generator/src/generator/components/parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,19 @@ export function isParameterRequired(
parameterOrRef: ParameterObject | ReferenceObject,
ctx: Context,
): boolean {
let parameter = parameterOrRef as ParameterObject;
if (parameterOrRef.$ref) {
const ref = ctx.resolveReference('parameters', parameterOrRef.$ref);
if (!ref) {
throw new Error(`$ref '${parameterOrRef.$ref}' wasn't found`);
}
return !!ref.spec.required;
parameter = ref.spec;
}
return !!(parameterOrRef as ParameterObject).required;

// Cookies can be fully handled by the navigator, so we need to
// declare those as optional.
if (parameter.in === 'cookie') {
return false;
}
return !!parameter.required;
}

0 comments on commit 8263d04

Please sign in to comment.