openapi: 3.1.0 info: title: Alfredos API version: 1.0.0 description: API REST didatica para consultar os Alfredos e os itens encontrados pelas automacoes. servers: - url: http://127.0.0.1:3000 description: Ambiente local tags: - name: Sistema - name: Alfredos - name: Itens paths: /health: get: tags: [Sistema] summary: Verifica a saude da API responses: "200": description: API disponivel content: application/json: schema: type: object required: [status, timestamp] properties: status: { type: string, const: ok } timestamp: { type: string, format: date-time } /api/v1/stats: get: tags: [Sistema] summary: Retorna totais agregados responses: "200": description: Estatisticas atuais content: application/json: schema: type: object properties: data: { $ref: "#/components/schemas/Stats" } /api/v1/alfredos: get: tags: [Alfredos] summary: Lista Alfredos parameters: - $ref: "#/components/parameters/Page" - $ref: "#/components/parameters/Limit" - name: active in: query schema: { type: boolean } - name: category in: query schema: { $ref: "#/components/schemas/AlfredoCategory" } - name: search in: query schema: { type: string } responses: "200": description: Lista paginada content: application/json: schema: allOf: - $ref: "#/components/schemas/PaginatedResponse" - type: object properties: data: type: array items: { $ref: "#/components/schemas/Alfredo" } "400": { $ref: "#/components/responses/BadRequest" } post: tags: [Alfredos] summary: Cria um Alfredo requestBody: required: true content: application/json: schema: { $ref: "#/components/schemas/CreateAlfredo" } example: name: Alfredo Clima description: Consulta a previsao e envia um resumo ao Telegram. category: outro schedule: Todos os dias as 07:00 active: true responses: "201": description: Alfredo criado headers: Location: schema: { type: string } content: application/json: schema: type: object properties: data: { $ref: "#/components/schemas/Alfredo" } "409": { $ref: "#/components/responses/Conflict" } "415": { $ref: "#/components/responses/UnsupportedMediaType" } "422": { $ref: "#/components/responses/ValidationError" } /api/v1/alfredos/{id}: parameters: - $ref: "#/components/parameters/Id" get: tags: [Alfredos] summary: Consulta um Alfredo por ID responses: "200": description: Alfredo encontrado content: application/json: schema: type: object properties: data: { $ref: "#/components/schemas/Alfredo" } "404": { $ref: "#/components/responses/NotFound" } patch: tags: [Alfredos] summary: Atualiza parte de um Alfredo requestBody: required: true content: application/json: schema: { $ref: "#/components/schemas/UpdateAlfredo" } responses: "200": description: Alfredo atualizado content: application/json: schema: type: object properties: data: { $ref: "#/components/schemas/Alfredo" } "404": { $ref: "#/components/responses/NotFound" } "409": { $ref: "#/components/responses/Conflict" } "422": { $ref: "#/components/responses/ValidationError" } delete: tags: [Alfredos] summary: Exclui um Alfredo sem itens relacionados responses: "204": { description: Excluido sem corpo na resposta } "404": { $ref: "#/components/responses/NotFound" } "409": { $ref: "#/components/responses/Conflict" } /api/v1/items: get: tags: [Itens] summary: Lista noticias, jogos e alertas parameters: - $ref: "#/components/parameters/Page" - $ref: "#/components/parameters/Limit" - name: alfredoId in: query schema: { type: string } - name: type in: query schema: { $ref: "#/components/schemas/ItemType" } - name: status in: query schema: { $ref: "#/components/schemas/ItemStatus" } - name: search in: query schema: { type: string } responses: "200": description: Lista paginada content: application/json: schema: allOf: - $ref: "#/components/schemas/PaginatedResponse" - type: object properties: data: type: array items: { $ref: "#/components/schemas/Item" } "400": { $ref: "#/components/responses/BadRequest" } post: tags: [Itens] summary: Cria uma noticia, jogo ou alerta requestBody: required: true content: application/json: schema: { $ref: "#/components/schemas/CreateItem" } example: alfredoId: alfredo-gamer type: jogo title: Jogo gratuito de exemplo description: Oferta criada pelo Postman para praticar POST. url: https://example.com/jogo status: pendente metadata: platform: Steam responses: "201": description: Item criado headers: Location: schema: { type: string } content: application/json: schema: type: object properties: data: { $ref: "#/components/schemas/Item" } "415": { $ref: "#/components/responses/UnsupportedMediaType" } "422": { $ref: "#/components/responses/ValidationError" } /api/v1/items/{id}: parameters: - $ref: "#/components/parameters/Id" get: tags: [Itens] summary: Consulta um item por ID responses: "200": description: Item encontrado content: application/json: schema: type: object properties: data: { $ref: "#/components/schemas/Item" } "404": { $ref: "#/components/responses/NotFound" } patch: tags: [Itens] summary: Atualiza parte de um item requestBody: required: true content: application/json: schema: { $ref: "#/components/schemas/UpdateItem" } responses: "200": description: Item atualizado content: application/json: schema: type: object properties: data: { $ref: "#/components/schemas/Item" } "404": { $ref: "#/components/responses/NotFound" } "422": { $ref: "#/components/responses/ValidationError" } delete: tags: [Itens] summary: Exclui um item responses: "204": { description: Excluido sem corpo na resposta } "404": { $ref: "#/components/responses/NotFound" } components: parameters: Id: name: id in: path required: true schema: { type: string } Page: name: page in: query schema: { type: integer, minimum: 1, default: 1 } Limit: name: limit in: query schema: { type: integer, minimum: 1, maximum: 100, default: 10 } schemas: AlfredoCategory: type: string enum: [noticias, games, seguranca, outro] ItemType: type: string enum: [noticia, jogo, alerta-seguranca] ItemStatus: type: string enum: [pendente, enviado, arquivado] CreateAlfredo: type: object additionalProperties: false required: [name, description, category, schedule, active] properties: name: { type: string, minLength: 2, maxLength: 80 } slug: { type: string, pattern: "^[a-z0-9]+(?:-[a-z0-9]+)*$" } description: { type: string, minLength: 5, maxLength: 500 } category: { $ref: "#/components/schemas/AlfredoCategory" } schedule: { type: string, minLength: 1, maxLength: 100 } active: { type: boolean } UpdateAlfredo: type: object additionalProperties: false minProperties: 1 properties: name: { type: string, minLength: 2, maxLength: 80 } slug: { type: string, pattern: "^[a-z0-9]+(?:-[a-z0-9]+)*$" } description: { type: string, minLength: 5, maxLength: 500 } category: { $ref: "#/components/schemas/AlfredoCategory" } schedule: { type: string, minLength: 1, maxLength: 100 } active: { type: boolean } Alfredo: type: object additionalProperties: false required: [id, name, slug, description, category, schedule, active, createdAt, updatedAt] properties: id: { type: string } name: { type: string, minLength: 2, maxLength: 80 } slug: { type: string, pattern: "^[a-z0-9]+(?:-[a-z0-9]+)*$" } description: { type: string, minLength: 5, maxLength: 500 } category: { $ref: "#/components/schemas/AlfredoCategory" } schedule: { type: string, minLength: 1, maxLength: 100 } active: { type: boolean } createdAt: { type: string, format: date-time } updatedAt: { type: string, format: date-time } CreateItem: type: object additionalProperties: false required: [alfredoId, type, title, description] properties: alfredoId: { type: string } type: { $ref: "#/components/schemas/ItemType" } title: { type: string, minLength: 3, maxLength: 160 } description: { type: string, minLength: 3, maxLength: 1000 } url: anyOf: - { type: string, format: uri, maxLength: 2000 } - { type: string, const: "" } status: { $ref: "#/components/schemas/ItemStatus" } metadata: { type: object, additionalProperties: true } UpdateItem: type: object additionalProperties: false minProperties: 1 properties: alfredoId: { type: string } type: { $ref: "#/components/schemas/ItemType" } title: { type: string, minLength: 3, maxLength: 160 } description: { type: string, minLength: 3, maxLength: 1000 } url: anyOf: - { type: string, format: uri, maxLength: 2000 } - { type: string, const: "" } status: { $ref: "#/components/schemas/ItemStatus" } metadata: { type: object, additionalProperties: true } Item: type: object additionalProperties: false required: [id, alfredoId, type, title, description, url, status, metadata, createdAt, updatedAt] properties: id: { type: string } alfredoId: { type: string } type: { $ref: "#/components/schemas/ItemType" } title: { type: string, minLength: 3, maxLength: 160 } description: { type: string, minLength: 3, maxLength: 1000 } url: anyOf: - { type: string, format: uri, maxLength: 2000 } - { type: string, const: "" } status: { $ref: "#/components/schemas/ItemStatus" } metadata: { type: object, additionalProperties: true } createdAt: { type: string, format: date-time } updatedAt: { type: string, format: date-time } PaginationMeta: type: object required: [page, limit, total, totalPages] properties: page: { type: integer } limit: { type: integer } total: { type: integer } totalPages: { type: integer } PaginatedResponse: type: object required: [data, meta, links] properties: meta: { $ref: "#/components/schemas/PaginationMeta" } links: type: object properties: self: { type: string } next: { type: [string, "null"] } previous: { type: [string, "null"] } Stats: type: object properties: alfredos: type: object properties: total: { type: integer } active: { type: integer } items: type: object properties: total: { type: integer } byType: { type: object, additionalProperties: { type: integer } } byStatus: { type: object, additionalProperties: { type: integer } } Error: type: object properties: error: type: object required: [code, message, requestId] properties: code: { type: string } message: { type: string } requestId: { type: string } details: type: array items: type: object properties: field: { type: string } message: { type: string } responses: BadRequest: description: Requisicao malformada content: application/json: schema: { $ref: "#/components/schemas/Error" } NotFound: description: Recurso nao encontrado content: application/json: schema: { $ref: "#/components/schemas/Error" } Conflict: description: Conflito com o estado atual content: application/json: schema: { $ref: "#/components/schemas/Error" } UnsupportedMediaType: description: Content-Type nao suportado content: application/json: schema: { $ref: "#/components/schemas/Error" } ValidationError: description: Dados invalidos content: application/json: schema: { $ref: "#/components/schemas/Error" }