0

I want to let user allow flexibility to provide only one of either ref_id or dataCenter. Could someone correct this schema ?

  kind: kind
    metadata:
      name: kind.v1
      namespace: system
    spec:
      descrption: This is an example specification 
      schema:
        type: object
        properties:
          ref_id:
            type: string
            minLength: 25
            maxLength: 40
          dataCenter:
            type: string
            enum:
              - "abc"
              - "xyzzy"
          version:
            type: integer
            example: 1
        required:
          - ref_id
          - dataCenter
          - version
bosari
  • 1,922
  • 1
  • 19
  • 38
  • 1
    Does this answer your question? [Mutually exclusive properties in OpenAPI](https://stackoverflow.com/q/55615638/113116) – Helen Jan 29 '21 at 17:11
  • 1
    @Helen Yes it did and this too https://stackoverflow.com/questions/52563638/openapi-3-0-allof-inside-oneof – bosari Feb 01 '21 at 12:00

1 Answers1

0

Because you have additional properties besides those two, a simple oneOf would be insufficient. Instead, nest a oneOf for ref_id and dataCenter inside an allOf.

(Example simplified for brevity)

properties:
  allOf:
    - version:
    - oneOf:
      - ref_id:
      - dataCenter:
Software2
  • 2,358
  • 1
  • 18
  • 28