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

HTTP4S Generator: Skip decoders/encoders for models with no fields #626

Merged
merged 2 commits into from
Feb 19, 2021

Conversation

mbryzek
Copy link
Collaborator

@mbryzek mbryzek commented Feb 17, 2021

Through swagger conversion we can end up w/ a model with no fields resulting in a compile error:

implicit def decodeTestAPIFooError: Decoder[FooError] = Decoder.instance { c =>
     for {
      } yield {
        FooError(
        )
      }
    }
    implicit def encodeTestAPIFooError: Encoder[FooError] = Encoder.instance { t =>
      Json.fromFields(Seq(
      ).flatten)
    }

This PR fixes that by skipping generation of decoders/encoders for models with no fields. I think this is the right approach for right now as in the future there is an open issue to support models w/ no fields (and thus think better to solve for this error here).

Related issue: #627

@mbryzek mbryzek requested a review from gheine February 17, 2021 19:08
if (enum.values.isEmpty) {
None
} else {
Some(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of if (...) None else Some(...) could do enum.values.headOption.map { _ => ...}

if (model.fields.isEmpty) {
None
} else {
Some(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above

Copy link
Collaborator

@gheine gheine left a comment

Choose a reason for hiding this comment

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

LGTM

@mbryzek mbryzek merged commit b99908b into master Feb 19, 2021
@mbryzek mbryzek deleted the empty_models branch February 19, 2021 15:45
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.

2 participants