question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

no-invalid-media-type-examples | not working as expected

See original GitHub issue

Describe the bug

i’ve looked at the OAS schema and it uses either a ref or example object. We are using an example schema in our definition but the external file is not a valid example per the linter. I can’t share the full schema for a repo of the issue but my external schema file is matching the expected response body schema, is there any reason why the linter says it should be type object? my external document is a valid uri

$ redocly lint --config ~/repos/.redocly.yaml openapi.json --format stylish

validating specs/openapi.json...
openapi.json:
  101:22  warning  no-invalid-media-type-examples  Example value must conform to the schema: type must be object.

openapi.json

"content": {
	"application/json": {
		"schema": {
			"$ref": "./schemas/response-schema_v01.json"
		},
		"examples": {
			"response": {
				"externalValue": "./examples/success-response_v01.json"
			}
		}
	}
}

Response body schema

{
	"$schema": "http://json-schema.org/draft-04/schema#",
	"title": "ActivityLogs",
	"description": "Activity Logs",
	"type": "object",
	"properties": {
		"ActivityLogs": {
			"type": "array",
			"items": {
				"type": "object",
				"additionalProperties": false,
				"properties": {
					"activityLog": {
						"$ref": "../../../../common/logEntryBaseType_v02.json"
					},
					"links": {
						"type": "array",
						"items": {
							"$ref": "../../../../common/linkType_v01.json"
						}
					}
				}
			}
		}
	},
	"additionalProperties": false
}

Example

{
	"ActivityLogs": [
		{ 
                      "activityLog": { ...

OAS meta schema

"examples": {
        "properties": {
          "example": true,
          "examples": {
            "type": "object",
            "additionalProperties": {
              "$ref": "#/$defs/example-or-reference"
            }
          }
        }
      },
"$defs": {
"example-or-reference": {
        "if": {
          "type": "object",
          "required": [
            "$ref"
          ]
        },
        "then": {
          "$ref": "#/$defs/reference"
        },
        "else": {
          "$ref": "#/$defs/example"
        }
      }
},
"example": {
        "$comment": "https://spec.openapis.org/oas/v3.1.0#example-object",
        "type": "object",
        "properties": {
          "summary": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "value": true,
          "externalValue": {
            "type": "string",
            "format": "uri"
          }
        },
        "not": {
          "required": [
            "value",
            "externalValue"
          ]
        },
        "$ref": "#/$defs/specification-extensions",
        "unevaluatedProperties": false
      }



Issue Analytics

  • State:open
  • Created a year ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
jeremyfielcommented, Nov 11, 2022

i’ve tried to make a solid example of different locations and usage of examples in OAS3.0.x and OAS3.1.x based on discussion with Andrew in our call.

I’m asking for Redocly to support externalValue $ref resolution to validate examples against the request/response/example/header/parameter schema.

I may be able to provide some development effort from our internal tooling team to make this happen. If there is interest, we can arrange further discussion for how you would like the feature added.

redocly-examples-repo.md

0reactions
tatomyrcommented, Nov 11, 2022

Thanks for summing it up!

Read more comments on GitHub >

github_iconTop Results From Across the Web

no-invalid-media-type-examples - Redocly
Disallow invalid media type examples by ensuring they comply with the corresponding schema definitions.
Read more >
no-invalid-media-type-examples fails with "schema with key or ...
Exception schema with key or id "C:\Users\ybagriy\sources\scripts\Clients\Client.yaml" already exists is thrown by ajv. I'm not familiar with it ...
Read more >
Flutter: Http post request Error Invalid media type: expected
Use this for post request. Future<Map<String, dynamic>> postRequest(String url, Map jsonMap) async{ print('$url , $jsonMap'); HttpClient ...
Read more >
415 Unsupported Media Type - HTTP - MDN Web Docs
The HTTP 415 Unsupported Media Type client error response code indicates that the server refuses to accept the request because the payload ...
Read more >
Describing Responses - Swagger
To specify the response media types, use the produces keyword on the root level ... By "known errors" we mean, for example, a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found