Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

303
Views
¿Cuál es el tipo de esquema para el objeto JSON en swagger 2.0?

Estoy escribiendo un documento API con la ayuda de Swagger 2.0. He generado una API donde la respuesta está en una variedad de libros que funciona bien.

 [{ "id": 1, "book_name": "The Complete Reference Java8", "author": "Herbert Schidt", "genre": "Technology" }, { "id": 2, "book_name": "C Programming", "author": "Dennis Ritchie", "genre": "Technology" }]

Pavonearse

 /fetchBooks: get: description: | Returns an array of book objects. responses: 200: description: Successful response schema: title: ArrayOfBooks type: array items: type: object properties: id: type: integer book_name: type: string author: type: string genre: type: string

Bueno, quiero enviar solo los detalles de un libro en una API en JSONObject qué tipo de esquema debo tomar, ya que probé que el objeto no funciona.

 { "id": 1, "book_name": "The Complete Reference Java8", "author": "Herbert Schidt", "genre": "Technology" }

Pavonearse

 /fetchBook: get: description: | Returns a book object parameters: - name: id in: query description: Books Id's reqrequired: true type: integer format: int responses: 200: description: Successful response schema: type: object <-- What type should I specify for JSONObject here items: type: object properties: id: type: integer book_name: type: string author: type: string genre: type: string

Como el objeto no funciona, Swagger no muestra el formato JSON .

Estado actual :

ingrese la descripción de la imagen aquí

Estado esperado:

ingrese la descripción de la imagen aquí

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

 /fetchBook: get: description: | Returns a book object parameters: - name: id in: query description: Books Id's required: true type: integer format: int responses: '200': description: Successful response schema: type: object properties: id: type: integer book_name: type: string author: type: string genre: type: string

el problema que tuviste fue un error tipográfico en el campo requerido

y el siguiente es la sintaxis correcta para las respuestas de un solo objeto

over 4 years ago · Santiago Trujillo Report

0

Sugerencia: si desea reutilizar el mismo esquema en varias operaciones, por ejemplo, tener un solo Book y un ArrayOfBooks , puede definir el esquema en la sección de definitions y $ref en otro lugar.

 paths: /fetchBooks: get: ... responses: 200: description: Successful response schema: $ref: '#/definitions/ArrayOfBooks' # <-------- /fetchBook: get: ... responses: 200: description: Successful response schema: $ref: '#/definitions/Book' # <-------- definitions: Book: type: object properties: id: type: integer book_name: type: string author: type: string genre: type: string ArrayOfBooks: type: array items: $ref: '#/definitions/Book' # <--------


Además, si se trata de una nueva API en desarrollo y no de una API existente, "buscar" en GET /fetchBooks es redundante (GET = buscar). Considere soltar "buscar" y usar solo GET /books y GET /book?id=... .

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!