No sample values or examples provided for API Conformance Scan

Issue ID: v3-warning-sample-undefined

Description

One or more parameter or schema objects in your API are missing sample values or examples that Conformance Scan could use to generate successful happy path requests.

When you scan an API, Conformance Scan generates and sends a happy path request to all operations in your API to establish a successful benchmark against which it can then compare the results from the intentionally malformed test requests. Any operations where the happy path request fails are skipped in the scan.

To successfully call the API operations, Conformance Scan must follow the OpenAPI definition of the API and provide all required parameters in the calls. It may be very difficult to create valid values for some things, like some object schemas, or strings with a very specific pattern. To ensure best performance, we recommend including samples or examples directly in your OpenAPI definition by using the x-42c-sample or example objects.

For more details, see:

Example

The following is an example of how this issue could look in your API definition. The property name is quite well defined, but it does not provide one or more sample values that Conformance Scan could use:

{
    "components": {
        "schemas": {
            "Dog": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                    "name"
                ],
                "properties": {
                    "name": {
                        "type": "string",
                        "maxLength": 20,
                        "pattern": "^[A-Za-z]{3,20}$"
                    }     
                    // ...
                }
            }
        }
    }    
}

Remediation

Make sure that you define sample values using the properties x-42c-sample or example for schema objects:

{
    "components": {
        "schemas": {
            "Dog": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                    "name"
                ],
                "properties": {
                    "name": {
                        "type": "string",
                        "maxLength": 20,
                        "pattern": "^[A-Za-z]{3,20}$",
                        "x-42c-sample": "Porkchop"
                    }     
                    // ...
                }
            }
        }
    }    
}

If you need to define an array of sample values, use the property examples:

{
    "components": {
        "schemas": {
            "Dog": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                    "name"
                ],
                "properties": {
                    "name": {
                        "type": "string",
                        "maxLength": 20,
                        "pattern": "^[A-Za-z]{3,20}$"
                    }     
                    // ...
                },
                "examples": [
                    "Porkchop",
                    "Jimmy Chew",
                    "Bark Twain"
                ]
            }
        }
    }    
}

For mediaType objects and simple parameter objects not in body, use the properties x-42c-sample or example:

{
    "parameters": [
        {
            "name": "limit",
            "in": "query",
            "description": "How many items to return at one time (max 100)",
            "required": false,
            "schema": {
                "type": "integer",
                "format": "int32"
            },
            "x-42c-sample": 0
        }
    ]
}