I want to create a component one with default value other one without default value how to do
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Raj, try wrappin the $ref into allOf:
TitleWithDefault
allOf:
- $ref: '#/components/schemas/Title'
default: Unknown
Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
G'day Helen,
Thanks for your reply. I tried. It did not work.
Please can you help.
Thanking you,
Raj
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
"default" needs to be on the same level as "allOf", not inside it.
TitleWithDefault
allOf:
- $ref: '#/components/schemas/Title'
default: Unknown
Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
G'day,
I am not sure I followed as you suggested - it still did not work.
Regards,
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Can you please post your entire "components" section with all schemas?
Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
G'day Helen,
Thanks so much for spending time to help me with this. I posting the complete yml.
openapi: 3.0.0 info: title: Customers API description: Customer resource version: 1.0.0 contact: name: Raj email: Rajendra.Kashi@gmail.com paths: /customers: get: description: to retireve all the customer detail summary: This route retrieves all the customer detail responses: 200: description: retieves all the customer information content: application/json: schema: $ref: '#/components/schemas/CustomersRetrieveResponse' /customers/{customer_id}: get: description: retrieve customer summary: This route retrieve customer by customer id parameters: - in: path name: customer_id required: true description: customer id schema: type: string responses: 200: description: retieves all the customer information content: application/json: schema: $ref: '#/components/schemas/CustomerRetrieveResponse' post: description: create customer summary: This route retrieves all the customer detail requestBody: required: false content: application/json: schema: $ref: '#/components/schemas/CustomerCreateRequest' responses: 200: description: Description content: application/json: schema: type: string components: schemas: CustomersRetrieveResponse: type: array items: $ref: '#/components/schemas/CustomerRetrieveItem' CustomerRetrieveResponse: $ref: '#/components/schemas/CustomerRetrieveItem' CustomerCreateRequest: $ref: '#/components/schemas/CustomerCreateItem' CustomerCreateItem: required: - first_name - last_name allOf: - $ref: '#/components/schemas/CustomerTitleWithDefault' - $ref: '#/components/schemas/CustomerBasicData' CustomerRetrieveItem: allOf: - $ref: '#/components/schemas/CustomerId' - $ref: '#/components/schemas/CustomerTitle' - $ref: '#/components/schemas/CustomerBasicData' CustomerBasicData: type: object properties: first_name: type: string last_name: type: string CustomerId: type: object properties: id: type: string CustomerTitleWithDefault: allOf: - $ref: '#/components/schemas/CustomerTitle' default: Unknown #type: object #properties: # title: # type: string # enum: # - Mr # - Mrs # - M/S # - Dr # - Unknown # default: Unknown CustomerTitle: type: object properties: title: type: string enum: - Mr - Mrs - M/S - Dr - Unknown |
