Skip to content

Add test case for status code mappings with empty output with descrip…#1332

Merged
adamw merged 5 commits intomasterfrom
openapi_status_codes_mappings_with_empty_outputs
Jun 23, 2021
Merged

Add test case for status code mappings with empty output with descrip…#1332
adamw merged 5 commits intomasterfrom
openapi_status_codes_mappings_with_empty_outputs

Conversation

@slabiakt
Copy link
Copy Markdown
Contributor

closes #687

test("should support description for status code mappings with empty output") {
val expectedYaml = load("oneOf/expected_status_codes_with_empty_output.yaml")

val e = endpoint.errorOut(sttp.tapir.oneOf(oneOfMapping(StatusCode.Forbidden, EndpointIO.Empty(Codec.idPlain(), EndpointIO.Info.empty).description("forbidden"))))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

maybe you can use emptyOutput instead of EndpointIO.Empty(Codec.idPlain(), EndpointIO.Info.empty)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I already tried but endpointOutput is defined as
val emptyOutput: EndpointOutput[Unit] = EndpointIO.Empty(Codec.idPlain(), EndpointIO.Info.empty)
and it's type doesn't allow to specify description as EndpointIO does, can I change emptyOutput's type to EndpointIO ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah ... yes, I think returning a more specific type (I think it will need to be even more specific than EndpointIO) is fine

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

all the other methods return specific return types

val entries = f.documentedCodes.keys.map(code => Some(code) -> Vector(f)).toList
Right(entries)
case _: EndpointIO.Empty[_] => Left(Vector.empty)
case e: EndpointIO.Empty[_] => if (e.info.description.nonEmpty) Left(Vector(e)) else Left(Vector.empty)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

what happens if we remove this special-case entirely? Maybe that case here isn't needed at all, since we already handle this case in EndpointToOperationResponse.scala

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

unfortunately when I remove this case entirely then 89 out of 183 tests in openapi-docs fail, would you like me to check why and try to fix them or just leave it as it is?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm that's weird, yes please check what's going on :)

@adamw adamw merged commit 699e206 into master Jun 23, 2021
@mergify mergify Bot deleted the openapi_status_codes_mappings_with_empty_outputs branch June 23, 2021 07:36
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.

Unable to attach description to emptyOutput AND it doesn't show up in OpenApi json

2 participants