I have a doubt about the source code of jsonschema validator:, I'm checking the validators.py file, and found the function I'm using : "def validator_for(schema, default =_UNSET):" to validate through the error of my JSON as follows:
from jsonschema import validate
from jsonschema.validators import validator_for
def validator_schema():
sebas_schema = get_schema()
validator = validator_for(sebas_schema)(sebas_schema)
for error in validator.iter_errors(jsondata):
print(error)
validator = validator_schema()
This code iterate within a JSON file against a JSON schema to validate it if one or more key or values is the same or not, So when the income JSON file doesn't have one of the keys of the expected schema, it will raise an error, but the error comes along together with the whole schema at the command line (my schema has over 1000 lines), as the following:
Output:
python3 schemas_valid.py
'cycle' is a required property
Failed validating 'required' in schema:
{'$schema': 'http://json-schema.org/draft-07/schema#',
'properties': {'assessmentId': {'type': 'string'},
'customData': {'properties': {'missingDocuments': {'items': {'properties': {'codeGroup': {'type': 'string'},
'documents': {'items': {'type': 'string'},
'type': 'array'},
'requires': {'type': 'number'}},
'required': ['codeGroup',
'documents',
'requires'],
'type': 'object'},
'type': 'array'}},
'required': ['missingDocuments'],
'type': 'object'},
'cycle': {'type': 'string'},
'iteration': {'type': 'string'},
'typeCall': {'type': 'string'}},
'required': ['typeCall',
'assessmentId',
'iteration',
'cycle',
'customData'],
'title': 'Generated schema for Root',
'type': 'object'}
On instance:
{'assessmentId': '123456',
'customData': {'missingDocuments': [{'codeGroup': 'string',
'documents': ['string'],
'requires': 0}]},
'iteration': '1',
'typeCall': 'ASSESSMENT'}
'cycle' is a required property
Failed validating 'required' in the schema:
(1000 plus of JSON schema lines comes here)
Therefore, I would like to ask you guys if the output error message can be modified in the source code to only shown on the command line the first line of the error (name of the JSON key that is missing only), if so can you please guide me through where I could modify the error message in the JSON validator source code (validators.py)
Any help, I would really appreciate it :).
[SOLVED] : To print only the error message where the error is in the schema without the of printing the schema, just add the attribute at the print line:
for error in validator.iter_errors(jsondata):
print(error.message)
So the error.message will only print the line where the issue is with the schema.
Related
I am trying to call this api : http://localhost/api/columns {"tab":"client"}
but I couldn't get that one value from the json format
I get this error from the browser : {"code":404,"message":"No route found for \"GET \/api\/columns%20%7B%22tab%22:%22client%22%7D\""}
And tihs from CURL : {"code":400,"message":"Parameter \"tab\" of value \"NULL\" violated a constraint \"This value should not be null.\""}
This is my fos_rest.yml file :
fos_rest:
routing_loader: false
body_listener: true
exception:
enabled: true
param_fetcher_listener: force
view:
view_response_listener: 'force'
formats:
json: true
format_listener:
rules:
- { path: '^/api', prefer_extension: false , priorities: [json], fallback_format: json}
routes.yml
dashboard:
type: rest
resource: App\Controller\DashboardController
prefix : api
What I get from : php bin/console debug:router to check my routes :
get_columns GET ANY ANY /api/columns.{_format}
Typescript Version: 3.2.4
Angular version: ^7.2.15
Syncfusion Version: 17.1.50
Hi all. I am having an issue with Syncfusion's Pivot Grid. The code below is my onInit method which is taken straight from their demo. This was working as of 17.1.41 but now has magically stopped working. This issue is also on their StackBlitz example.
ngOnInit() {
let data: DataManager;
data = new DataManager({
url: this._controllerUrl + "/billing/extract",
adaptor: new WebApiAdaptor(),
crossDomain: true,
headers: [
{
"Content-Type": "application/json",
Accept: "application/json",
Authorization: "Bearer " + this.token
}
]
});
this.dataSource = {
enableSorting: true,
columns: [{ name: "Year" }, { name: "Month" }],
values: [{ name: "Cost", caption: "Cost (GBP)" }],
data: data,
rows: [{ name: "ServiceId" }],
formatSettings: [],
expandAll: false,
filters: []
};
this.button = new Button({ isPrimary: true });
this.button.appendTo("#export");
this.button.element.onclick = (): void => {
this.pivotGridObj.excelExport();
};
}
Here is the full error in Firefox:
ERROR Error: "Uncaught (in promise): TypeError: this.parent.dataSource.values is undefined
./node_modules/#syncfusion/ej2-pivotview/src/common/grouping-bar/axis-field-renderer.js/AxisFields.prototype.createPivotButtons#http://localhost:4200/views-billing-billing-module.js:197167:17
./node_modules/#syncfusion/ej2-pivotview/src/common/grouping-bar/axis-field-renderer.js/AxisFields.prototype.render#http://localhost:4200/views-billing-billing-module.js:197143:14
./node_modules/#syncfusion/ej2-pivotview/src/common/grouping-bar/grouping-bar.js/GroupingBar.prototype.appendToElement#http://localhost:4200/views-billing-billing-module.js:197347:49
./node_modules/#syncfusion/ej2-base/src/observer.js/Observer.prototype.notify#http://localhost:4200/views-billing-billing-module.js:10781:25
./node_modules/#syncfusion/ej2-base/src/component.js/Component.prototype.notify#http://localhost:4200/views-billing-billing-module.js:5505:32
./node_modules/#syncfusion/ej2-pivotview/src/pivotview/base/pivotview.js/PivotView.prototype.renderPivotGrid#http://localhost:4200/views-billing-billing-module.js:204990:18
./node_modules/#syncfusion/ej2-base/src/observer.js/Observer.prototype.notify#http://localhost:4200/views-billing-billing-module.js:10781:25
./node_modules/#syncfusion/ej2-base/src/component.js/Component.prototype.notify#http://localhost:4200/views-billing-billing-module.js:5505:32
./node_modules/#syncfusion/ej2-pivotview/src/pivotview/base/pivotview.js/PivotView.prototype.initEngine#http://localhost:4200/views-billing-billing-module.js:206000:14
./node_modules/#syncfusion/ej2-pivotview/src/pivotview/base/pivotview.js/PivotView.prototype.executeQuery#http://localhost:4200/views-billing-billing-module.js:206047:14
./node_modules/zone.js/dist/zone.js/</ZoneDelegate.prototype.invoke#http://localhost:4200/polyfills.js:7688:26
onInvoke#http://localhost:4200/vendor.js:82616:33
./node_modules/zone.js/dist/zone.js/</ZoneDelegate.prototype.invoke#http://localhost:4200/polyfills.js:7687:52
./node_modules/zone.js/dist/zone.js/</Zone.prototype.run#http://localhost:4200/polyfills.js:7447:43
scheduleResolveOrReject/<#http://localhost:4200/polyfills.js:8186:34
./node_modules/zone.js/dist/zone.js/</ZoneDelegate.prototype.invokeTask#http://localhost:4200/polyfills.js:7720:31
onInvokeTask#http://localhost:4200/vendor.js:82607:33
./node_modules/zone.js/dist/zone.js/</ZoneDelegate.prototype.invokeTask#http://localhost:4200/polyfills.js:7719:60
./node_modules/zone.js/dist/zone.js/</Zone.prototype.runTask#http://localhost:4200/polyfills.js:7492:47
drainMicroTaskQueue#http://localhost:4200/polyfills.js:7898:35
./node_modules/zone.js/dist/zone.js/</ZoneTask.invokeTask#http://localhost:4200/polyfills.js:7799:21
invokeTask#http://localhost:4200/polyfills.js:9041:14
globalZoneAwareCallback#http://localhost:4200/polyfills.js:9067:17
Here is the full error in Chrome/Edge
core.js:15724 ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'length' of undefined
TypeError: Cannot read property 'length' of undefined
at AxisFields.push../node_modules/#syncfusion/ej2-pivotview/src/common/grouping-bar/axis-field-renderer.js.AxisFields.createPivotButtons (axis-field-renderer.js:45)
at AxisFields.push../node_modules/#syncfusion/ej2-pivotview/src/common/grouping-bar/axis-field-renderer.js.AxisFields.render (axis-field-renderer.js:21)
at GroupingBar.push../node_modules/#syncfusion/ej2-pivotview/src/common/grouping-bar/grouping-bar.js.GroupingBar.appendToElement (grouping-bar.js:142)
at Observer.push../node_modules/#syncfusion/ej2-base/src/observer.js.Observer.notify (observer.js:89)
at PivotViewComponent.push../node_modules/#syncfusion/ej2-base/src/component.js.Component.notify (component.js:188)
at PivotViewComponent.push../node_modules/#syncfusion/ej2-pivotview/src/pivotview/base/pivotview.js.PivotView.renderPivotGrid (pivotview.js:881)
at Observer.push../node_modules/#syncfusion/ej2-base/src/observer.js.Observer.notify (observer.js:89)
at PivotViewComponent.push../node_modules/#syncfusion/ej2-base/src/component.js.Component.notify (component.js:188)
at PivotViewComponent.push../node_modules/#syncfusion/ej2-pivotview/src/pivotview/base/pivotview.js.PivotView.initEngine (pivotview.js:1891)
at PivotViewComponent.push../node_modules/#syncfusion/ej2-pivotview/src/pivotview/base/pivotview.js.PivotView.executeQuery (pivotview.js:1938)
at resolvePromise (zone.js:831)
at zone.js:896
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:423)
at Object.onInvokeTask (core.js:17290)
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:422)
at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:195)
at drainMicroTaskQueue (zone.js:601)
at ZoneTask.push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask [as invoke] (zone.js:502)
at invokeTask (zone.js:1744)
at XMLHttpRequest.globalZoneAwareCallback (zone.js:1770)
The weird thing about this, is that if I use a subset of the data that is coming back from the server and set it locally, it all works.
Here is an image of the request that I am making with the response and the data. I'm not sure if this is something that I can fix as this may be a bug with the DataManager.
I have tried reverting back to the previous version that I used, but there still seems to be the same problem.
We are glad to announce that our Essential Studio 2019 Volume 2 Beta Release version 17.2.0.28 is rolled out with the mentioned issue fix and is available for download under the following link.
https://www.syncfusion.com/forums/145548/essential-studio-2019-volume-2-beta-release-v17-2-0-28-is-available-for-download
Note: This issue fix will be included in our main release as well which is expected to be available by mid of July 2019.
We thank you for your support and appreciate your patience in waiting for this release. Please get in touch with us if you would require any further assistance.
Regards,
Dinesh Babu Yadav
I have a Users model stored in MongoDb and a UserTypes model stored in MySQL.
When I try to create a new User:
Users.create({name: "Shivam", userType: 1})
I get following error:
{ AdapterError: Unexpected error from database adapter: Invalid replacement foreign key value provided for association (`userType`). Cannot interpret `1` as a Mongo id.
(Usually, this is the result of a bug in application logic.)
For more info on Mongo ids, see:
• https://docs.mongodb.com/manual/reference/bson-types/#objectid
• http://sailsjs.com/support
at _afterPotentiallyFinding (/My_Project_Root//node_modules/waterline/lib/waterline/methods/find-or-create.js:258:17)
at _afterPotentiallyRunningAfterLC (/My_Project_Root//node_modules/waterline/lib/waterline/methods/find-one.js:328:20)
at _maybeRunAfterLC (/My_Project_Root//node_modules/waterline/lib/waterline/methods/find-one.js:322:20)
at _afterFetchingRecords (/My_Project_Root//node_modules/waterline/lib/waterline/methods/find-one.js:324:13)
at _afterGettingPopulatedPhysicalRecords (/My_Project_Root//node_modules/waterline/lib/waterline/utils/query/help-find.js:754:12)
at /My_Project_Root//node_modules/waterline/lib/waterline/utils/query/help-find.js:151:16
at Object.success (/My_Project_Root//node_modules/sails-mongo/lib/private/do-with-connection.js:254:18)
at /My_Project_Root//node_modules/machine/lib/private/help-build-machine.js:1354:30
at _tryToRunCb (/My_Project_Root//node_modules/parley/lib/private/Deferred.js:542:20)
at /My_Project_Root//node_modules/parley/lib/private/Deferred.js:755:16
at /My_Project_Root//node_modules/machine/lib/private/help-build-machine.js:966:24
at Function.handlerCbs.success (/My_Project_Root//node_modules/machine/lib/private/help-build-machine.js:826:26)
at Object.fn (/My_Project_Root//node_modules/sails-mongo/lib/private/machines/release-connection.js:77:18)
at wrapper (/My_Project_Root//node_modules/#sailshq/lodash/lib/index.js:3275:19)
at Deferred.parley.now.flaverr.name [as _handleExec] (/My_Project_Root//node_modules/machine/lib/private/help-build-machine.js:1068:17)
at Deferred.exec (/My_Project_Root//node_modules/parley/lib/private/Deferred.js:679:10)
at Deferred.switch (/My_Project_Root//node_modules/machine/lib/private/help-build-machine.js:1306:16)
at /My_Project_Root//node_modules/sails-mongo/lib/private/do-with-connection.js:242:92
at /My_Project_Root//node_modules/sails-mongo/lib/private/do-with-connection.js:123:18
at Object.success (/My_Project_Root//node_modules/sails-mongo/lib/private/build-std-adapter-method.js:61:47)
at /My_Project_Root//node_modules/machine/lib/private/help-build-machine.js:1354:30
at _tryToRunCb (/My_Project_Root//node_modules/parley/lib/private/Deferred.js:520:18)
cause:
{ AdapterError: Unexpected error from database adapter: Invalid replacement foreign key value provided for association (`userType`). Cannot interpret `1` as a Mongo id.
(Usually, this is the result of a bug in application logic.)
For more info on Mongo ids, see:
• https://docs.mongodb.com/manual/reference/bson-types/#objectid
• http://sailsjs.com/support
at _afterPotentiallyFinding (/My_Project_Root//node_modules/waterline/lib/waterline/methods/find-or-create.js:258:17)
at _afterPotentiallyRunningAfterLC (/My_Project_Root//node_modules/waterline/lib/waterline/methods/find-one.js:328:20)
at _maybeRunAfterLC (/My_Project_Root//node_modules/waterline/lib/waterline/methods/find-one.js:322:20)
at _afterFetchingRecords (/My_Project_Root//node_modules/waterline/lib/waterline/methods/find-one.js:324:13)
at _afterGettingPopulatedPhysicalRecords (/My_Project_Root//node_modules/waterline/lib/waterline/utils/query/help-find.js:754:12)
at /My_Project_Root//node_modules/waterline/lib/waterline/utils/query/help-find.js:151:16
at Object.success (/My_Project_Root//node_modules/sails-mongo/lib/private/do-with-connection.js:254:18)
at /My_Project_Root//node_modules/machine/lib/private/help-build-machine.js:1354:30
at _tryToRunCb (/My_Project_Root//node_modules/parley/lib/private/Deferred.js:542:20)
at /My_Project_Root//node_modules/parley/lib/private/Deferred.js:755:16
at /My_Project_Root//node_modules/machine/lib/private/help-build-machine.js:966:24
at Function.handlerCbs.success (/My_Project_Root//node_modules/machine/lib/private/help-build-machine.js:826:26)
at Object.fn (/My_Project_Root//node_modules/sails-mongo/lib/private/machines/release-connection.js:77:18)
at wrapper (/My_Project_Root//node_modules/#sailshq/lodash/lib/index.js:3275:19)
at Deferred.parley.now.flaverr.name [as _handleExec] (/My_Project_Root//node_modules/machine/lib/private/help-build-machine.js:1068:17)
at Deferred.exec (/My_Project_Root//node_modules/parley/lib/private/Deferred.js:679:10)
at Deferred.switch (/My_Project_Root//node_modules/machine/lib/private/help-build-machine.js:1306:16)
at /My_Project_Root//node_modules/sails-mongo/lib/private/do-with-connection.js:242:92
at /My_Project_Root//node_modules/sails-mongo/lib/private/do-with-connection.js:123:18
at Object.success (/My_Project_Root//node_modules/sails-mongo/lib/private/build-std-adapter-method.js:61:47)
at /My_Project_Root//node_modules/machine/lib/private/help-build-machine.js:1354:30
at _tryToRunCb (/My_Project_Root//node_modules/parley/lib/private/Deferred.js:520:18)
name: 'AdapterError',
adapterMethodName: 'create',
modelIdentity: 'users',
raw:
{ Error: Invalid replacement foreign key value provided for association (`userType`). Cannot interpret `1` as a Mongo id.
(Usually, this is the result of a bug in application logic.)
For more info on Mongo ids, see:
• https://docs.mongodb.com/manual/reference/bson-types/#objectid
• http://sailsjs.com/support
at /My_Project_Root//node_modules/sails-mongo/lib/private/machines/private/reify-values-to-set.js:95:35
at /My_Project_Root//node_modules/#sailshq/lodash/lib/index.js:3253:15
at baseForOwn (/My_Project_Root//node_modules/#sailshq/lodash/lib/index.js:2223:14)
at /My_Project_Root//node_modules/#sailshq/lodash/lib/index.js:3223:18
at Function.<anonymous> (/My_Project_Root//node_modules/#sailshq/lodash/lib/index.js:3526:13)
at reifyValuesToSet (/My_Project_Root//node_modules/sails-mongo/lib/private/machines/private/reify-values-to-set.js:68:5)
at Object.fn (/My_Project_Root//node_modules/sails-mongo/lib/private/machines/create-record.js:58:7)
at wrapper (/My_Project_Root//node_modules/#sailshq/lodash/lib/index.js:3275:19)
at Deferred.parley.now.flaverr.name [as _handleExec] (/My_Project_Root//node_modules/machine/lib/private/help-build-machine.js:1068:17)
at Deferred.exec (/My_Project_Root//node_modules/parley/lib/private/Deferred.js:679:10)
at Deferred.switch (/My_Project_Root//node_modules/machine/lib/private/help-build-machine.js:1306:16)
at Object.during (/My_Project_Root//node_modules/sails-mongo/lib/private/build-std-adapter-method.js:74:18)
at _makeCallToDuringFn (/My_Project_Root//node_modules/sails-mongo/lib/private/do-with-connection.js:109:17)
at /My_Project_Root//node_modules/sails-mongo/lib/private/do-with-connection.js:128:7
at Object.success (/My_Project_Root//node_modules/sails-mongo/lib/private/do-with-connection.js:91:16)
at /My_Project_Root//node_modules/machine/lib/private/help-build-machine.js:1354:30
at _tryToRunCb (/My_Project_Root//node_modules/parley/lib/private/Deferred.js:542:20)
at /My_Project_Root//node_modules/parley/lib/private/Deferred.js:755:16
at /My_Project_Root//node_modules/machine/lib/private/help-build-machine.js:966:24
at Function.handlerCbs.success (/My_Project_Root//node_modules/machine/lib/private/help-build-machine.js:826:26)
at Object.fn (/My_Project_Root//node_modules/sails-mongo/lib/private/machines/get-connection.js:61:18)
at wrapper (/My_Project_Root//node_modules/#sailshq/lodash/lib/index.js:3275:19) code: 'E_CANNOT_INTERPRET_AS_OBJECTID' } },
isOperational: true,
adapterMethodName: 'create',
modelIdentity: 'users',
raw:
{ Error: Invalid replacement foreign key value provided for association (`userType`). Cannot interpret `1` as a Mongo id.
(Usually, this is the result of a bug in application logic.)
For more info on Mongo ids, see:
• https://docs.mongodb.com/manual/reference/bson-types/#objectid
• http://sailsjs.com/support
at /My_Project_Root//node_modules/sails-mongo/lib/private/machines/private/reify-values-to-set.js:95:35
at /My_Project_Root//node_modules/#sailshq/lodash/lib/index.js:3253:15
at baseForOwn (/My_Project_Root//node_modules/#sailshq/lodash/lib/index.js:2223:14)
at /My_Project_Root//node_modules/#sailshq/lodash/lib/index.js:3223:18
at Function.<anonymous> (/My_Project_Root//node_modules/#sailshq/lodash/lib/index.js:3526:13)
at reifyValuesToSet (/My_Project_Root//node_modules/sails-mongo/lib/private/machines/private/reify-values-to-set.js:68:5)
at Object.fn (/My_Project_Root//node_modules/sails-mongo/lib/private/machines/create-record.js:58:7)
at wrapper (/My_Project_Root//node_modules/#sailshq/lodash/lib/index.js:3275:19)
at Deferred.parley.now.flaverr.name [as _handleExec] (/My_Project_Root//node_modules/machine/lib/private/help-build-machine.js:1068:17)
at Deferred.exec (/My_Project_Root//node_modules/parley/lib/private/Deferred.js:679:10)
at Deferred.switch (/My_Project_Root//node_modules/machine/lib/private/help-build-machine.js:1306:16)
at Object.during (/My_Project_Root//node_modules/sails-mongo/lib/private/build-std-adapter-method.js:74:18)
at _makeCallToDuringFn (/My_Project_Root//node_modules/sails-mongo/lib/private/do-with-connection.js:109:17)
at /My_Project_Root//node_modules/sails-mongo/lib/private/do-with-connection.js:128:7
at Object.success (/My_Project_Root//node_modules/sails-mongo/lib/private/do-with-connection.js:91:16)
at /My_Project_Root//node_modules/machine/lib/private/help-build-machine.js:1354:30
at _tryToRunCb (/My_Project_Root//node_modules/parley/lib/private/Deferred.js:542:20)
at /My_Project_Root//node_modules/parley/lib/private/Deferred.js:755:16
at /My_Project_Root//node_modules/machine/lib/private/help-build-machine.js:966:24
at Function.handlerCbs.success (/My_Project_Root//node_modules/machine/lib/private/help-build-machine.js:826:26)
at Object.fn (/My_Project_Root//node_modules/sails-mongo/lib/private/machines/get-connection.js:61:18)
at wrapper (/My_Project_Root//node_modules/#sailshq/lodash/lib/index.js:3275:19)
code: 'E_CANNOT_INTERPRET_AS_OBJECTID' } }
However, .populate() works just fine:
Users.findOne('USER_ID_HERE').populate('userType')
yields the following result:
{
id: "USER_ID_HERE",
name: "Shivam",
userType: {
id: 1,
label: "Student"
}
}
Here are my Models:
Users.js:
module.exports = {
datastore: 'mongoDb',
attributes: {
id: {type: 'string', columnName: '_id', required: false},
name: {
type: 'string',
required: false,
allowNull: true,
maxLength: 50,
minLength: 3
},
userType: {model: 'usertypes', required: true},
}
};
and UserTypes.js:
module.exports = {
datastore: 'default',
attributes: {
id: {type: 'number', autoIncrement: true},
label: {
type: 'string',
maxLength: 255,
required: true,
unique: true
},
createdAt: false,
updatedAt: false,
users: {collection: 'users', via: 'userType'}
}
};
where default datastore is MySQL and mongoDb datastore is MongoDb.
Here is the version info:
Version Info:
: Sails : v1.0.2
: node : v8.1.2
: engine (v8) : 5.8.283.41
: openssl : 1.0.2l
: sails-mongo : ^1.0.1
: sails-mysql : ^1.0.0
: sails-hook-orm : ^2.0.0-16
What am I doing wrong?
For others experiencing the same issue, here is a hotfix:
Set dontUseObjectIds: true for all models using MySQL adapter.
This seems to trick the sails-mongo adapter to not check for ObjectIds for Foreign Keys to Models using sails-mysql Adapter.
Please note that this is NOT a proper solution, but just a workaround.
i'm working on a RESTful API using swagger-api and swagger-editor for routes.
I can't figure out why the JSON i am sending through body, never reaches my controller.
here is my YAML
schemes:
- http
- https
produces: [application/json, multipart/form-data, application/x-www-form-urlencoded]
paths:
/projects:
x-swagger-router-controller: project
post:
description: create a new project
operationId: postProjects
consumes:
- application/json
parameters:
- name: param1
in: body
description: description
required: false
schema:
$ref: "#/definitions/Project"
responses:
"200":
description: Success
schema:
$ref: "#/definitions/Project"
default:
description: Error
schema:
$ref: "#/definitions/ErrorResponse"
definitions:
Project:
properties:
name:
type: string
required:
- name
an example of the post request i'm sending.
curl -v -X POST -H "Content-Type: application/json" -d '{"name":"test"}' http://127.0.0.1:10010/projects
and the response
{"message":"Request validation failed: Parameter (param1) failed schema validation","code":"SCHEMA_VALIDATION_FAILED","failedValidation":true,"results":{"errors":[{"code":"OBJECT_MISSING_REQUIRED_PROPERTY","message":"Missing required property: name","path":[]}],"warnings":[]},"path":["paths","/projects","post","parameters","0"],"paramName":"param1"}
If i set the parameter "name" as not required, i just received an empty response like this
{ param1:
{ path: [ 'paths', '/projects', 'post', 'parameters', '0' ],
schema:
{ name: 'param1',
in: 'body',
description: 'description',
required: false,
schema: [Object] },
originalValue: {},
value: {} } }
I have no clue why since other format such as header, path or formdata works fine.
I always receive an empty object. req.swagger.params has no value.
I tried several schema but even the simplest is not working.
i can tell from the header that 'content-type': 'application/json'.
So the content type is set, the schema validates a simple string argument named "name". Everything should be ok. but still not.
This issue has been fixed.
It wasn't swagger related.
I built an API with nodeJs and i realized i didn't have a middleware to handle body parameter.
So because i missed a step before enabled the swagger middleware, i couldn't do anything with body parameter.
The main reason behind getting null values when sending json data to the API backend is the paramater path most of the time you give and the naming you give the parameter.
You also have to declare explicitly the type of schema you expect
You have to set parameter name to body and set in: body so that it picks the body object as a JSON
An example is here. You can try it out
/auth/register:
post:
tags:
- Auth
parameters:
- in: body
name: user
description: Create a new user.
schema:
type: object
required:
- firstName
- lastName
- email
- password
- confirmPassword
properties:
firstName:
type: string
lastName:
type: string
email:
type: string
password:
type: string
confirmPassword:
type: string
example:
firstName: Jane
lastName: Doe
email: janedoe#gmail.com
password: pass
confirmPassword: pass
responses:
"200":
description: OK
I try to specify the response from GET method with Swagger Editor.
But when I look in Swagger UI, the response JSON doesn't show.
My declaration swagger :
/clients/{id}:
get:
consumes:
- application/hal+json
produces:
- application/hal+json
# This is array of GET operation parameters:
parameters:
# An example parameter that is in query and is required
- name: id
in: path
required: true
type: string
# Expected responses for this operation:
responses:
# Response code
200:
description: Succes
# A schema describing your response object.
# Use JSON Schema format
schema:
example:
application/json: |
- {"produits":[{"idOffre":{"codeBanque":"038","identifiant":"123"},"idProduit":{"codeBanque":"061","identifiant":"123"}},{"idOffre":{"code":"038","identifiant":"123"},"idProduit":{"code":"061","identifiant":"123"}}]}
.....
In Swagger UI , the box where is written Response Class (Status 200) > Model Schema there is an empty json like that -> {}
I'm not sure swagger-ui supports examples, however I fixed some errors in you swagger extract:
example renamed examples
examples at same indentation level as schema (in you example, example is processed as a property of the response schema, I'm not sure this is what you want)
schema must describe response model, complete TODO
Fixed version:
swagger: '2.0'
info:
title: Clients
description: API
version: "1.0.0"
host: api.test.com
schemes:
- https
basePath: /v1
produces:
- application/json
paths:
/clients/{id}:
get:
consumes:
- application/hal+json
produces:
- application/hal+json
parameters:
- name: id
in: path
required: true
type: string
responses:
200:
description: Succes
schema:
type: array
items:
properties:
produits:
type: string
description: TODO
examples:
application/json: |
- {"produits":[{"idOffre":{"codeBanque":"038","identifiant":"123"},"idProduit":{"codeBanque":"061","identifiant":"123"}},{"idOffre":{"code":"038","identifiant":"123"},"idProduit":{"code":"061","identifiant":"123"}}]}