Skip to content

Can I Specify a Flexible Properties of Any Type on a Schema? #2773

@jake-xie-sfdc

Description

@jake-xie-sfdc

Hi OpenAPI-Specification team,
We are on OpenAPI Specification 3.0.1. We have a highly customizable platform that allows users to create custom fields on a schema. For example, let's say we provide a schema called "Order" out of the box:

Order:
      type: object
      properties:
        id:
          type: integer
          format: int64
        shipDate:
          type: string
          format: date-time
        status:
          type: string
          description: Order Status
          enum:
          - placed
          - approved
          - delivered
        complete:
          type: boolean
          default: false
      xml:
        name: Order

Let's say the customer retrieve an OpenAPI specification (OAS) that contains the above schema. They generate a client library using the OAS and can use it in code to populate the field value like following:

order.setShipDate("10/29/2021");

Now let's say they add a new custom field call "quantity" to the order schema:

quantity:
  type: integer
  format: int32

But they don't regenerate client library using the updated OAS. , so they can't do order.setQuantity(2); in their code.

If possible, we would like to reduce the number of times that customers need to regenerate OAS and client library. We are thinking about defining a flexible field on the schema that can support any number of properties of any type. For example, something like

properties:
  anyPropertyName:
     type: anyType

And by doing so, we hope to enable following capability in client code:

order.setShipDate("10/29/2021");  // "ShipDate" is a property provided out of the box, so customers can directly do setShipDate
order.setField("quantity", 2);  // "quantity" is a customer-defined field, not a property provided out of the box, so customers need to use setField(fieldName, fieldValue) to populate the object
order.setField("shippingCity", "San Francisco");  // "shippingCity" is a customer-defined field, not a property provided out of the box, so customers need to use setField(fieldName, fieldValue) to populate the object

So, my question: Is there anything in OpenAPI specification 3.0.1 that allow us to specify a flexible property under schema that allow us to do object.setField(fieldName, fieldValue) ?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions