how to have different required fields for the create (put) and update api?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2020
01:02 AM
01-24-2020
01:02 AM
how to have different required fields for the create (put) and update api?
I have a schema defined say star which has name as required field. But i want this field to be required in create body request but not in update body request. What is the correct way to do without redundant code?
Star:
title: Star
description: star found
required:
- name
properties:
id:
description: the id for the star
type: string
format: uuid4
readOnly: true
x-go-name: ID
name:
description: name of the star
type: string
x-go-name: Star
1 REPLY 1
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2020
09:10 AM
02-03-2020
09:10 AM
Define the base "Star" model where the "name" property is optional. Then define another model, say, "NewStar", as allOf of the base model and the required list. Use the base "Star" model in the update request and the "NewStar" model in the create request.
Star: type: object properties: ... NewStar: allOf: - $ref: '#/definitions/Star' # or '#/components/schemas/Star' if you use OAS3 - required: - name
Helen Kosova
SmartBear Documentation Team Lead
________________________
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
