Interpretation of Referenced RequestBody

Hi everyone,

I’m quite new to API design as well as Stoplight.

I tried to make use of the RequestBody Object and refactored a RequestBody of my API file as reusable RequestBody Object.
Unfortunately, Stoplight somehow didn’t recognized/interpreted the referenced requestBody (including examples). The requestBody info is not shown in the preview view.

In order to find the problem I set up an example project according to the description in this blog post: https://stoplight.io/blog/reuse-openapi-descriptions/
I got the same result. See screenshots and API definition below

I’m a little lost. I don’t know if

  • I missed something in the definition, or
  • maybe misunderstood the RequestBody usage, or
  • if Stoplight just do not support referenced RequestBodies
    … or something else :thinking:

Some advice or help would be appreciated.

Thanks,
Sue

openapi: '3.0.2'
info:
  description: Stoplight Example
  contact:
    name: Some Body
  title: stoplight-examples
  version: '1.0'
servers:
- url: http://localhost:3000
tags:
  - name: Customer
  - name: Account
paths:
  '/customers':
    get:
      operationId: getCustomer
      description: list all customers
      tags:
        - Customer
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Customer'
    post:
      operationId: postCustomer
      tags:
        - Customer
      description: Create a customer
      requestBody:
        $ref: '#/components/requestBodies/CreateCustomer'
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CustomerId'
  /customers/{CustomerId}:
    get:
      description: get customer by id
      operationId: getSingleCustomer
      tags:
        - Customer
      parameters:
        - $ref: '#/components/parameters/CustomerId'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/CustomerProperties'
                  - $ref: '#/components/schemas/CustomerRequiredProperties'
    put:
      description: Update customer
      operationId: updateCustomer
      tags:
        - Customer
      requestBody:
        $ref: '#/components/requestBodies/CreateCustomer'
      parameters:
        - $ref: '#/components/parameters/CustomerId'
      responses:
        '204':
          description: Updated
  '/accounts':
    get:
      operationId: getAccounts
      description: list all accounts
      tags:
        - Account
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Account'
    post:
      operationId: postAccount
      tags:
        - Account
      description: Create an account
      requestBody:
        description: Create a new account
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/AccountProperties'
                - $ref: '#/components/schemas/AccountRequiredProperties'
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AccountId'
components:
  parameters:
    CustomerId:
      name: CustomerId
      in: path
      required: true
      schema:
        $ref: '#/components/schemas/Id'
  requestBodies:
    CreateCustomer:
      description: Create a new customer
      content:
        application/json:
          schema:
            allOf:
              - $ref: '#/components/schemas/CustomerProperties'
              - $ref: '#/components/schemas/CustomerRequiredProperties'
  schemas:
    Id:
      type: integer
    CustomerId:
      type: object
      properties:
        Id:
          $ref: '#/components/schemas/Id'
    Customer:
      allOf:
        - $ref: '#/components/schemas/CustomerId'
        - $ref: '#/components/schemas/CustomerProperties'
        - $ref: '#/components/schemas/CustomerRequiredProperties'
    CustomerRequiredProperties:
      type: object
      required:
        - FirstName
        - LastName
        - DOB
    CustomerProperties:
      type: object
      properties:
        FirstName:
          type: string
        LastName:
          type: string
        DOB:
          type: string
          format: date-time
        Segment:
          type: string
          enum:
            - Young
            - MiddleAged
            - Old
            - Moribund
    Account:
      allOf:
        - $ref: '#/components/schemas/CustomerId'
        - $ref: '#/components/schemas/CustomerProperties'
        - $ref: '#/components/schemas/CustomerRequiredProperties'
    AccountId:
      type: object
      properties:
        Id:
          $ref: '#/components/schemas/Id'
    AccountRequiredProperties:
      type: object
      required:
        - AccountName
        - Type
        - AccountDescription
    AccountProperties:
      type: object
      properties:
        AccountName:
          type: string
        AccountDescription:
          type: string
        endDate:
          type: string
          format: date-time
        Type:
          type: string
          enum:
            - Young
            - MiddleAged
            - Old
            - Moribund