Forum Discussion

kashira's avatar
kashira
New Contributor
3 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

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    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
        SmartBear Alumni (Retired)

        "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
        SmartBear Alumni (Retired)

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