Hello,

I started writing a gocd plugin and I'm writing unit tests based on the 
provided json schema in the developer.gocd.io for the messages I will send 
to gocd server.

In order to validate messages, I'm 
using https://github.com/networknt/json-schema-validator.

Based on this validator, it seems that samples are not correct. For 
examples, 
in 
https://developer.gocd.io/17.5.0/writing_go_plugins/package_material/version_1_0/repository_configuration.html

Here is the sample object:

{
    "REPO_URL": {
        "display-name": "Repository URL",
        "display-order": "0"
    },
    "USERNAME": {
        "part-of-identity": false,
        "required": false,
        "display-name": "User",
        "display-order": "1"
    },
    "PASSWORD": {
        "secure": true,
        "part-of-identity": false,
        "required": false,
        "display-name": "Password",
        "display-order": "2"
    }
}


and Here is the provided schema:

{
    "title": "Repository configuration response schema",
    "description": "Schema for repository configuration response json",
    "type": "object",
    "patternProperties": {
        "^[a-zA-Z0-9_-]+$": {
            "type": [
                "object",
                "null"
            ],
            "properties": {
                "default-value": {
                    "type": "string",
                    "required": false,
                    "default": "",
                    "pattern": "^[a-zA-Z0-9_-]+$"
                },
                "secure": {
                    "type": "boolean",
                    "required": false,
                    "default": false,
                },
                "part-of-identity": {
                    "type": "boolean",
                    "required": false,
                    "default": true,
                },
                "required": {
                    "type": "boolean",
                    "required": false,
                    "default": true
                },
                "display-name": {
                    "type": "string",
                    "required": false,
                    "pattern": "^[a-zA-Z0-9_-]+$"
                },
                "display-order": {
                    "type": "string",
                    "required": false,
                    "pattern": "^[0-9]+$"
                }
            },
            "additionalProperties": false
        }
    },
    "additionalProperties": false
}

Here are my issues:
* display-name pattern is '^[a-zA-Z0-9_-]+$' I think it should allow space 
character too (the sample json won't work and I think Gocd server allow spaces 
in display name)
* I'm not sure if it valid or not but sometimes your last property in the 
schema end with a comma. Most validator won't accept it and you should remove 
these commas like in secure.default

Documentation contains a lot of theses "typos". As you are using a json API, 
schemas and samples should be correct. I found a pr about it 
"https://github.com/gocd/developer.go.cd/pull/22"; that has been closed because 
of a migration to https://plugin-api.go.cd but there is still no documentation 
about package repositories plugin in there.

Json schema allows us to validate our messages via unit tests.

For the moment I'm going to fix the schemas in my code to validate your samples 
json as I think they are coming from existing plugins.

When do you plan to integrate documentations about plugins with json schemas in 
https://plugin-api.go.cd ?

Thanks,

Avit

-- 
You received this message because you are subscribed to the Google Groups 
"go-cd" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to