Conditional Types for Headers and/or Parameters
mattdillon100 opened this issue · 3 comments
We will be creating our API spec, hopefully created by spot. However (and this is an example), we have headers that can either accept a cookie or authentication information. This is legacy code and not ideal but, regardless, would need to be covered in the specification.
If this is not possible, what workarounds exist. Here is an example of what we need:
@request
request(
@headers
headers: {
"Accept": "*/*"
"Host": String,
{
"Cookie": String
} ||
{
"Authorisation": String
}
}
) {}
We currently don't have support for generating cookie
params as defined by the OpenAPI's Parameter Locations. However there is support for optional @headers
:
@request
request(
@headers
headers: {
Accept: "*/*";
Host: String;
Cookie?: String; // optional
Authorisation?: String; // optional
}
) {}
Is this sufficient for your use case @wildcard27?
It could be, thanks @lfportal.
I am wondering if you could elaborate on the security-header
part of the specification. Can this be used to globally specify the 2 optional authorisation headers mentioned above?
It could be, thanks @lfportal.
I am wondering if you could elaborate on the
security-header
part of the specification. Can this be used to globally specify the 2 optional authorisation headers mentioned above?
Unfortunately @securityHeader
currently has limited use. It can only be used to globally specify exactly one non-optional authorisation header:
@securityHeader
"security-header-name": String;
I don't think this will fit your use case. There appears to be another open issue to more broadly look at how to handle security for Spot contracts - see #1004. We can take a stab at designing a broader DSL to support security there.