{
  "openapi": "3.1.0",
  "info": {
    "title": "API publica de pliego",
    "version": "v1",
    "description": "Contenido publicado por el administrador. Toda lectura necesita un token de consumidor en la cabecera Authorization, y cada token tiene sus entornos y sus secciones. El prefijo /v1 no es decorativo: si algun dia un cambio rompe el contrato, nace /v2 y /v1 sigue sirviendo a quien no migro."
  },
  "servers": [
    {
      "url": "https://pliego-bff.carlosurquiza.cl"
    }
  ],
  "components": {
    "securitySchemes": {
      "tokenDeConsumidor": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "RespuestaSecciones": {
        "type": "object",
        "properties": {
          "secciones": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "clave": {
                  "type": "string"
                },
                "nombre": {
                  "type": "string"
                },
                "descripcion": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "entornos": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                }
              },
              "required": [
                "clave",
                "nombre",
                "descripcion",
                "entornos"
              ],
              "additionalProperties": false
            }
          }
        },
        "required": [
          "secciones"
        ],
        "additionalProperties": false
      },
      "RespuestaContenido": {
        "type": "object",
        "properties": {
          "entorno": {
            "type": "string"
          },
          "seccion": {
            "type": "string"
          },
          "version": {
            "type": "integer",
            "exclusiveMinimum": 0,
            "maximum": 9007199254740991
          },
          "publicadoEn": {
            "type": "string"
          },
          "documento": {}
        },
        "required": [
          "entorno",
          "seccion",
          "version",
          "publicadoEn",
          "documento"
        ],
        "additionalProperties": false
      },
      "RespuestaEsquema": {
        "type": "object",
        "properties": {
          "entorno": {
            "type": "string"
          },
          "seccion": {
            "type": "string"
          },
          "esquema": {
            "$ref": "#/$defs/__schema0"
          }
        },
        "required": [
          "entorno",
          "seccion",
          "esquema"
        ],
        "additionalProperties": false,
        "$defs": {
          "__schema0": {
            "type": "object",
            "properties": {
              "title": {
                "type": "string",
                "maxLength": 200
              },
              "description": {
                "type": "string",
                "maxLength": 1000
              },
              "type": {
                "type": "string",
                "const": "object"
              },
              "properties": {
                "type": "object",
                "propertyNames": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 200
                },
                "additionalProperties": {
                  "$ref": "#/$defs/__schema1"
                }
              },
              "required": {
                "type": "array",
                "items": {
                  "type": "string",
                  "minLength": 1
                }
              }
            },
            "required": [
              "type",
              "properties"
            ],
            "additionalProperties": false
          },
          "__schema1": {
            "oneOf": [
              {
                "$ref": "#/$defs/__schema0"
              },
              {
                "type": "object",
                "properties": {
                  "title": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "description": {
                    "type": "string",
                    "maxLength": 1000
                  },
                  "type": {
                    "type": "string",
                    "const": "array"
                  },
                  "items": {
                    "$ref": "#/$defs/__schema1"
                  }
                },
                "required": [
                  "type",
                  "items"
                ],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "title": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "description": {
                    "type": "string",
                    "maxLength": 1000
                  },
                  "type": {
                    "type": "string",
                    "const": "string"
                  },
                  "enum": {
                    "minItems": 1,
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "x-recurso": {
                    "type": "object",
                    "properties": {
                      "clase": {
                        "type": "string",
                        "enum": [
                          "json",
                          "imagen",
                          "pdf",
                          "texto",
                          "otro"
                        ]
                      },
                      "esquema": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 500
                      }
                    },
                    "required": [
                      "clase"
                    ],
                    "additionalProperties": false
                  }
                },
                "required": [
                  "type"
                ],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "title": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "description": {
                    "type": "string",
                    "maxLength": 1000
                  },
                  "type": {
                    "type": "string",
                    "const": "boolean"
                  }
                },
                "required": [
                  "type"
                ],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "title": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "description": {
                    "type": "string",
                    "maxLength": 1000
                  },
                  "type": {
                    "type": "string",
                    "const": "number"
                  }
                },
                "required": [
                  "type"
                ],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "title": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "description": {
                    "type": "string",
                    "maxLength": 1000
                  },
                  "type": {
                    "type": "string",
                    "const": "integer"
                  }
                },
                "required": [
                  "type"
                ],
                "additionalProperties": false
              }
            ]
          }
        }
      },
      "RespuestaHistorial": {
        "type": "object",
        "properties": {
          "entorno": {
            "type": "string",
            "enum": [
              "dev",
              "qa",
              "prod"
            ]
          },
          "versiones": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "numero": {
                  "type": "integer",
                  "exclusiveMinimum": 0,
                  "maximum": 9007199254740991
                },
                "publicadoPor": {
                  "type": "string"
                },
                "publicadoEn": {
                  "type": "string",
                  "format": "date-time",
                  "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$"
                },
                "nota": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "bytes": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 9007199254740991
                }
              },
              "required": [
                "numero",
                "publicadoPor",
                "publicadoEn",
                "nota",
                "bytes"
              ],
              "additionalProperties": false
            }
          }
        },
        "required": [
          "entorno",
          "versiones"
        ],
        "additionalProperties": false
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "codigo": {
                "type": "string"
              },
              "mensaje": {
                "type": "string"
              }
            },
            "required": [
              "codigo",
              "mensaje"
            ],
            "additionalProperties": false
          }
        },
        "required": [
          "error"
        ],
        "additionalProperties": false
      }
    }
  },
  "security": [
    {
      "tokenDeConsumidor": []
    }
  ],
  "paths": {
    "/v1/secciones": {
      "get": {
        "summary": "Secciones que este token puede leer",
        "description": "Devuelve solo las secciones permitidas para el token, con los entornos a los que tiene acceso.",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Correcto.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RespuestaSecciones"
                }
              }
            }
          },
          "401": {
            "description": "Falta el token o no existe.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "El token no tiene permiso sobre ese entorno o esa sección.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "No existe, o no hay nada publicado todavia.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/contenido/{entorno}/{seccion}": {
      "get": {
        "summary": "Documento publicado",
        "description": "El documento tal como quedo al publicarse. Con ?v=N devuelve esa version en vez de la ultima. Responde ETag; mandar If-None-Match evita descargarlo de nuevo.",
        "parameters": [
          {
            "name": "entorno",
            "in": "path",
            "required": true,
            "description": "dev, qa o prod.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "seccion",
            "in": "path",
            "required": true,
            "description": "Clave de la sección.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "v",
            "in": "query",
            "required": false,
            "description": "Número de versión. Sin el, la última publicada.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Correcto.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RespuestaContenido"
                }
              }
            }
          },
          "304": {
            "description": "Sin cambios desde el ETag enviado."
          },
          "401": {
            "description": "Falta el token o no existe.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "El token no tiene permiso sobre ese entorno o esa sección.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "No existe, o no hay nada publicado todavia.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/esquema/{entorno}/{seccion}": {
      "get": {
        "summary": "JSON Schema de la sección",
        "description": "La forma declarada del documento. Sirve para generar tipos en vez de escribirlos a mano.",
        "parameters": [
          {
            "name": "entorno",
            "in": "path",
            "required": true,
            "description": "dev, qa o prod.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "seccion",
            "in": "path",
            "required": true,
            "description": "Clave de la sección.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Correcto.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RespuestaEsquema"
                }
              }
            }
          },
          "401": {
            "description": "Falta el token o no existe.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "El token no tiene permiso sobre ese entorno o esa sección.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "No existe, o no hay nada publicado todavia.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/versiones/{entorno}/{seccion}": {
      "get": {
        "summary": "Historial de versiones",
        "description": "Número, quien público, cuando y la nota de cada versión.",
        "parameters": [
          {
            "name": "entorno",
            "in": "path",
            "required": true,
            "description": "dev, qa o prod.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "seccion",
            "in": "path",
            "required": true,
            "description": "Clave de la sección.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Correcto.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RespuestaHistorial"
                }
              }
            }
          },
          "401": {
            "description": "Falta el token o no existe.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "El token no tiene permiso sobre ese entorno o esa sección.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "No existe, o no hay nada publicado todavia.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/contenido/{entorno}/{seccion}/preview": {
      "get": {
        "summary": "Borrador sin publicar",
        "description": "El borrador armado desde la base, para probar antes de publicar. Requiere un token con permiso de preview.",
        "parameters": [
          {
            "name": "entorno",
            "in": "path",
            "required": true,
            "description": "dev, qa o prod.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "seccion",
            "in": "path",
            "required": true,
            "description": "Clave de la sección.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Correcto.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RespuestaContenido"
                }
              }
            }
          },
          "401": {
            "description": "Falta el token o no existe.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "El token no tiene permiso sobre ese entorno o esa sección.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "No existe, o no hay nada publicado todavia.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  }
}