Open APIs

 View Only
  • 1.  OAS3 allOf composition in combination with discriminator

    TM Forum Member
    Posted Apr 08, 2024 08:01
    Edited by Alen Ruvic Apr 08, 2024 08:04

    Hi,

    How to understand (for example below ContactMedium schema object)?

    allOf is used to achieve composition of the Model to avoid redundancy: object Extensible is referenced and enriched with local properties. But what is the role of the discriminator here?

    oneOf/anyOf in combination with discriminator and a mandatory propertyName and mapping I understand. It is used to achieve Polymorphism. Is below a mistake or this is deliberately generated?  ContactMedium is just one example, but this pattern exists in many other places.



    ------------------------------
    Alen Ruvic
    SES Astra S.A.
    ------------------------------



  • 2.  RE: OAS3 allOf composition in combination with discriminator

    TM Forum Member
    Posted Apr 08, 2024 09:35

    Is following maybe better:



    ------------------------------
    Alen Ruvic
    SES Astra S.A.
    ------------------------------



  • 3.  RE: OAS3 allOf composition in combination with discriminator

    TM Forum Member
    Posted Apr 08, 2024 14:29

    Hi Alen

    Indeed, the file is generated that way - the source schema for ContactMedium does not have the discriminator.

    The allOf in the class ContactMedium is only to add the properties from the Extensible schema to the specific contact medium properties (id, preferred, contactType, validFor).

    The discriminator is added so that the subclasses will be included in the OAS file.

    I'm not sure if your suggestion is "better", but I'm not a swagger/OAS expert so I'd leave it to others to express an opinion.



    ------------------------------
    Jonathan Goldberg
    Amdocs Management Limited
    Any opinions and statements made by me on this forum are purely personal, and do not necessarily reflect the position of the TM Forum or my employer.
    ------------------------------



  • 4.  RE: OAS3 allOf composition in combination with discriminator

    TM Forum Member
    Posted Apr 10, 2024 03:21

    Hi Jonathan,

    Thanks for the answer.

    I was confused by wrongly generated code from OAS file. A prominent OAS code generator struggles with allOf.

    I understand now that allOf + discriminator is for composition/classical inheritance and oneOf + discriminator is for polymorphic inheritance.

    allOf is implemented (for example in Java) with "extends", while oneOf is implemented  as "implements" an interface



    ------------------------------
    Alen Ruvic
    SES Astra S.A.
    ------------------------------