-
Notifications
You must be signed in to change notification settings - Fork 60
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
When we have a schema that defines a field of object type as optional, and if in the request body we don't include that optional field, oas tool complains.
To Reproduce
Steps to reproduce the behavior:
- the schema of object definition as the following:
schemas:
TestDocument:
type: object
required:
- version
- id
properties:
version:
description: Schema version
type: string
id:
description: Unique ID
type: string
example: 1234567
owner:
$ref: '#/components/schemas/Owner'
Owner:
type: object
required:
- id
properties:
id:
type: string
format: uri
name:
type: string
minLength: 1
maxLength: 256
- The following is the configuration to initiate the api server
const express = require("express");
const { initialize } = require('@oas-tools/core');
const serverPort = 8000;
const app = express();
app.use(express.json({limit: '50mb'}));
const config = {
middleware: {
validator: {
strict: true,
requestValidation: true,
responseValidation: true,
},
}
}
initialize(app, config).then(() => {
http.createServer(app).listen(serverPort, () => {
console.log("\nApp running at http://localhost:" + serverPort);
console.log("________________________________________________________________");
if (config.middleware.swagger?.disable !== false) {
console.log('API docs (Swagger UI) available on http://localhost:' + serverPort + '/docs');
console.log("________________________________________________________________");
}
});
});
- Send the following in a request body
{
"version": "v1",
"id": "12"
}
Expected behavior
This should pass the schema validation.
Instead, the API sever return 404 with the following error
{
"error": "RequestValidationError: Request body does not match the schema specified in the OAS Document:\n- Validation failed at #/properties/owner/required > must have required property 'id'"
}
Screenshots
Additional context
this is for oas-tool version "3.0.3
The problem is with parseBody function that it would set "owner" value as {} . it results in the schema validation. The "owner" should be omitted in this case.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
Type
Projects
Status
Done