Improve the api versioning

- Don't use the project version for the API, but
  the actual API version (just v1 defined now).
- Change the return type to a list of versions (we can't be
  that optimistic).

blueprint api
Change-Id: Icb8c0c91798cf4eb1e10b39040e123119e859d10
This commit is contained in:
Angus Salkeld 2013-11-18 11:03:21 +11:00
parent 8cd2ffb226
commit 3fec56d204
2 changed files with 44 additions and 6 deletions

View File

@ -14,20 +14,56 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import pecan
from wsme import types as wtypes from wsme import types as wtypes
import wsmeext.pecan as wsme_pecan import wsmeext.pecan as wsme_pecan
from solum import version
STATUS_KIND = wtypes.Enum(str, 'SUPPORTED', 'CURRENT', 'DEPRECATED')
class Link(wtypes.Base):
"""A link representation."""
href = wtypes.text
"The link url"
targetName = wtypes.text
"Textual name of the target link"
@classmethod
def sample(cls):
return cls(href=('http://localhost:9777/v1'),
targetName='v1')
class Version(wtypes.Base): class Version(wtypes.Base):
"""Version representation.""" """Version representation."""
version = wtypes.text id = wtypes.text
"The version identifier"
status = STATUS_KIND
"The status of the API (SUPPORTED, CURRENT or DEPRECATED)"
link = Link
"The link to the versioned API"
@classmethod
def sample(cls):
return cls(id='v1.0',
status='CURRENT',
link=Link(targetName='v1',
href='http://localhost:9777/v1'))
class RootController(object): class RootController(object):
@wsme_pecan.wsexpose(Version) @wsme_pecan.wsexpose([Version])
def index(self): def index(self):
return Version(version=version.version_string()) host_url = '%s/%s' % (pecan.request.host_url, 'v1')
v1 = Version(id='v1.0',
status='CURRENT',
link=Link(targetName='v1',
href=host_url))
return [v1]

View File

@ -16,7 +16,6 @@
from solum.openstack.common import jsonutils from solum.openstack.common import jsonutils
from solum.tests.api import base from solum.tests.api import base
from solum import version
class TestRootController(base.FunctionalTest): class TestRootController(base.FunctionalTest):
@ -25,4 +24,7 @@ class TestRootController(base.FunctionalTest):
response = self.app.get('/', headers={'Accept': 'application/json'}) response = self.app.get('/', headers={'Accept': 'application/json'})
self.assertEqual(response.status_int, 200) self.assertEqual(response.status_int, 200)
data = jsonutils.loads(response.body) data = jsonutils.loads(response.body)
self.assertEqual(data['version'], version.version_string()) self.assertEqual(data[0]['id'], 'v1.0')
self.assertEqual(data[0]['status'], 'CURRENT')
self.assertEqual(data[0]['link'], {'href': 'http://localhost/v1',
'targetName': 'v1'})