reslang icon indicating copy to clipboard operation
reslang copied to clipboard

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

Open ChristianHansen opened this issue 5 years ago • 0 comments

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.

ChristianHansen avatar Oct 21 '20 02:10 ChristianHansen