Ich verstehe also, dass wir, wenn wir Körperparameter wollen, ein Schema haben müssen, was ich auch tue. Das Problem ist egal, wie ich versuche, mein Schema zu definieren, es erlaubt mir nicht, mehrere Körperparameter zu haben. Hier ist ein Beispiel für eine der Methoden, die ich ausprobiert habe. Jede Hilfe wäre toll!
swagger: '2.0'
# This is your document metadata
info:
version: "0.0.1"
title: Todo App
schema: {
}
Host: localhost:3000
schemes:
- http
- https
consumes:
- application/json
produces:
- application/x-www-form-urlencoded
basePath: /
paths:
# This is a path endpoint. Change it.
/tasks:
post:
description: |
Add 'Task' object.
parameters:
# An example parameter that is in query and is required
-
name: name
in: query
description: unique object task name
required: true
schema:
type: string
- name: description
in: query
description: task description
required: true
schema:
type: string
responses:
# Response code
200:
description: Successful response
# A schema describing your response object.
# Use JSON Schema format
schema:
title: Return String
type: string
example: "Task added succesfully"
500:
description: Error
schema:
type: string
example: "Could not add Task"
Ich bin mir nicht sicher, ob ich deine Frage verstehe ...
Körper Es kann nur einen Körperparameter geben
Ihre Beispielknoten sind auch falsch, siehe hier für weitere Details.
swagger: '2.0'
info:
version: "0.0.1"
title: Todo App
Host: localhost:3000
schemes:
- http
- https
consumes:
- application/json
produces:
- application/x-www-form-urlencoded
basePath: /
paths:
# This is a path endpoint. Change it.
/tasks:
post:
description: |
Add 'Task' object.
parameters:
- name: task
in: body
description: task object
required: true
schema:
$ref: '#/definitions/Task'
responses:
200:
description: Successful response
schema:
title: Return String
type: string
example: "Task added succesfully"
500:
description: Error
schema:
type: string
example: "Could not add Task"
definitions:
Task:
description: Task object
properties:
name:
type: string
description: task object name
description:
type: string
description: task description
required:
- name
- description
Sie können auch die Eigenschaften des Request-Body-Parameters definieren, indem Sie properties
als Teil seines schema
verwenden. Dies ist ein gutes Beispiel unter Object Payload: https://swagger.io/docs/specification/2-0/describing-request-body/ .
paths:
/users:
post:
summary: Creates a new user.
consumes:
- application/json
parameters:
- in: body
name: user
description: The user to create.
schema:
type: object
required:
- userName
properties:
userName:
type: string
firstName:
type: string
lastName:
type: string
responses:
201:
description: Created
Der Nachteil ist natürlich, dass Sie keine Objektdefinition wiederverwenden können, aber manchmal ist eine Objektdefinition nicht geeignet.