Created
April 25, 2017 19:54
-
-
Save lbragstad/6eca287b684bc34da6908ce1afdee03f to your computer and use it in GitHub Desktop.
Keystone API Validation using JSD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
endpoint_schema = Endpoint(required=True) | |
resource_to_validate = endpoint_schema.__class__.__name__.lower() | |
@validation.validated(endpoint_schema.json(), resource_to_validate) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
endpoint_schema = Endpoint(required=True) | |
@validation.validated(endpoint_schema) # validation handles calling .json() | |
# and figuring out the class name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"additionalProperties": true, | |
"properties": { | |
"description": { | |
"type": [ | |
"string", | |
"null" | |
] | |
}, | |
"domain_id": { | |
"maxLength": 64, | |
"minLength": 1, | |
"pattern": "^[a-zA-Z0-9-]+$", | |
"type": "string" | |
}, | |
"enabled": { | |
"enum": [ | |
true, | |
false | |
], | |
"type": "boolean" | |
}, | |
"name": { | |
"maxLength": 64, | |
"minLength": 1, | |
"type": "string" | |
} | |
}, | |
"required": [ | |
"name" | |
], | |
"type": "object" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import jsd | |
class Project(jsd.Object): | |
description = jsd.String() | |
domain_id = jsd.String() | |
enabled = jsd.Boolean() | |
name = jsd.String(required=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"properties": { | |
"description": { | |
"type": [ | |
"string", | |
"null" | |
] | |
}, | |
"domain_id": { | |
"type": [ | |
"string", | |
"null" | |
] | |
}, | |
"enabled": { | |
"type": [ | |
"boolean", | |
"null" | |
] | |
}, | |
"name": { | |
"type": "string" | |
} | |
}, | |
"required": [ | |
"name" | |
], | |
"type": "object" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"additionalProperties": true, | |
"minProperties": 1, | |
"properties": { | |
"description": { | |
"type": [ | |
"string", | |
"null" | |
] | |
}, | |
"domain_id": { | |
"maxLength": 64, | |
"minLength": 1, | |
"pattern": "^[a-zA-Z0-9-]+$", | |
"type": "string" | |
}, | |
"enabled": { | |
"enum": [ | |
true, | |
false | |
], | |
"type": "boolean" | |
}, | |
"name": { | |
"maxLength": 64, | |
"minLength": 1, | |
"type": "string" | |
} | |
}, | |
"type": "object" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import jsd | |
class Url(jsd.String): | |
min_length = 0 | |
max_length = 255 | |
pattern = '^[a-zA-Z0-9-]+$' | |
class Endpoint(jsd.Object): | |
enabled = jsd.Boolean() | |
interface = jsd.String(required=True) | |
region_id = jsd.String() | |
service_id = jsd.String(required=True) | |
url = Url(required=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import jsd | |
class Url(jsd.String): | |
min_length = 0 | |
max_length = 255 | |
pattern = '^[a-zA-Z0-9-]+$' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
url = { | |
'type': 'string', | |
'minLength': 0, | |
'maxLength': 225, | |
'pattern': '^[a-zA-Z0-9-]+$' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment