You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently you cannot create a contract with a method in which all arguments are optional. Instead you get an error when creating the chaincode as the reflected metadata doesn't produce a valid JSON schema. This is because there are some components with an empty required field, whereas draft-04 of the JSON schema specifies all required fields must contain at least 1 value (so if all fields are optional the required field should be omitted entirely instead),
panic: cannot use metadata. Metadata did not match schema:
1. components.schemas.Args.required: Array must have at least 1 items
I think the issue here is that:
the contract schema is generated through reflection and includes an empty array ("required:" []) i.e. all fields are optional.
the version of JSON schema used via packr (see metadata/schema/schema.json) has "objecttype.properties.required.$ref": "http://json-schema.org/draft-04/schema#/definitions/stringArray"
and in draft-04 stringArray's had to have a minimum length of 1.
I think this can probably be fixed in a number of ways...
We could add omitempty to the JSON tag of the required field in metadata.ObjectMetadata so that if there are no required fields then the required field isn't included (to match draft-04 of the spec). I think this should just be a 1 word fix and mean that the generated contract schema is correct as per draft-04 schemas.
Or we change which draft is used to a later version (which allows for empty required lists), i.e. explicitly saying all fields are optional. Not sure what other changes have been made since draft-04 though, so I can't say if this would have other effects or not.
The text was updated successfully, but these errors were encountered:
Currently you cannot create a contract with a method in which all arguments are optional. Instead you get an error when creating the chaincode as the reflected metadata doesn't produce a valid JSON schema. This is because there are some components with an empty
required
field, whereas draft-04 of the JSON schema specifies all required fields must contain at least 1 value (so if all fields are optional the required field should be omitted entirely instead),Example:
Will give:
I think the issue here is that:
"required:" []
) i.e. all fields are optional.packr
(seemetadata/schema/schema.json
) has"objecttype.properties.required.$ref": "http://json-schema.org/draft-04/schema#/definitions/stringArray"
I think this can probably be fixed in a number of ways...
omitempty
to the JSON tag of therequired
field inmetadata.ObjectMetadata
so that if there are no required fields then therequired
field isn't included (to match draft-04 of the spec). I think this should just be a 1 word fix and mean that the generated contract schema is correct as per draft-04 schemas.required
lists), i.e. explicitly saying all fields are optional. Not sure what other changes have been made since draft-04 though, so I can't say if this would have other effects or not.The text was updated successfully, but these errors were encountered: