Skip to content

Commit

Permalink
Don't generate an inline object for objects with no properties
Browse files Browse the repository at this point in the history
The core doesn't really know how to emit objects like that (so it
doesn't, and we end up with a compile error when building the generated
classes).  At any rate, if there's a bare object type without any
properties, our assumption is that the user is expected to populate it
with arbitrary key/value pairs (sorta like a map, but I guess they get
more freedom for keys?), so in this case we should just use
objectType() (io.cire.Json or Jackson JsonNode).
  • Loading branch information
kelnos committed Aug 16, 2019
1 parent ebcab0b commit bc2df0e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,13 @@ object SwaggerUtil {
Sw: SwaggerTerms[L, F],
Fw: FrameworkTerms[L, F]
): Free[F, ResolvedType[L]] = {
import Sc._
import Fw._
val action: Free[F, ResolvedType[L]] = Free.pure(Resolved[L](tpe, None, None, None, None))
propMetaImpl(property) {
case _: ObjectSchema =>
case schema: ObjectSchema if Option(schema.getProperties).exists(p => !p.isEmpty) =>
action
case _: ObjectSchema =>
objectType(None).map(Resolved[L](_, None, None, None, None))
case _: ComposedSchema =>
action
}
Expand Down
16 changes: 16 additions & 0 deletions modules/sample/src/main/resources/additional-properties.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@ info:
paths: {}
components:
schemas:
SimpleMap:
type: object
required:
- simple_obj
- simple_str
properties:
simple_obj:
type: object
additionalProperties:
type: object
simple_str:
type: object
additionalProperties:
type: string
just_obj:
type: object
FooMapValues:
type: object
required:
Expand Down

0 comments on commit bc2df0e

Please sign in to comment.