json - APIM Swagger Issue on Validation OpenAI APIs - Stack Overflow

admin2025-04-17  4

I used the Azure OpenAI API 2024-12-01-preview swagger and uploaded into my Azure APIM

After Uploaded into the APIM my swagger yaml looks like this

In my APIM, I used JSON validation for input requests against the swagger spec like below

        <validate-content unspecified-content-type-action="ignore" max-size="4194394" size-exceeded-action="detect" errors-variable-name="requestBodyValidation">
            <content type="application/json" validate-as="json" action="prevent" allow-additional-properties="true" />
        </validate-content>

This is working all find however, if I provide vision input like image_url (like below request which is valid one) for that i got bad request such that the validation of json is blocking the request

Request

{
    "messages": [
       { 
           "role": "system", 
           "content": "" 
        },
       { 
           "role": "user", 
           "content": [
               { 
                   "type": "text", 
                   "text": "describe"
               },
               {
                   "type": "image_url",
                   "image_url": {
                       "url": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAP8AAAD/CAYAAAA+CADKAAAAAXNSR0IArs4c6QAAIABJREFUeF7svYeSXNeVJbquS+/Ke3hPEiRFeanNaDrmxUzEvHjxPnHmF6bnzUy0mVaPRKlJ0YOEIYACUN6nz7z2xdr7nMwsSGJ3U2qVKFQxigCysjLznnu2W3vtdZz/8h//a4bzr/MVOF+BV24FnSJQfFUDLarphQVLQQ7/KIG+mP+9/+OJdSXheRWcR7WpppkaToLd1nl2AWzVOKPmju5650G49gucl6OBZzHe5PAE/afuSDkvLuz/DrcKLa8vv/H6D9yL14BMhIWGQjq6lN7ho0IuQVSfWbFwJOGiqQf0or+/wFrbnH3sR7ztgAAAABJRU5ErkJggg=="
                       }
                   }
               ]
           }
       ],     
     "stream":true
}

Response

 {
     "statusCode": 400,
     "message": "Body of the request does not conform to the definition which is associated with the content type application/json. Path:messages[1].role Message: Value \"user\" is not defined in enum. Line: 8, Position: 20 SchemaId: #/components/schemas/chatCompletionRequestFunctionMessage/properties/role"
 }

From the error its complaining about chatCompletionRequestFunctionMessage but i dont know why its picking up this schema it supposed to be get picked by chatCompletionRequestUserMessage and chatCompletionRequestUserMessageContentPart

I'm not sure if this due to any error on the swagger spec or any issues from the APIM swagger validator !

转载请注明原文地址:http://anycun.com/QandA/1744861250a88653.html