0

I created a swagger containing a get and a put, where in the first I call an element ("MyCar") and in the second I update the license plate. Being the same object, how can I make sure that in the swagger put it can show only the plate instead of all the fields of the object?

  '/example/car/{carId}':
get:
  summary: Get a Car by Id
  description: Get a car
  operationId: getCar
  tags:
    - Car
  parameters:
    - in: path
      name: carId
      required: true
      description: carID
      schema:
        type: string
  responses:
    '200':
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/MyCar'
[...]
put:
  summary: Update car plate
  description: update a plate by carID
  operationId: updatePlate
  tags:
    - Car
  parameters:
    - in: path
      name: carId
      required: true
      description: CarID to save
      schema:
        type: string
  requestBody:
    description: The new plate to create
    content:
      application/json:
        schema:
          $ref: '#/components/schemas/MyCar'
[...]
 MyCar:
  type: object
  properties:
    id:
      type: string
    owner:
      type: string
    plate:
      type: string

is there a way to show only the license plate in the put without showing the whole object?

Jacket
  • 353
  • 6
  • 18
  • You'll need two schemas - the base schema for PUT with just the `plate` property, and an extended schema for GET that inherits from the base schema (by using `allOf`+`$ref`) and adds additional properties. See the linked Q&As for examples. – Helen Jun 03 '22 at 18:33

0 Answers0