{
  "openapi": "3.0.0",
  "info": {
    "title": "REST4i - CL Command Services",
    "description": "CL Command Services provide APIs for running CL commands.",
    "version": "1.0.7-rest4i",
    "contact": {
      "name": "API Support",
      "url": "https://github.com/rest4i"
    },
    "license": {
      "name": "Apache 2.0",
      "url": "https://www.apache.org/licenses/LICENSE-2.0.html"
    }
  },
  "servers": [
    {
      "url": "/rest4i/api"
    }
  ],
  "tags": [
    {
      "name": "CL Command Services",
      "description": "CL Command Services provide APIs for running CL commands."
    }
  ],
  "paths": {
    "/v1/cl": {
      "post": {
        "tags": ["CL Command Services"],
        "summary": "Run one or more CL commands on the server.",
        "description": "Run one or more CL commands on the server. Accepts both JSON and form-urlencoded content types. If a command fails, any messages relating to the error is returned. If the command succeeds, no data is returned.",
        "operationId": "clRunCLCommand",
        "parameters": [
          {
            "name": "Authorization",
            "in": "header",
            "description": "The authorization HTTP header.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "description": "List of CL commands to run.",
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/rest4i_CLCommands"
              },
              "example": {
                "continueOnError": true,
                "includeMessageOnSuccess": true,
                "includeMessageHelpText": false,
                "clCommands": [
                  "qsys/crtlib lib1",
                  "qsys/crtsrcpf lib1/qrpglesrc"
                ]
              }
            },
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "properties": {
                  "continueOnError": {
                    "type": "boolean",
                    "description": "Continue processing if error encountered",
                    "default": false
                  },
                  "includeMessageOnSuccess": {
                    "type": "boolean",
                    "description": "Return messages on success",
                    "default": false
                  },
                  "includeMessageHelpText": {
                    "type": "boolean",
                    "description": "Return message help text",
                    "default": false
                  },
                  "clCommands": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "description": "Array of CL command strings to execute"
                  }
                },
                "required": ["clCommands"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Command(s) issued successfully, error(s) may have occurred.",
            "content": {
              "application/json": {
                "example": {
                  "totalIssued": 2,
                  "totalSuccesses": 1,
                  "totalFailures": 1,
                  "commandOutputList": [
                    {
                      "success": false,
                      "command": "qsys/crtlib lib1",
                      "output": ["CPF2111: Library LIB1 already exists."]
                    },
                    {
                      "success": true,
                      "command": "qsys/crtsrcpf lib1/qrpglesrc",
                      "output": ["CPC7301: File QRPGLESRC created in library LIB1."]
                    }
                  ]
                }
              }
            }
          },
          "204": {
            "description": "All command(s) issued successfully, no content."
          },
          "400": {
            "description": "Bad request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized request was made.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "The request is forbidden.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "500": {
            "description": "Unable to process the request due to an internal server error.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerHttpAuthentication": []
          },
          {
            "basicHttpAuthentication": []
          }
        ]
      }
    },
    "/v1/cl/{commandname}": {
      "get": {
        "tags": ["CL Command Services"],
        "summary": "Retrieves the command definition for the specified CL command.",
        "description": "Retrieves the command definition for the specified CL command. The command definition is returned as an XML document. The generated command information XML source is called Command Definition Markup Language or CDML. See the Document Type Definition (DTD) in /QIBM/XML/DTD/QcdCLCmd.dtd for the definition of the CDML tag language returned by this API.",
        "operationId": "clGetCommandDefinition",
        "parameters": [
          {
            "name": "Authorization",
            "in": "header",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "library",
            "in": "query",
            "description": "The library name. Valid values are a specific name, or one of the following special values: *CURLIB - The current library is searched. *LIBL - The library list is searched. This is the default.",
            "schema": {
              "type": "string",
              "default": "*LIBL"
            }
          },
          {
            "name": "ignorecase",
            "in": "query",
            "description": "Boolean indicating whether case should be ignored. The default value is 'true'. If set to 'false', the library and command name will not be uppercased.",
            "schema": {
              "type": "boolean",
              "default": true
            }
          },
          {
            "name": "commandname",
            "in": "path",
            "description": "The CL command name.",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful request.",
            "content": {
              "application/json": {
                "example": {
                  "definition": "<QcdCLCmd DTDVersion=\"1.0\">...</QcdCLCmd>"
                }
              }
            }
          },
          "400": {
            "description": "Bad request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized request was made.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "The request is forbidden.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "The specified resource was not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "500": {
            "description": "Unable to process the request due to an internal server error.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearerHttpAuthentication": []
          },
          {
            "basicHttpAuthentication": []
          }
        ]
      }
    }
  },
  "components": {
    "schemas": {
      "rest4i_CLCommands": {
        "required": ["clCommands"],
        "type": "object",
        "properties": {
          "continueOnError": {
            "type": "boolean",
            "description": "Continue processing CL commands if an error is encountered.",
            "default": false
          },
          "includeMessageOnSuccess": {
            "type": "boolean",
            "description": "Return CL command messages on success.",
            "default": false
          },
          "includeMessageHelpText": {
            "type": "boolean",
            "description": "Return message help text for CL command messages.",
            "default": false
          },
          "clCommands": {
            "type": "array",
            "description": "CL command to run.",
            "items": {
              "type": "string"
            }
          }
        },
        "description": "List of CL commands to run."
      },
      "Problem": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "code": {
            "type": "integer",
            "format": "int32"
          },
          "details": {
            "type": "object"
          }
        }
      }
    },
    "securitySchemes": {
      "bearerHttpAuthentication": {
        "type": "http",
        "description": "Bearer token authentication.",
        "scheme": "bearer",
        "bearerFormat": "Bearer [token]"
      },
      "basicHttpAuthentication": {
        "type": "http",
        "description": "Basic authentication.",
        "scheme": "basic"
      }
    }
  }
}
