Crear un modelo extensible usando Swagger / OpenAPI
En mi API, me gustaría tener un modelo simple para mi colección y un modelo más elaborado para mi recurso individual. Por ejemplo:
una solicitud GET en/libraries
debería volver
BaseLibrary:
type: object
properties:
library_id:
type: string
description: The id of the library
display_name:
type: string
description: Name of the library
href:
type: string
description: The URI linking to this library.
mientras que una solicitud a una biblioteca específica debe devolver todo lo anterior, incluidos los libros de parámetros adicionales:
Entonces, una solicitud GET paralibraries/{library_id}
debería volver:
ExtendedLibrary:
type: object
properties:
library_id:
type: string
description: The id of the library
display_name:
type: string
description: Name of the library
href:
type: string
description: The URI linking to this library.
books:
type: array
description: The books in this library
items:
$ref: "#/definitions/books"
Me gustaría mucho no tener que definir una "BaseLibrary" dos veces y me gustaría modelar simplemente una "ExtendedLibrary" adicional que contenga todas las respuestas de una biblioteca base y la propiedad adicional de libros.
Intenté muchas cosas diferentes, siendo las definiciones más cercanas al éxito:
definitions:
BaseLibrary:
type: object
properties:
library_id:
type: string
description: The id of the library.
display_name:
type: string
description: Name of the library
href:
type: string
description: The URI linking to this library.
ExtendedLibrary:
type: object
properties:
$ref: "#/definitions/BaseLibrary/properties"
books:
type: array
description: The available books for this library.
items:
$ref: "#/definitions/Book"
Sin embargo, esto me da una advertencia de "Se ignorarán las propiedades de referencia JSON adicionales: libros" y la salida parece ignorar esta propiedad adicional. ¿Hay una manera limpia de manejar mi problema? ¿O simplemente tendré que copiar y pegar todo mi modelo de BaseLibrary en mi modelo de ExtendedLibrary?