Skip to content
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

Merged
merged 4 commits into from
Jan 27, 2020
Merged

Use type-is for content type comparison #944

merged 4 commits into from
Jan 27, 2020

Conversation

XVincentX
Copy link
Contributor

@XVincentX XVincentX commented Jan 24, 2020

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

@XVincentX XVincentX changed the title master Use type-is for content type comparison Jan 24, 2020
);
}

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> {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good!

Copy link
Contributor

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.

Copy link
Contributor

@karol-maciaszek karol-maciaszek left a 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?

@XVincentX
Copy link
Contributor Author

@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.

Copy link
Contributor

@karol-maciaszek karol-maciaszek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@XVincentX XVincentX merged commit f2a161e into master Jan 27, 2020
@XVincentX XVincentX deleted the fix/type-is branch January 27, 2020 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Including "charset=UTF-8" in Content-Type header causes an incorrect 422 response
2 participants