Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Response variants are always inlined #1210

Open
JMLX42 opened this issue Nov 19, 2024 · 2 comments
Open

Response variants are always inlined #1210

JMLX42 opened this issue Nov 19, 2024 · 2 comments

Comments

@JMLX42
Copy link
Contributor

JMLX42 commented Nov 19, 2024

Hello,

Here is my code:

#[derive(Debug, Serialize, ToSchema)]
pub struct SuccessResponsePayload<T: ResourceObject> {
    #[schema(inline = false)]
    pub data: Vec<T>,
    #[schema(ignore = Self::ignore_included)]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub included: Option<Vec<T::RelationshipValue>>,
    #[schema(inline)]
    pub links: LinksObject<T>,
}

impl<T: ResourceObject> SuccessResponsePayload<T> {
    fn ignore_included() -> bool {
        !T::HAS_RELATIONSHIPS
    }
}

#[derive(Debug, Serialize, IntoResponses, ToSchema)]
#[serde(untagged)]
pub enum Response<T: ResourceObject> {
    #[response(
        status = 204,
        content_type = CONTENT_TYPE,
        description = "Success response with no content.",
    )]
    Empty,
    #[response(
        status = 200,
        content_type = CONTENT_TYPE,
        description = "Success response."
    )]
    Success(#[to_schema] SuccessResponsePayload<T>),
    #[response(
        status = "4XX",
        content_type = CONTENT_TYPE,
        description = "Client error response.",
        example = json!(EXAMPLE_ERROR_NOT_FOUND)
    )]
    ClientError(#[to_schema] ClientErrorResponse),
    #[response(
        status = "5XX",
        content_type = CONTENT_TYPE,
        description = "Server error response.",
        example = json!(EXAMPLE_ERROR_INTERNAL_SERVER_ERROR)
    )]
    ServerError(#[to_schema] ServerErrorResponse),
}
"responses": {
          "200": {
            "description": "Success response.",
            "content": {
              "application/vnd.api+json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data",
                    "links"
                  ],
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "allOf": [
                          {
                            "$ref": "#/components/schemas/AccessorSparseIndicesResourceIdentifierObject"
                          },
                          {
                            "type": "object",
                            "required": [
                              "attributes",
                              "relationships"
                            ],
                            "properties": {
                              "attributes": {
                                "$ref": "#/components/schemas/AccessorSparseIndicesResourceSparseAttributesObject"
                              },
                              "relationships": {
                                "$ref": "#/components/schemas/AccessorSparseIndicesResourceSparseRelationshipsObject"
                              }
                            }
                          }
                        ],
                        "description": "An object pointing to a buffer view containing the indices of deviating accessor values. The number of indices is\nequal to `accessor.sparse.count`. Indices **MUST** strictly increase."
                      }
                    },

For some reason, SuccessResponsePayload::data is still inlined despite #1184 .

I will write a specific test for the expected behavior (using $ref) to understand what needs to be changed.

@JMLX42
Copy link
Contributor Author

JMLX42 commented Nov 19, 2024

@juhaku I would appreciate any input you have on how to resolve this.

I will open a PR ASAP.

@JMLX42
Copy link
Contributor Author

JMLX42 commented Nov 19, 2024

Another problem:

#[derive(Debug, serde::Serialize, utoipa::ToResponse)]
pub struct #successs_ident(#[to_schema] pub ::jsonapi::response::SuccessResponse<#resource_object_ident>);

As per the documentation, I would expect SuccessResponse<#resource_object_ident> to be inlined. But it is not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant