Specmatic Generated Value Exceeds Defined Maximum for Query Parameter in OpenAPI Specification #1146
-
Open API Spec
Although the count query parameter has a defined minimum of 1 and a maximum of 100 in the OpenAPI specification, Specmatic generated a value greater than 100 and expected a 200 status code response for this invalid input.
How can this be resolved or what are the possible workarounds? |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 2 replies
-
Hi @premsvmm, thanks for reporting this issue. |
Beta Was this translation helpful? Give feedback.
-
Hey @premsvmm, this has been taken care of in the latest version of Specmatic [1.3.26]. |
Beta Was this translation helpful? Give feedback.
-
Hi @yogeshnikam671 , Thank you for informing me that the reported issue has been resolved in the latest version. However, I'm encountering a problem with version 1.3.26 when running the tests. It fails to load the specmatic.json config file, which wasn't an issue in version 1.3.24. Here are the logs to help diagnose the issue:
While running the contract test:
|
Beta Was this translation helpful? Give feedback.
-
Hi @premsvmm, thanks for reporting this. |
Beta Was this translation helpful? Give feedback.
-
With the latest version 1.3.26 , the minimum and maximum constraints are not being enforced in the properties field:
Even though the min and max values are set, the test payload is generating values less than the specified minimum. |
Beta Was this translation helpful? Give feedback.
-
@premsvmm I tested with your API specification above with Specmatic 1.3.29 and it is generating values within the set Also, I see that your name examples are not co-ordinated between request and response. In Once I fixed this (renamed Unsuccessful Scenarios:
"Load Error FAILED"
Reason: Error loading test data for Scenario: POST /v1/orders -> 200
>> REQUEST.BODY.amount
Expected number <= 100000 as per the specification, but the example example_1 had 1000000 (number) Then once I fixed this, the tests ran with the values in the examples. Here is the full updated spec. openapi: 3.0.1
info:
title: Order API
description: API for creating orders
version: 1.0.0
servers:
- url: https://localhost
components:
securitySchemes:
basicAuth:
type: http
scheme: basic
schemas:
OrderRequest:
type: object
required:
- amount
- currency
properties:
amount:
type: integer
minimum: 100
maximum: 100000
example: 100
description: Amount in the smallest currency unit (e.g., paise for INR)
currency:
type: string
description: Currency code
enum: [INR, USD]
receipt:
type: string
nullable: true
description: Receipt identifier
notes:
type: object
additionalProperties:
type: string
description: Additional notes
OrderResponse:
type: object
properties:
id:
type: string
amount:
type: integer
minimum: 100
maximum: 100000
currency:
type: string
receipt:
type: string
nullable: true
status:
type: string
notes:
oneOf:
- type: object
additionalProperties:
type: string
- type: array
items:
type: object
amount_due:
type: integer
amount_paid:
type: integer
attempts:
type: integer
created_at:
type: integer
entity:
type: string
offer_id:
type: string
nullable: true
ErrorResponse:
type: object
properties:
error:
type: object
properties:
code:
type: string
description:
type: string
field:
type: string
nullable: true
source:
type: string
step:
type: string
reason:
type: string
metadata:
type: object
additionalProperties: true
security:
- basicAuth: []
paths:
/v1/orders:
post:
summary: Create an Order
operationId: createOrder
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/OrderRequest'
examples:
example:
summary: Success Request
value:
amount: 10000
currency: "INR"
receipt: "Receipt no. 1"
notes:
notes_key_1: "Tea, Earl Grey, Hot"
notes_key_2: "Tea, Earl Grey… decaf."
"[WIP] SUCCESS":
summary: Success Request
value:
amount: 100000
currency: "INR"
receipt: "Receipt no. 1"
notes:
notes_key_1: "Tea, Earl Grey, Hot"
notes_key_2: "Tea, Earl Grey… decaf."
responses:
'200':
description: Order created successfully
content:
application/json:
schema:
$ref: '#/components/schemas/OrderResponse'
examples:
example:
summary: Successful response with notes as object
value:
amount: 10000
amount_due: 1000000
amount_paid: 0
attempts: 0
created_at: 1717991270
currency: "INR"
entity: "order"
id: "order_OKumxaVkPEnex7"
notes:
notes_key_1: "Tea, Earl Grey, Hot"
notes_key_2: "Tea, Earl Grey… decaf."
offer_id: null
receipt: "Receipt no. 1"
status: "created"
"[WIP] SUCCESS":
summary: Successful response with notes as array
value:
amount: 10000
amount_due: 1000000
amount_paid: 0
attempts: 0
created_at: 1717991270
currency: "INR"
entity: "order"
id: "order_OKumxaVkPEnex7"
notes: []
offer_id: null
receipt: "Receipt no. 1"
status: "created"
'400':
description: Bad Request
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse' Here are the logs from my testing. % specmatic test test.yaml
API Specification Summary: test.yaml
OpenAPI Version: 3.0.1
API Paths: 1, API Operations: 1
Schema components: 3, Security Schemes: [http]
Endpoints API not found, cannot calculate actual coverage
--------------------
Request to http://localhost:9000 at 2024-6-25 7:7:50.841
POST /v1/orders
Authorization: Basic UEpPUVI6V0NYQ1Q=
Accept-Charset: UTF-8
Accept: */*
Content-Type: application/json
{
"amount": 10000,
"currency": "INR",
"receipt": "Receipt no. 1",
"notes": {
"notes_key_1": "Tea, Earl Grey, Hot",
"notes_key_2": "Tea, Earl Grey… decaf."
}
}
Response at 2024-6-25 7:7:50.842
200 OK
Vary: Origin
X-Specmatic-Result: success
Content-Length: 398
Content-Type: application/json
Connection: keep-alive
{
"amount": 10000,
"amount_due": 1000000,
"amount_paid": 0,
"attempts": 0,
"created_at": 1717991270,
"currency": "INR",
"entity": "order",
"id": "order_OKumxaVkPEnex7",
"notes": {
"notes_key_1": "Tea, Earl Grey, Hot",
"notes_key_2": "Tea, Earl Grey… decaf."
},
"offer_id": null,
"receipt": "Receipt no. 1",
"status": "created"
}
Scenario: POST /v1/orders -> 200 | EX:example has SUCCEEDED
--------------------
Request to http://localhost:9000 at 2024-6-25 7:7:50.864
POST /v1/orders
Authorization: Basic RkVEWEU6QUlHSEU=
Accept-Charset: UTF-8
Accept: */*
Content-Type: application/json
{
"amount": 100000,
"currency": "INR",
"receipt": "Receipt no. 1",
"notes": {
"notes_key_1": "Tea, Earl Grey, Hot",
"notes_key_2": "Tea, Earl Grey… decaf."
}
}
Response at 2024-6-25 7:7:50.864
200 OK
Vary: Origin
X-Specmatic-Result: success
Content-Length: 297
Content-Type: application/json
Connection: keep-alive
{
"amount": 10000,
"amount_due": 1000000,
"amount_paid": 0,
"attempts": 0,
"created_at": 1717991270,
"currency": "INR",
"entity": "order",
"id": "order_OKumxaVkPEnex7",
"notes": [],
"offer_id": null,
"receipt": "Receipt no. 1",
"status": "created"
}
Scenario: POST /v1/orders -> 200 | EX:[WIP] SUCCESS has SUCCEEDED
Could not load report configuration, coverage will be calculated but no coverage threshold will be enforced
|-----------------------------------------------------------------------|
| API COVERAGE SUMMARY |
|-----------------------------------------------------------------------|
| coverage | path | method | response | # exercised | remarks |
|----------|------------|--------|----------|-------------|-------------|
| 33% | /v1/orders | POST | 200 | 2 | covered |
| | | | 400 | 0 | did not run |
| | | | 401 | 0 | did not run |
|-----------------------------------------------------------------------|
| 33% API Coverage reported from 1 path |
|-----------------------------------------------------------------------|
Saving Open API Coverage Report json to ./build/reports/specmatic ...
Tests run: 2, Successes: 2, Failures: 0, Errors: 0 Please feel free to reach out to us if you have any questions on this. |
Beta Was this translation helpful? Give feedback.
-
Thanks @harikrishnan83 for the detailed explanation. The named example changes made it work perfectly. |
Beta Was this translation helpful? Give feedback.
@premsvmm I tested with your API specification above with Specmatic 1.3.29 and it is generating values within the set
minimum
andmaximum
values for youramount
field. Can you please check again with the latest version of Specmatic?Also, I see that your name examples are not co-ordinated between request and response. In
request
section you have two examplesexample
and[WIP] SUCCESS
, however inresponses
you haveexamples_1
andexamples_2
. So your examples were not getting picked up as test data. Since OpenAPI inherently does not have a way to associaterequest
andresponse
examples, in Specmatic we leverage example names as a way to associate request and responses.Once I fixed this (re…