oas3-rs icon indicating copy to clipboard operation
oas3-rs copied to clipboard

$ref schemas ignore other constraints

Open janrueth opened this issue 3 weeks ago • 0 comments

I was test driving the library using the pet-store example on swagger.io: https://petstore31.swagger.io/api/v31/openapi.json

This contains things like:

        "requestBody" : {
          "description" : "Pet object that needs to be updated in the store",
          "content" : {
            "application/json" : {
              "schema" : {
                "$ref" : "#/components/schemas/Pet",
                "description" : "A Pet in JSON Format",
                "required" : [ "id" ],
                "writeOnly" : true
              }
            },

"Pet" : {
        "$schema" : "https://json-schema.org/draft/2020-12/schema",
        "description" : "Pet",
        "properties" : {
          "id" : {
            "type" : "integer",
            "format" : "int64"
          },
          "category" : {
            "$ref" : "#/components/schemas/Category",
            "description" : "Pet Category"
          },
          "name" : {
            "type" : "string",
            "examples" : [ "doggie" ]
          },
          "photoUrls" : {
            "type" : "array",
            "items" : {
              "type" : "string",
              "xml" : {
                "name" : "photoUrl"
              }
            },
            "xml" : {
              "wrapped" : true
            }
          },
          "tags" : {
            "type" : "array",
            "items" : {
              "$ref" : "#/components/schemas/Tag"
            },
            "xml" : {
              "wrapped" : true
            }
          },
          "status" : {
            "type" : "string",
            "description" : "pet status in the store",
            "enum" : [ "available", "pending", "sold" ]
          },
          "availableInstances" : {
            "type" : "integer",
            "format" : "int32",
            "examples" : [ "7" ],
            "exclusiveMaximum" : 10,
            "exclusiveMinimum" : 1,
            "swagger-extension" : true
          },
          "petDetailsId" : {
            "type" : "integer",
            "format" : "int64",
            "$ref" : "/api/v31/components/schemas/petdetails#pet_details_id"
          },
          "petDetails" : {
            "$ref" : "/api/v31/components/schemas/petdetails"
          }
        },
        "required" : [ "name", "photoUrls" ],
        "xml" : {
          "name" : "Pet"
        }
      },

I initially thought, that the schema is buggy, since it defined $ref and other constraints/fields in the schema object which in OpenAPI 3.0 was not allowed.

However, this is now allowed in OpenAPI 3.1 as it is allowed in the underlying json schema spec.

So for example, for the Pet in the requestBody above, [ "name", "photoUrls" ] and [ "id" ] fields need to be present.

When this crate resolves references it just takes the reference and ignores all other fields ( here ignores that id is also required).

I think it would need to merge constraints selecting the more strict constraint and overwrite "informational" fields such as description

janrueth avatar Nov 25 '25 12:11 janrueth