Redocly / Redocly/redocly-cli

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

Open
#1,276 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

governance p3 Type: Enhancement
Dominant language
TypeScript
Stars
1.5k
Forks
228
Avg merge
1d 14h
Merged PRs (30d)
48

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Locate the no-invalid-media-type-example(s) rule and reproduce the report with the OpenAPI document shown in the issue. Run redocly lint sample.json and verify that the XML example using the schema's OAS XML metadata no longer raises a false positive.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, typescript
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.