# Copyright 2020 Google LLC. 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.
$schema: "http://json-schema.org/draft-07/schema#"
title: OutputMessage
type: object
additionalProperties: false
description: |-
  The specification for a structured output message. Binaries that want to have
  more control over how their output is rendered in gcloud should wrap all
  messages logged to stdin and stdout in this schema.
definitions:
  error_details:
    type: object
    required:
    - error
    properties:
      error:
        type: string
        description: |-
          The exception or error being logged e.g.
          'User Error' or 'ValidationException'.
      context:
        type: string
        description: Any stack-trace or additional error context.
oneOf:
# version, timestamp, body required & error_details NOT specified.
- required: [version, timestamp, body]
  not:
    required: [error_details]
# OR version, timestamp, error_details required & body, resource_body NOT specfied.
- required: [version, timestamp, error_details]
  not:
    required: [body, resource_body]
properties:
  version:
    type: string
    description: |-
     Semantic version of the message format e.g. v1.0.0. Useful if message
      format changes before binary is updated.
  timestamp:
    type: string
    format: date-time
    description: |-
      [RFC 3339](https://www.rfc-editor.org/rfc/rfc3339.txt) encoded timestamp.
  body:
    type: string
    description: |-
      The actual content of the message. JSON/YAML structured content will be
      assumed to be resource content otherwise it will be assumed to be
      plain text.
  resource_body:
    oneOf:
    - {type: object}
    - {type: array}
    description: |-
      Structured resource/resource list content e.g. YAML or JSON serializable
      content representing some resource or set of resources.
  error_details:
    "$ref": "#/definitions/error_details"
    description: Only present if the message is related to an error.
  level:
    type: string
    description: The message level.
