redocly-cli icon indicating copy to clipboard operation
redocly-cli copied to clipboard

Rules no-invalid-media-type-example does not handle OAS specifics tags for XML

Open LasneF opened this issue 11 months ago • 1 comments

Describe the bug no-invalid-media-type-example is behaving incorrectly and raising a false positive error when using XML

OAS specify dedicated tag to handle XML around tag names rewrite , name space, and attribute. Those looks not handled by redoclint

To Reproduce given the specification below the example is correct but redoclint raises the below error using the minimal command line : redocly lint sample.json Warning was generated by the no-invalid-media-type-examples rule. with Example value must conform to the schema: type must be object.

Expected behavior

The example should not raise an error , as the file is correct

Logs

[7] sample.json:18:44 at #/paths/~1pet/get/responses/200/content/application~1xml/example

Example value must conform to the schema: type must be object.

16 |             "$ref": "#/components/schemas/niceCatResult"
17 |         },
18 |         "example": "<Cat><nice>true</nice></Cat>"
19 |     }
20 | }

referenced from sample.json:14:48 at #/paths/~1pet/get/responses/200/content/application~1xml

OpenAPI description

{
    "openapi": "3.0.0",
    "info": {
        "title": "Kitten",
        "version": "1.0.0"
    },
    "paths": {
        "/pet": {
            "get": {
                "responses": {
                    "200": {
                        "description": "cat",
                        "content": {
                            "application/xml": {
                                "schema": {
                                    "$ref": "#/components/schemas/niceCatResult"
                                },
                                "example": "<Cat><nice>true</nice></Cat>"
                            }
                        }
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "niceCatResult": {
                "type": "object",
                "properties": {
                    "nice" : {
                        "type": "string"
                    }
                },
                "xml": {
                    "name": "Cat"
                }
            }
        }
    }
}

Redocly Version(s)

Using 1.0.2

LasneF avatar Sep 28 '23 07:09 LasneF

Thanks for reporting @LasneF!

tatomyr avatar Sep 28 '23 09:09 tatomyr