a2aproject / a2aproject/a2a-java

[Feat]: Clarify nullability and optionality of the spec API

Abierto
#506 1 comentario 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Java
Estrellas
490
Forks
172
Merge medio
1 d 6 h
PR fusionados (30 d)
55

Descripción

### Is your feature request related to a problem? Please describe.

The `spec` API is not consistent with this expectation for the nullability and optionality of objects.

For example, the [Task](https://github.com/a2aproject/a2a-java/blob/cb084ec517f5511c45c0457850337b4b74431b10/spec/src/main/java/io/a2a/spec/Task.java#L68) class
will always instantiate its `history` and `artifact` with (potentially empty) collections while its `metatada` can be null.
The API should be consistent unless there is a good reason not to.
In that case, the `metadata` should also be an empty Map if the parameter is `null`.

For case where we want to record that a field can have a value or be null, we could also leverage `Optional`.
For example, in [TaskStatus](https://github.com/a2aproject/a2a-java/blob/cb084ec517f5511c45c0457850337b4b74431b10/spec/src/main/java/io/a2a/spec/TaskStatus.java#L46), the `message` is optional. We could make its type `Optional` to constrain its contract.

### Describe the solution you'd like

Update the spec API to:
* be consistent with the nullabitity of fields (especially collections)
* use the `Optional` type for optional fields
* update the javadoc when there is exception to this general rule

### Describe alternatives you've considered

_No response_

### Additional context

_No response_

### Code of Conduct

- [x] I agree to follow this project's Code of Conduct

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.