LiveRamp / reslang

A language for describing resource-oriented APIs & turning them into Swagger or resource diagrams. Oriented around the concepts we want to expose in the APIs.
Apache License 2.0
23 stars 7 forks source link

Support empty structures #134

Closed ChristianHansen closed 4 years ago

ChristianHansen commented 4 years ago

Describe The Bug

Trying to generate a spec with an empty struct, at least when the struct is used in a union, results in an error messsage: Expected "/*", "//", "\"", [ \t\r\n], or [a-zA-Z_] but "}" found., location: 186, 1.

The motivation for doing this is that I want to be able to have a union type where one of the possible types doesn't require additional properties. Here's an example to illustrate a use case:

"Describes how a particular column should be treated with respect to fields."
union Treatment {
    mapToExistingField: MapToExistingField
    unmap: LeaveUnmapped
}

structure MapToExistingField {
    fieldId: long
}

"Use this to indicate that a Column should intentionally be left unmapped to a field."
structure LeaveUnmapped {
  // There doesn't need to be anything in this structure.
}

To Reproduce

  1. Check out this commit: https://github.com/LiveRamp/api-specs/pull/317/commits/4b322002e2ccbd21ef6c8837d0a77ca0bc618219
  2. Run ./generate-specs.sh specs-draft/field-mapper

Expected Behavior I should be able to create a structure with no properties. I'd expect that inlining that structure S in a resource or other structure adds no properties and that a property with type S always can only hold an empty object.

Reslang Version

I'm using the docker image with ID 8bc0860fb6ec, which is gcr.i o/liveramp-eng/reslang:master at time of writing. I get the same error when using the reslang CLI tool with version v2.2.5 directly.

forestgagnon commented 4 years ago

closing since #137 was merged