Closed tillig closed 6 days ago
hi @tillig
Would this be the expected result?
I created a PR that would fix the issue, but i'm not sure about the result.
Yeah, I think that's right. This is actually a very, very pared down bit of a larger schema where the real replacement is a {{variable}}
that has a value, but whether it's a variable or a plain value, the exception message ends up being the same.
My assumption is that with oneOf
or anyOf
, the overwrite should take the 1st item since there could be multiple, and use that object to apply the overwrite. The current implementation overwrites the whole object.
I will dive in deeper.
hi @tillig
After some investigating, I have found the actual cause. The OpenAPI was missing a type per oneOf (with assistance from ChatGPT).
If we modified the spec from
components:
schemas:
dateTimeType:
description: Either a date-only or a date with a time.
oneOf:
- format: date-time
- format: date
type: string
to
components:
schemas:
dateTimeType:
description: Either a date-only or a date with a time.
oneOf:
- type: string
format: date-time
- type: string
format: date
The conversion (v1.30.1) did properly process it (without error) resulting in this:
While I don't mind changing the schema, based on examples like this one from json-schema.org
...
{
"type": "number",
"oneOf": [
{ "multipleOf": 5 },
{ "multipleOf": 3 }
]
}
...it seems like having the type: string
outside the oneOf
should be legal.
hi @tillig
We have just released Portman v1.30.2, this contains the improvements to prevent the error with the oneOf schema.
If this works for you, feel free to close this issue.
I'm still working on getting a chance to test this. I haven't forgotten, I just haven't been at a keyboard.
@tillig No worries, there is no time pressure. Being away from the keyboard is usually better, since it could mean other fun activities.
Verified - 1.30.2 works great. Thanks!
I have a schema with a single operation
POST /event
where the body looks like:In the
portman-config.json
I have anoverwrite
specified for theevent.startDateTime
value.When using Portman 1.29.2, generating tests yields an error:
Under Portman 1.28.0 this works without error. Once it hits 1.29.0 I see the error.
I believe this has to do with
oneOf
on the property - thestartDateTime
may be adate
(2024-02-07
) or adate-time
(2024-02-07T12:13:14Z
) - in combination with usingoverwrites
and the new empty value testing.Click to see the JSON schema
```json { "components": { "schemas": { "dateTimeType": { "description": "Either a date-only or a date with a time.", "oneOf": [ { "format": "date-time" }, { "format": "date" } ], "type": "string" }, "event": { "description": "An object with a start date.", "properties": { "startDateTime": { "$ref": "#/components/schemas/dateTimeType" } }, "required": [ "startDateTime" ], "type": "object" }, "eventContainer": { "description": "Object that holds an event. The holder is important for the repro, if it's not here then the problem doesn't show.", "properties": { "event": { "$ref": "#/components/schemas/event" } }, "type": "object" } } }, "info": { "title": "Demo", "version": "v1" }, "openapi": "3.0.3", "paths": { "/event": { "post": { "description": "Creates an event.", "operationId": "post-event", "requestBody": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/eventContainer" } } } }, "responses": { "204": { "description": "Success." } }, "tags": [ "demo" ] } } }, "servers": [ { "description": "Demo API.", "url": "https://api.demo.com" } ], "tags": [ { "description": "Demo.", "name": "demo" } ] } ```Click to see the Portman config JSON
```json { "overwrites": [ { "openApiOperationIds": [ "post-event" ], "overwriteRequestBody": [ { "key": "event.startDateTime", "overwrite": true, "value": "2002-12-01" } ] } ], "tests": { "contractTests": [ { "openApiOperation": "*::/*" } ] }, "version": 1 } ```Click to see a simple package.json to drive the repro
Run `npm install && npm run build` to make it go. ```json { "devDependencies": { "@apideck/portman": "^1.30.0" }, "license": "ISC", "name": "specification", "scripts": { "build": "portman -l schema.json -o artifacts/tests/postman.json -c portman-config.json -b http://api", "clean": "rm -rf artifacts && mkdir -p artifacts", "prebuild": "npm run clean" }, "type": "commonjs", "version": "1.0.0" } ```