Skip to main content

to_openapi3

Function to_openapi3 

Source
pub fn to_openapi3(value: &mut Value)
Expand description

Rewrite vld’s JSON Schema (2020-12) into the OpenAPI 3.0 dialect, applied when the generator uses SchemaSettings::openapi3():

  • tuples (prefixItems + items: false) become items: {anyOf: [...]} with the existing minItems / maxItems;
  • null branches of anyOf / oneOf and "null" in a type array become nullable: true (a lone remaining $ref is wrapped in allOf);
  • numeric exclusiveMinimum / exclusiveMaximum (2020-12) become minimum / maximum plus the boolean 3.0 exclusiveMinimum: true / exclusiveMaximum: true;
  • a schema that only allows null becomes {"type": "string", "nullable": true, "enum": [null]} (3.0 ignores nullable without a type, and has no null type).

Doing it here keeps schemars’ own OpenAPI 3.0 transforms from producing additionalItems or {"enum": [null], "nullable": true}.