How to define UUID property in JSON Schema and Open API (OAS)

前端 未结 3 1377
醉酒成梦
醉酒成梦 2021-01-07 16:50

When using JSON Schema and Open API specification (OAS) to document a REST API, how do I define the UUID property?

3条回答
  •  北海茫月
    2021-01-07 17:34

    The only way I found so far is to manually specify the RegEx pattern as reusable schema component:

    openapi: 3.0.1
    
    paths:
      /transactions/:
        post:
          responses:
            200:
              content:
                application/json:
                  schema:
                    type: object
                    properties:
                      transactionId:
                        $ref: '#/components/schemas/uuid'
    
    components:
      schemas:
        uuid:
          type: string
          pattern: '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'
    

    But, I would definitely want to use a more standardized approach.

提交回复
热议问题