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

not possible to generate Option[List[Foo]] or empty list #180

Open
rkazanova opened this issue Mar 28, 2022 · 4 comments
Open

not possible to generate Option[List[Foo]] or empty list #180

rkazanova opened this issue Mar 28, 2022 · 4 comments

Comments

@rkazanova
Copy link

rkazanova commented Mar 28, 2022

there is not possible to generate Option[List[Foo]] or empty list

somearray:
   type: array
   items:
      $ref: "#/components/schemas/Foo"

We can use property for this feature:
nullable: true => for Option[List[Foo]] // to generate Option[List[Foo]]
default: [] => for empty list // to generate empty list

@rkazanova
Copy link
Author

rkazanova commented Mar 28, 2022

for the first proposal I added CustomMapping and it works:

.addMapping(CustomMapping.forField({
    case Field(prop, annot, typeDef) if prop.nullable & prop.`type`.isCollection =>
      Field(prop, annot, typeDef = TypeDef(s"Option[${typeDef.name}]", Imports.empty))
  }))

it means that

locations:
   type: array
   items:
     $ref: "#/components/schemas/Location"
   nullable: true

generates field in case class as Option[List[Location]]

@eikek
Copy link
Owner

eikek commented Apr 12, 2022

Sorry for the delay. That is a bug then, it should be an Option if the property is not mentioned in the list of required. Thank you for the good workaround! I assume that your workaround also works without the nullable: true property (only omit it from the required list)?

@rkazanova
Copy link
Author

Without nullable my solution doesn't work. BTW. I don't have this collection in required.

@eikek
Copy link
Owner

eikek commented Apr 13, 2022

Thanks for the update! Hm, seems like arrays are handled a bit differently. I think your workaround could be applied by the plugin automatically whenever nullable: true is defined.

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

No branches or pull requests

2 participants