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.

Examples field is not validated against openAPI 3.0.0 spec

See original GitHub issue

Describe the bug No validation rule applies on the “Examples” field name defined in https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#exampleObject –> All the fixed fields declared above are objects that MUST use keys that match the regular expression: ^[a-zA-Z0-9.-_]+$.

To Reproduce I created an openapi.yaml containing the following lines

parameters:
    - name: identifier
    - required: true
          in: path
          allowEmptyValue: false
          description: Some description
          examples:
            valid identifier:
              description: 'Some description'
              value: '49039557299384'

Running ‘redocly lint openapi.yaml’ returns that the file is valid.

The field name ‘valid identifier’ within the examples is invalid but I could not find any rule detecting this. An custom built assertion rule did not work because it only works for the value of a given property.

Expected behavior An error should be shown, that the ‘valid identifier’ is invalid

OpenAPI definition .redocly.yaml

lint:
  extends:
    - all

Specification version used: 3.0.0

Redocly Version(s) v1.0.0-beta.103

Node.js Version(s) v16.12.0

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
tatomyrcommented, Aug 1, 2022

Basing on the internal discussion it’s been decided to implement this as a separate rule with the spec prefix.

1reaction
azimbelmcommented, Jul 11, 2022

Workaround for anyone who needs this now:

Create a Plugin/Custom Rule (use this guide: https://redocly.com/docs/cli/guides/response-contains-property/#response-contains-property.js) and use this code:

function ExampleKeyMatchesOASSpec () {
  return {
    Example(example, { key, report, location }) {
      if(new RegExp('^[a-zA-Z0-9\\.\\-_]+$').test(key) == false){
      //if (example.value || example.externalValue) {
        report({
          message: 'The key of the example "'+key+'" does not match the regular expression "^[a-zA-Z0-9\\.\\-_]+$"',
          location: location.key(),
        });
      }
  }
}}
Read more comments on GitHub >

github_iconTop Results From Across the Web

OpenAPI Specification - Version 3.0.3 - Swagger
For example, a valid OpenAPI 3.0.2 document, upon changing its openapi property ... In the following description, if a field is not explicitly...
Read more >
Integrated Swagger UI throws error on valid OpenAPI spec file
Summary When opening a valid OpenAPI JSON file from the Repository / Files section, an error message is displayed saying:
Read more >
What does 'required' in OpenAPI really mean - Stack Overflow
An object instance is valid against this keyword if every item in the [ required ] array is the name of a property...
Read more >
OpenAPI.Tools
openapi -core - Validate your requests and responses against an OpenAPI 3 specification and get very verbose and human-readable descriptions of errors. You...
Read more >
OpenAPI Specification v3.0.3 | Introduction, Definitions, & More
The OpenAPI Specification (OAS) defines a standard, programming language-agnostic interface description for HTTP APIs.
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