Add create flavor json schema check

Change-Id: I02e6dbf65c4b08c71d48aa0d342ea2758c39f060
This commit is contained in:
Zhenguo Niu 2017-05-09 20:04:07 +08:00
parent 164ca9844e
commit c9f1727dd7
5 changed files with 43 additions and 11 deletions

View File

@ -68,7 +68,6 @@ Request
- name: flavor_name
- description: flavor_description
- is_public: flavor_is_public_not_required
- uuid: flavor_uuid_not_required
**Example Create Flavor**

View File

@ -173,7 +173,7 @@ flavor_is_public_not_required:
Whether the flavor is public (available to all projects) or scoped
to a set of projects. Default is True if not specified.
in: body
required: true
required: false
type: boolean
flavor_name:
description: |
@ -187,12 +187,6 @@ flavor_uuid:
in: body
required: true
type: string
flavor_uuid_not_required:
description: |
The UUID of the flavor.
in: body
required: false
type: string
flavorRef:
description: |
The flavor reference, as a UUID for the flavor for your server server.

View File

@ -21,6 +21,7 @@ from wsme import types as wtypes
from mogan.api.controllers import base
from mogan.api.controllers import link
from mogan.api.controllers.v1.schemas import flavor as flavor_schema
from mogan.api.controllers.v1.schemas import flavor_access
from mogan.api.controllers.v1 import types
from mogan.api import expose
@ -227,15 +228,15 @@ class FlavorsController(rest.RestController):
return Flavor.convert_with_links(rpc_flavor)
@policy.authorize_wsgi("mogan:flavor", "create")
@expose.expose(Flavor, body=Flavor,
@expose.expose(Flavor, body=types.jsontype,
status_code=http_client.CREATED)
def post(self, flavor):
"""Create an new flavor.
:param flavor: a flavor within the request body.
"""
new_flavor = objects.Flavor(pecan.request.context,
**flavor.as_dict())
validation.check_schema(flavor, flavor_schema.create_flavor)
new_flavor = objects.Flavor(pecan.request.context, **flavor)
new_flavor.create()
# Set the HTTP Location Header
pecan.response.location = link.build_url('flavors',

View File

@ -0,0 +1,29 @@
# Copyright 2017 Huawei Technologies Co.,LTD.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from mogan.api.validation import parameter_types
create_flavor = {
"type": "object",
"properties": {
'name': parameter_types.name,
'description': parameter_types.description,
'is_public': parameter_types.boolean,
},
'required': ['name', 'description'],
'additionalProperties': False,
}

View File

@ -97,3 +97,12 @@ personality = {
'additionalProperties': False,
}
}
boolean = {
'type': ['boolean', 'string'],
'enum': [True, 'True', 'TRUE', 'true', '1', 'ON', 'On', 'on',
'YES', 'Yes', 'yes',
False, 'False', 'FALSE', 'false', '0', 'OFF', 'Off', 'off',
'NO', 'No', 'no'],
}