Using `ref` with a dynamic label name

I am parsing a api.json with some schemas will be shown after. this is the basic structure:

{
  "paths": {
    "/users": {
      "response": {
        "$ref": "UserResponse"
      }
    },
    ...
  },
  "components": {
    "schemas": {
      "UserResponse": {
        ... // structure
      },
      ...
    }
  }
}

structure simplified for explaining here

At the bottom part of the document there will be a place with all the schemas labeled:

#for schema in api.components.schemas [
  == #schema.at(0) #label(schema.at(0))
  #schema.at(1) \ // will be formatted later
]

And I am trying to make this work by using a ref on the type, but it still does not work:

#let read_json_type(typ) = {
  if "type" in typ [ // it is an actual type and not a ref
    TODO:
    #typ
  ] else {
    let name = typ.at("$ref").split("/").last() // "$ref" stores the whole path, so i get the last one    
    ref(label(name))
  }
}

there is an error on ref(label(name)):

is there a way of doing this? is it just not allowed?

Project link: Typst

Duplicate of Why does my heading label errors with "cannot reference text"?.

1 Like

The link does not work, FYI. Perhaps you posted your project URL instead of sharing it?

Duplicate of

Thanks for pointing it out @Andrew! @Micaias_Oliveira, feel free to flag your own post/message me if you think this is an error.