Forum Discussion

kashira's avatar
kashira
New Contributor
4 years ago
Solved

I want to create a component one with default value other one without default value how to do

G'day All, 

 

Please can someone suggest me what is best way to write this component with reuse. 

 

Title:

  Type: string 

   Enum: 

       - Mr

       - Mrs

       - Unknown

 

TitleWithDefault

   $ref: '#/components/schemas/Title'

   default: Unknown

 

Is it possible?

 

Please if someone knows the answer can you share it.

 

Thanking you, 

Raj

  • "default" needs to be on the same level as "allOf", not inside it.

    TitleWithDefault
      allOf:
        - $ref: '#/components/schemas/Title'
      default: Unknown

6 Replies

  • Hi Raj, try wrappin the $ref into allOf:

    TitleWithDefault
      allOf:
        - $ref: '#/components/schemas/Title'
      default: Unknown

     

    • kashira's avatar
      kashira
      New Contributor

      G'day Helen,

       

      Thanks for your reply. I tried. It did not work. 

       

      Please can you help.

       

      Thanking you,

      Raj

      • HKosova's avatar
        HKosova
        Icon for Alumni rankAlumni

        "default" needs to be on the same level as "allOf", not inside it.

        TitleWithDefault
          allOf:
            - $ref: '#/components/schemas/Title'
          default: Unknown
    • kashira's avatar
      kashira
      New Contributor

      G'day, 

       

      I am not sure I followed as you suggested  - it still did not work.

       

      Regards, 

      • HKosova's avatar
        HKosova
        Icon for Alumni rankAlumni

        Can you please post your entire "components" section with all schemas?