{
  "openapi": "3.1.0",
  "info": {
    "title": "DPP Fácil REST API",
    "version": "1.0.0",
    "description": "API REST del Pasaporte Digital de Producto (DPP). Identificadores GS1 Digital Link; el pasaporte público se sirve también en JSON y JSON-LD (schema.org), formatos abiertos. Tus datos son tuyos y exportables, sin lock-in.",
    "contact": {
      "name": "DPP Fácil",
      "email": "info@dppfacil.com",
      "url": "https://dppfacil.com"
    },
    "license": {
      "name": "Datos propiedad del cliente; exportación libre"
    }
  },
  "servers": [
    {
      "url": "https://dppfacil.com",
      "description": "Producción"
    }
  ],
  "tags": [
    {
      "name": "Productos",
      "description": "CRUD de pasaportes con clave de API. Una clave de empresa solo ve sus productos."
    },
    {
      "name": "Pasaporte público",
      "description": "Lectura pública del pasaporte (sin clave). Resolver GS1 Digital Link."
    }
  ],
  "components": {
    "securitySchemes": {
      "ApiKeyHeader": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key"
      },
      "BearerKey": {
        "type": "http",
        "scheme": "bearer"
      },
      "ApiKeyQuery": {
        "type": "apiKey",
        "in": "query",
        "name": "api_key"
      }
    },
    "schemas": {
      "Producto": {
        "type": "object",
        "required": [
          "serie",
          "nombre"
        ],
        "additionalProperties": true,
        "properties": {
          "serie": {
            "type": "string",
            "example": "CAM-100"
          },
          "nombre": {
            "type": "string",
            "example": "Camiseta orgánica"
          },
          "cliente": {
            "type": "string",
            "description": "Marca",
            "example": "Tu marca"
          },
          "gtin": {
            "type": "string",
            "example": "08412345000013"
          },
          "sector": {
            "type": "string",
            "enum": [
              "textil",
              "calzado",
              "electronica",
              "muebles",
              "baterias",
              "neumaticos",
              "acero",
              "colchones"
            ]
          },
          "materiales": {
            "type": "string",
            "example": "100% algodón orgánico"
          },
          "pais_fabricacion": {
            "type": "string",
            "example": "Portugal"
          },
          "certificaciones": {
            "type": "string",
            "example": "GOTS · OEKO-TEX"
          },
          "contenido_reciclado": {
            "type": "string"
          },
          "huella_carbono": {
            "type": "string"
          },
          "cuidado": {
            "type": "string"
          },
          "fin_vida": {
            "type": "string"
          }
        }
      },
      "RespuestaEscritura": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean"
          },
          "created": {
            "type": "boolean"
          },
          "serie": {
            "type": "string"
          },
          "passport": {
            "type": "string",
            "format": "uri",
            "description": "URL pública del pasaporte (GS1 Digital Link)"
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          }
        }
      }
    }
  },
  "paths": {
    "/api/v1/products": {
      "get": {
        "tags": [
          "Productos"
        ],
        "summary": "Listar productos",
        "security": [
          {
            "ApiKeyHeader": []
          },
          {
            "BearerKey": []
          },
          {
            "ApiKeyQuery": []
          }
        ],
        "responses": {
          "200": {
            "description": "Lista de productos",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "count": {
                      "type": "integer"
                    },
                    "products": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Producto"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Clave no válida o ausente",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "Productos"
        ],
        "summary": "Crear o actualizar un producto",
        "security": [
          {
            "ApiKeyHeader": []
          },
          {
            "BearerKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Producto"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Creado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RespuestaEscritura"
                }
              }
            }
          },
          "200": {
            "description": "Actualizado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RespuestaEscritura"
                }
              }
            }
          },
          "400": {
            "description": "Faltan serie/nombre o JSON inválido"
          },
          "401": {
            "description": "Sin clave"
          },
          "403": {
            "description": "Clave de solo lectura"
          }
        }
      }
    },
    "/api/v1/products/{serie}": {
      "get": {
        "tags": [
          "Productos"
        ],
        "summary": "Obtener un producto",
        "security": [
          {
            "ApiKeyHeader": []
          },
          {
            "BearerKey": []
          },
          {
            "ApiKeyQuery": []
          }
        ],
        "parameters": [
          {
            "name": "serie",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Producto",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Producto"
                }
              }
            }
          },
          "401": {
            "description": "Sin clave"
          },
          "404": {
            "description": "No encontrado"
          }
        }
      }
    },
    "/api/p/{serie}.json": {
      "get": {
        "tags": [
          "Pasaporte público"
        ],
        "summary": "Pasaporte público (JSON)",
        "description": "Sin autenticación. Solo datos de nivel consumidor.",
        "parameters": [
          {
            "name": "serie",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Pasaporte público",
            "content": {
              "application/json": {}
            }
          },
          "404": {
            "description": "No encontrado"
          }
        }
      }
    },
    "/api/p/{serie}.jsonld": {
      "get": {
        "tags": [
          "Pasaporte público"
        ],
        "summary": "Pasaporte público (JSON-LD, schema.org)",
        "description": "Formato abierto e interoperable (schema.org/Product). Sin autenticación.",
        "parameters": [
          {
            "name": "serie",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "JSON-LD",
            "content": {
              "application/ld+json": {}
            }
          },
          "404": {
            "description": "No encontrado"
          }
        }
      }
    },
    "/01/{gtin}/21/{serie}": {
      "get": {
        "tags": [
          "Pasaporte público"
        ],
        "summary": "Resolver GS1 Digital Link (pasaporte)",
        "description": "El identificador estándar del DPP. Devuelve la página pública del pasaporte.",
        "parameters": [
          {
            "name": "gtin",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "serie",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Página del pasaporte (HTML)",
            "content": {
              "text/html": {}
            }
          },
          "404": {
            "description": "No encontrado"
          }
        }
      }
    }
  }
}