Forum Discussion

Jaymeen-Sonara's avatar
Jaymeen-Sonara
New Member
2 months ago

How to define both fixed and dynamic fields in request body (visible in Swagger/Mintlify UI)?

I'm working on an OpenAPI 3.0 specification and I need to define a request body schema that includes:

  • Two static fields: title (string) and description (string), both required
  • Additional dynamic/custom fields with unknown names and values that can be complex (objects, arrays, strings, etc.)

I have tried using additionalProperties like this:

{ "type": "object", "properties": { "title": { "type": "string" }, "description": { "type": "string" } }, "required": ["title", "description"], "additionalProperties": true }

1 Reply

  • Using `additionalProperties: true` (or `unevalutatedProperties: true` for OAS 3.1 and above) are appropriate ways to solve your goal.

    What are you expecting to happen that's not working? 

    It might be just that you are not seeing renders making it very clear to that additional properties are allowed in these scenarios. Note - JSON schema is a constraints based language, so you should validate the schema against a JSON instance to determine validity.

    The latest versions of SwaggerUI give some additional hints that additional/unevaluated properties are allowed.

    For OAS 3.0.*, the Example Value field with show an `additionalProp1` to give an indication that more properties can be specifiedFor OAS 3.1.*, the Schema renderer also shows that Additional Properties are allowed

    You can check out the behaviour here: https://editor-next.swagger.io/