Gerne! Hier ist eine OpenAPI Beispiel-Spezifikation für ein Interface um tasks zu verwalten, mit den Methoden zum erstennel, bearbeiten und löschen von tasks, sowie dem abhaken von erfüllten tasks:
openapi: 3.0.0
info:
title: Task Manager API
version: 1.0.0
paths:
/tasks:
get:
summary: Get all tasks
description: Returns a list of all tasks
responses:
200:
description: List of tasks
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/Task"
404:
description: Not found
post:
summary: Create a new task
description: Creates a new task with the provided information
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/Task"
responses:
201:
description: Task created
location:
url: "/tasks/{id}"
headers:
Location:
description: The URL of the newly created task
security:
- Bearer: []
examples:
json:
"{\n \"text\": \"Testtask\",\n \"completed\": false,\n }"
statusCode: 201
put:
summary: Update a task
description: Updates a task with the provided information
parameters:
- in: path
name: id
schema:
type: string
description: The ID of the task to update
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/Task"
responses:
200:
description: Task updated
404:
description: Not found
/tasks/{id}:
get:
summary: Get a specific task
description: Returns a single task by its ID
parameters:
- in: path
name: id
schema:
type: string
description: The ID of the task to retrieve
responses:
200:
description: Task retrieved
content:
application/json:
schema:
$ref: "#/components/schemas/Task"
404:
description: Not found
delete:
summary: Delete a task
description: Deletes a task by its ID
parameters:
- in: path
name: id
schema:
type: string
description: The ID of the task to delete
responses:
200:
description: Task deleted
404:
description: Not found
components:
schemas:
Task:
type: object
properties:
id:
type: integer
text:
type: string
completed:
type: boolean
checked:
type: boolean
required:
- id
- text
- completed
- checked
Diese Spezifikation definiert zwei Pfade: /tasks und /tasks/{id}. Der erste zeigt eine Liste aller Tasks an und erlaubt das Ausführen von CRUD Operationen auf ihnen (erstellen, lesen, aktualisieren, löschen). Der zweite Pfad ist zum Zugreifen auf einen speziellen Task nach ID um ähnliche Operationen auf ihm auszuführen. Jede Operation hat eine korrespondierende HTTP Methode, die mit ihr assoziiert ist (GET, POST, PUT, DELETE).
Für jede Operation muss der Request-Body spezifizieren, welche Daten an den Server gesendet werden. Zum Beispiel muss beim Erstellen eines neuen Tasks der Request-Body ein JSON-Objekt enthalten, das die Felder für "text" und "completed" des Tasks definiert. Auf ähnliche Weise ist bei der Aktualisierung oder Löschung eines Tasks erforderlich, dass die Task-ID zusammen mit eventuellen Änderungen bereitgestellt wird.
Bitte beachte, dass das nur ein Beispiel ist, und je nachdem an deine eigenen Bedürfnisse angepasst werden muss.