Support both TPR and CRD with custom objects spec

This commit is contained in:
mbohlool
2017-07-06 13:48:05 -07:00
parent 0400ed23f3
commit d74ec595ae
3 changed files with 569 additions and 243 deletions

View File

@@ -0,0 +1,560 @@
{
"/apis/{group}/{version}/{plural}": {
"parameters": [
{
"uniqueItems": true,
"type": "string",
"description": "If 'true', then the output is pretty printed.",
"name": "pretty",
"in": "query"
},
{
"name": "group",
"in": "path",
"required": true,
"description": "The custom resource's group name",
"type": "string"
},
{
"name": "version",
"in": "path",
"required": true,
"description": "The custom resource's version",
"type": "string"
},
{
"name": "plural",
"in": "path",
"required": true,
"description": "The custom resource's plural name. For TPRs this would be lowercase plural kind.",
"type": "string"
}
],
"get": {
"operationId": "listClusterCustomObject",
"description": "list or watch cluster scoped custom objects",
"tags": [
"custom_objects"
],
"consumes": [
"*/*"
],
"produces": [
"application/json",
"application/json;stream=watch"
],
"schemes": [
"https"
],
"parameters": [
{
"uniqueItems": true,
"type": "string",
"description": "A selector to restrict the list of returned objects by their labels. Defaults to everything.",
"name": "labelSelector",
"in": "query"
},
{
"uniqueItems": true,
"type": "string",
"description": "When specified with a watch call, shows changes that occur after that particular version of a resource. Defaults to changes from the beginning of history. When specified for list: - if unset, then the result is returned from remote storage based on quorum-read flag; - if it's 0, then we simply return what we currently have in cache, no guarantee; - if set to non zero, then the result is at least as fresh as given rv.",
"name": "resourceVersion",
"in": "query"
},
{
"name": "watch",
"uniqueItems": true,
"type": "boolean",
"description": "Watch for changes to the described resources and return them as a stream of add, update, and remove notifications.",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "object"
}
},
"401": {
"description": "Unauthorized"
}
}
},
"post": {
"operationId": "createClusterCustomObject",
"description": "Creates a cluster scoped Custom object",
"produces": [
"application/json"
],
"schemes": [
"https"
],
"tags": [
"custom_objects"
],
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"description": "The JSON schema of the Resource to create.",
"schema": {
"type": "object"
}
}
],
"responses": {
"201": {
"schema": {
"type": "object"
}
},
"401": {
"description": "Unauthorized"
}
}
}
},
"/apis/{group}/{version}/namespaces/{namespace}/{plural}": {
"parameters": [
{
"uniqueItems": true,
"type": "string",
"description": "If 'true', then the output is pretty printed.",
"name": "pretty",
"in": "query"
},
{
"name": "group",
"in": "path",
"required": true,
"description": "The custom resource's group name",
"type": "string"
},
{
"name": "version",
"in": "path",
"required": true,
"description": "The custom resource's version",
"type": "string"
},
{
"name": "namespace",
"in": "path",
"required": true,
"description": "The custom resource's namespace",
"type": "string"
},
{
"name": "plural",
"in": "path",
"required": true,
"description": "The custom resource's plural name. For TPRs this would be lowercase plural kind.",
"type": "string"
}
],
"get": {
"operationId": "listNamespacedCustomObject",
"description": "list or watch namespace scoped custom objects",
"tags": [
"custom_objects"
],
"consumes": [
"*/*"
],
"produces": [
"application/json",
"application/json;stream=watch"
],
"schemes": [
"https"
],
"parameters": [
{
"uniqueItems": true,
"type": "string",
"description": "A selector to restrict the list of returned objects by their labels. Defaults to everything.",
"name": "labelSelector",
"in": "query"
},
{
"uniqueItems": true,
"type": "string",
"description": "When specified with a watch call, shows changes that occur after that particular version of a resource. Defaults to changes from the beginning of history. When specified for list: - if unset, then the result is returned from remote storage based on quorum-read flag; - if it's 0, then we simply return what we currently have in cache, no guarantee; - if set to non zero, then the result is at least as fresh as given rv.",
"name": "resourceVersion",
"in": "query"
},
{
"name": "watch",
"uniqueItems": true,
"type": "boolean",
"description": "Watch for changes to the described resources and return them as a stream of add, update, and remove notifications.",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "object"
}
},
"401": {
"description": "Unauthorized"
}
}
},
"post": {
"operationId": "createNamespacedCustomObject",
"description": "Creates a namespace scoped Custom object",
"produces": [
"application/json"
],
"schemes": [
"https"
],
"tags": [
"custom_objects"
],
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"description": "The JSON schema of the Resource to create.",
"schema": {
"type": "object"
}
}
],
"responses": {
"201": {
"schema": {
"type": "object"
}
},
"401": {
"description": "Unauthorized"
}
}
}
},
"/apis/{group}/{version}/{plural}/{name}": {
"parameters": [
{
"name": "group",
"in": "path",
"required": true,
"description": "the custom resource's group",
"type": "string"
},
{
"name": "version",
"in": "path",
"required": true,
"description": "the custom resource's version",
"type": "string"
},
{
"name": "plural",
"in": "path",
"required": true,
"description": "the custom object's plural name. For TPRs this would be lowercase plural kind.",
"type": "string"
},
{
"name": "name",
"in": "path",
"required": true,
"description": "the custom object's name",
"type": "string"
}
],
"get": {
"operationId": "getClusterCustomObject",
"description": "Returns a cluster scoped custom object",
"consumes": [
"*/*"
],
"produces": [
"application/json"
],
"schemes": [
"https"
],
"tags": [
"custom_objects"
],
"responses": {
"200": {
"description": "A single Resource",
"schema": {
"type": "object"
}
},
"401": {
"description": "Unauthorized"
}
}
},
"delete": {
"operationId": "deleteClusterCustomObject",
"description": "Deletes the specified cluster scoped custom object",
"consumes": [
"*/*"
],
"produces": [
"application/json"
],
"schemes": [
"https"
],
"tags": [
"custom_objects"
],
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/v1.DeleteOptions"
}
},
{
"name": "gracePeriodSeconds",
"uniqueItems": true,
"type": "integer",
"description": "The duration in seconds before the object should be deleted. Value must be non-negative integer. The value zero indicates delete immediately. If this value is nil, the default grace period for the specified type will be used. Defaults to a per object value if not specified. zero means delete immediately.",
"in": "query"
},
{
"name": "orphanDependents",
"uniqueItems": true,
"type": "boolean",
"description": "Deprecated: please use the PropagationPolicy, this field will be deprecated in 1.7. Should the dependent objects be orphaned. If true/false, the \"orphan\" finalizer will be added to/removed from the object's finalizers list. Either this field or PropagationPolicy may be set, but not both.",
"in": "query"
},
{
"name": "propagationPolicy",
"uniqueItems": true,
"type": "string",
"description": "Whether and how garbage collection will be performed. Either this field or OrphanDependents may be set, but not both. The default policy is decided by the existing finalizer set in the metadata.finalizers and the resource-specific default policy.",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "object"
}
},
"401": {
"description": "Unauthorized"
}
}
},
"put": {
"operationId": "replaceClusterCustomObject",
"description": "replace the specified cluster scoped custom object",
"consumes": [
"*/*"
],
"produces": [
"application/json"
],
"schemes": [
"https"
],
"tags": [
"custom_objects"
],
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"description": "The JSON schema of the Resource to replace.",
"schema": {
"type": "object"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "object"
}
},
"401": {
"description": "Unauthorized"
}
}
}
},
"/apis/{group}/{version}/namespaces/{namespace}/{plural}/{name}": {
"parameters": [
{
"name": "group",
"in": "path",
"required": true,
"description": "the custom resource's group",
"type": "string"
},
{
"name": "version",
"in": "path",
"required": true,
"description": "the custom resource's version",
"type": "string"
},
{
"name": "namespace",
"in": "path",
"required": true,
"description": "The custom resource's namespace",
"type": "string"
},
{
"name": "plural",
"in": "path",
"required": true,
"description": "the custom resource's plural name. For TPRs this would be lowercase plural kind.",
"type": "string"
},
{
"name": "name",
"in": "path",
"required": true,
"description": "the custom object's name",
"type": "string"
}
],
"get": {
"operationId": "getNamespacedCustomObject",
"description": "Returns a namespace scoped custom object",
"consumes": [
"*/*"
],
"produces": [
"application/json"
],
"schemes": [
"https"
],
"tags": [
"custom_objects"
],
"responses": {
"200": {
"description": "A single Resource",
"schema": {
"type": "object"
}
},
"401": {
"description": "Unauthorized"
}
}
},
"delete": {
"operationId": "deleteNamespacedCustomObject",
"description": "Deletes the specified namespace scoped custom object",
"consumes": [
"*/*"
],
"produces": [
"application/json"
],
"schemes": [
"https"
],
"tags": [
"custom_objects"
],
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/v1.DeleteOptions"
}
},
{
"name": "gracePeriodSeconds",
"uniqueItems": true,
"type": "integer",
"description": "The duration in seconds before the object should be deleted. Value must be non-negative integer. The value zero indicates delete immediately. If this value is nil, the default grace period for the specified type will be used. Defaults to a per object value if not specified. zero means delete immediately.",
"in": "query"
},
{
"name": "orphanDependents",
"uniqueItems": true,
"type": "boolean",
"description": "Deprecated: please use the PropagationPolicy, this field will be deprecated in 1.7. Should the dependent objects be orphaned. If true/false, the \"orphan\" finalizer will be added to/removed from the object's finalizers list. Either this field or PropagationPolicy may be set, but not both.",
"in": "query"
},
{
"name": "propagationPolicy",
"uniqueItems": true,
"type": "string",
"description": "Whether and how garbage collection will be performed. Either this field or OrphanDependents may be set, but not both. The default policy is decided by the existing finalizer set in the metadata.finalizers and the resource-specific default policy.",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "object"
}
},
"401": {
"description": "Unauthorized"
}
}
},
"put": {
"operationId": "replaceNamespacedCustomObject",
"description": "replace the specified namespace scoped custom object",
"consumes": [
"*/*"
],
"produces": [
"application/json"
],
"schemes": [
"https"
],
"tags": [
"custom_objects"
],
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"description": "The JSON schema of the Resource to replace.",
"schema": {
"type": "object"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "object"
}
},
"401": {
"description": "Unauthorized"
}
}
}
}
}

