¡Hola, gracias por un producto tan increíble!
Estoy documentando usando el formato JSONAPI y tengo un problema al expresar un objeto dentro de una matriz. Esto es necesario debido a la especificación JSONAPI para relaciones no vacías a muchos.
Aquí está mi código de ejemplo:
# Group Stock
All inventory information and management is exposed through the `stock` endpoint.
## Stock [/stock/{id}]
- Parameters
- id: 1 (number, required) - Specific `id` of a stock item
- Attributes (Stock Base)
- id: 1 (number) - Specific id of a stock item
- type: stock (string) - Resource type
### Retireve Stock [GET]
Fetch details about specific stock.
- Response 200 (application/vnd.api+json)
- Attributes (Stock)
## Stocks [/stock]
- Attributes
- data(array[Stock]) - Full output of all data
### List all Stock [GET]
Return details of all stock.
- Response 200 (application/vnd.api+json)
- Attributes (Stocks)
# Data Structures
## Stock Base (object)
- price: 4.50 (number) - Standard price
- sale_price: 3.00 (number) - Specific sale only price
- description: Coconut yoghurt (string) - Text description of stock item
- ingredients: Coconut, Nuts, Milk (string) - Comma separated list of all ingredients
- allergens: Nuts, dairy (string) - Comma separated list of all allergen information
- Include Stock Links Base
## Stock Links Base (object)
- links (object) - JSON API links section
- *dietary_requirements* (array)
- Include Linkage
- *stock_type*
- Include Linkage
## Linkage (object)
- linkage (object) - JSON API linkage section
- id: 1 (number)
- type: reference_type (string)
Si renderiza esto en colmenar, notará que la matriz dietary_requirements
está vacía, aunque hace referencia a la estructura de datos Linkage
.
Cualquier ayuda será muy apreciada.
Intente cambiar esto:
- *dietary_requirements* (array)
- Include Linkage
A esto:
- *dietary_requirements* (array[Linkage])
No creo que sea posible usar mixins ( include
) con matrices como en este ejemplo.
¡Guau, totalmente asombroso! Muchas gracias por la rápida respuesta, esto funcionó a la perfección: sonríe:
@kylef es correcto: Include
está destinado a funcionar solo con objetos ( especificación ).
Sin embargo, el analizador debería advertir en esta ocasión: ¿no es este el caso? // cc @pksunkara
@ pete001 también puede especificar cualquier tipo como contenido de matriz así:
- my_array (array)
- (type1)
- (type2)
- (another type)
¡Gracias @zdne! El analizador de colmenar no se quejaba de mí, estaba validando bien.
El analizador debería dar una advertencia. Dejame revisar.
Comentario más útil
@ pete001 también puede especificar cualquier tipo como contenido de matriz así: