-
Notifications
You must be signed in to change notification settings - Fork 350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use type-is for content type comparison #944
Conversation
); | ||
} | ||
|
||
const byResponseCode = ord.contramap<number, IHttpOperationResponse>(ordNumber, response => parseInt(response.code)); | ||
|
||
export function findLowest2xx(httpResponses: IHttpOperationResponse[]): Option<IHttpOperationResponse> { | ||
export function findLowest2xx(httpResponses: NonEmptyArray<IHttpOperationResponse>): Option<IHttpOperationResponse> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm aware of the discussion on http-spec typings. Just thinking of using IHttpOperation['responses'] as a type here to be consistent with what we could receive. Despite the fact of how bad the input things can be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say these function will take a non empty array, we will validate this ahead of the time, most likely in the CLI.
If we're going to receive garbage input — we're going to make sure to validate it before it enters in Prism-Http.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, almost good. I would be happier when we could rely on IHttpOperation for that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since http-spec won't provide non-empty array of responses anymore, I guess we need to implement additional checks, right?
2cc4581
to
52870a1
Compare
@karol-maciaszek The current version of http-spec is still returning a NonEmptyArray — when we will upgrade to the latest version (assuming it will make it in master) when we will upgrade the package we'll get type errors everywhere and we'll fix them. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
This PR will replace different checks we were doing in places to look for content so that instead of using regular string comparison we use the type-is library which will normalise content types with charset and so on
Closes #943