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

Moved "required" list for Components generated from unions to child Components. #156

Open ChristianHansen opened 3 years ago

ChristianHansen commented 3 years ago

Describe your request Instead of adding properties that are required in a reslang structure to the required list for the parent Component, the required list should be on the child Components in case multiple structures in the union have the same properties, but the properties have different required-ness.

For example consider:

union MyUnion {
  s1: Struct1
  s2: Struct2
}

If Struct1 and Struct2 both have sharedProp, but sharedProp is optional in Struct2, then the required list for MyUnion shouldn't include sharedProp, but the required list for Struct1 should:

MyUnionS1
      allOf:
        - $ref: '#/components/schemas/MyUnion'
        - type: object
          properties: ...
          required:
            - sharedProp

MyUnionS2
      allOf:
        - $ref: '#/components/schemas/MyUnion'
        - type: object
          properties: ...

By contrast, with the current code, MyUnion would look something like this

  MyUnion:
      type: object
      properties:
        type:
          type: string
      discriminator:
        propertyName: type
        mapping:
          s1: '#/components/schemas/MyUnionS1'
          s2: '#/components/schemas/MyUnionS2'
      required:
        - type
        - sharedProp

and there would be no required list for MyUnionS1 nor MyUnionS2.

Describe the value this feature would provide This would disambiguate which values are required for which Components and make the generated OpenAPI spec closer to the likely intent of the auther of the reslang.