View File

@@ -27,7 +27,9 @@ WATCH_OP_SUFFIX = "List"
LIST_OP_PREFIX = "list"
WATCH_QUERY_PARAM_NAME = "watch"
TPR_SPEC_PATH = os.path.join(os.path.dirname(__file__), 'thirdpartypaths.json')
CUSTOM_OBJECTS_SPEC_PATH = os.path.join(
os.path.dirname(__file__),
'custom_objects_spec.json')
_ops = ['get', 'put', 'post', 'delete', 'options', 'head', 'patch']
@@ -97,17 +99,17 @@ def strip_tags_from_operation_id(operation, _):
operation['operationId'] = operation_id
def add_thirdparty_resource_paths(spec):
with open(TPR_SPEC_PATH, 'r') as third_party_spec_file:
third_party_spec = json.loads(third_party_spec_file.read())
for path in third_party_spec.keys():
def add_custom_objects_spec(spec):
with open(CUSTOM_OBJECTS_SPEC_PATH, 'r') as custom_objects_spec_file:
custom_objects_spec = json.loads(custom_objects_spec_file.read())
for path in custom_objects_spec.keys():
if path not in spec['paths'].keys():
spec['paths'][path] = third_party_spec[path]
spec['paths'][path] = custom_objects_spec[path]
return spec
def process_swagger(spec):
spec = add_thirdparty_resource_paths(spec)
spec = add_custom_objects_spec(spec)
apply_func_to_spec_operations(spec, strip_tags_from_operation_id)

View File

@@ -1,236 +0,0 @@
{
"/apis/{fqdn}/v1/{resource}": {
"get": {
"operationId": "listThirdPartyResource",
"summary": "Gets Resources",
"description": "Returns a list of Resources",
"tags": [
"third_party_resources"
],
"parameters": [
{
"name": "watch",
"uniqueItems": true,
"type": "boolean",
"description": "Watch for changes to the described resources and return them as a stream of add, update, and remove notifications. Specify resourceVersion.",
"in": "query"
},
{
"name": "fqdn",
"in": "path",
"required": true,
"description": "The Third party Resource fqdn",
"type": "string"
},
{
"name": "resource",
"in": "path",
"required": true,
"description": "The Resource type",
"type": "string"
}
],
"responses": {
"200": {
"description": "A list of Resources",
"schema": {
"type": "object"
}
}
}
}
},
"/apis/{fqdn}/v1/namespaces/{namespace}/{resource}": {
"post": {
"operationId": "createThirdPartyResource",
"summary": "Create a Resource",
"description": "Creates a third party resource of the type specified",
"tags": [
"third_party_resources"
],
"parameters": [
{
"name": "namespace",
"in": "path",
"required": true,
"description": "The Resource's namespace",
"type": "string"
},
{
"name": "fqdn",
"in": "path",
"required": true,
"description": "The Third party Resource fqdn",
"type": "string"
},
{
"name": "resource",
"in": "path",
"required": true,
"description": "The Resource type",
"type": "string"
},
{
"name": "body",
"in": "body",
"required": true,
"description": "The JSON schema of the Resource to create.",
"schema": {
"type": "object"
}
}
],
"responses": {
"201": {
"description": "A list of Resources",
"schema": {
"type": "object"
}
}
}
}
},
"/apis/{fqdn}/v1/namespaces/{namespace}/{resource}/{name}": {
"get": {
"operationId": "getThirdPartyResource",
"summary": "Gets a specific Resource",
"description": "Returns a specific Resource in a namespace",
"tags": [
"third_party_resources"
],
"parameters": [
{
"name": "namespace",
"in": "path",
"required": true,
"description": "The Resource's namespace",
"type": "string"
},
{
"name": "name",
"in": "path",
"required": true,
"description": "The Resource's name",
"type": "string"
},
{
"name": "fqdn",
"in": "path",
"required": true,
"description": "The Third party Resource fqdn",
"type": "string"
},
{
"name": "resource",
"in": "path",
"required": true,
"description": "The Resource type",
"type": "string"
}
],
"responses": {
"200": {
"description": "A single Resource",
"schema": {
"type": "object"
}
}
}
},
"delete": {
"operationId": "deleteThirdPartyResource",
"summary": "Deletes a specific Resource",
"description": "Deletes the specified Resource in the specified namespace",
"tags": [
"third_party_resources"
],
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/v1.DeleteOptions"
}
},
{
"name": "gracePeriodSeconds",
"uniqueItems": true,
"type": "integer",
"description": "The duration in seconds before the object should be deleted. Value must be non-negative integer. The value zero indicates delete immediately. If this value is nil, the default grace period for the specified type will be used. Defaults to a per object value if not specified. zero means delete immediately.",
"in": "query"
},
{
"name": "orphanDependents",
"uniqueItems": true,
"type": "boolean",
"description": "Deprecated: please use the PropagationPolicy, this field will be deprecated in 1.7. Should the dependent objects be orphaned. If true/false, the \"orphan\" finalizer will be added to/removed from the object's finalizers list. Either this field or PropagationPolicy may be set, but not both.",
"in": "query"
},
{
"name": "propagationPolicy",
"uniqueItems": true,
"type": "string",
"description": "Whether and how garbage collection will be performed. Either this field or OrphanDependents may be set, but not both. The default policy is decided by the existing finalizer set in the metadata.finalizers and the resource-specific default policy.",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "object"
}
}
}
},
"put": {
"operationId": "updateThirdPartyResource",
"summary": "Update a Resource",
"description": "Update the specified third party resource of the type specified",
"tags": [
"third_party_resources"
],
"parameters": [
{
"name": "namespace",
"in": "path",
"required": true,
"description": "The Resource's namespace",
"type": "string"
},
{
"name": "fqdn",
"in": "path",
"required": true,
"description": "The Third party Resource fqdn",
"type": "string"
},
{
"name": "resource",
"in": "path",
"required": true,
"description": "The Resource type",
"type": "string"
},
{
"name": "body",
"in": "body",
"required": true,
"description": "The JSON schema of the Resource to create.",
"schema": {
"type": "object"
}
}
],
"responses": {
"201": {
"description": "A list of Resources",
"schema": {
"type": "object"
}
}
}
}
}
}