apache / apisix

The Cloud-Native API Gateway
https://apisix.apache.org/blog/
Apache License 2.0
14.54k stars 2.52k forks source link

help request: use yaml anchors and aliases in the config. #11501

Open teodorescuserban opened 3 months ago

teodorescuserban commented 3 months ago

Description

I would like to use standard yaml anchors ans aliases to not repeat myself too much in the config. The only reference to anchors i found is https://github.com/apache/apisix/issues/10468

Example:

include/variables.yaml:

variables:
  common_methods: &common_methods
    - GET
    - POST
    - PUT
    - DELETE
    ...

apisix.yaml:

include include/variables.yaml

routes:
  -
    uri: /inbound/api/*
    name: API Route
    methods: *common_methods
    service_id: 'service_api'
    upstream_id: 'upstream_api'
    labels:
      API_VERSION: '1'
      api_name: api
      api_type: inbound
    status: 1

This config will result in this error:

[error] 34#34: *3 [lua] config_yaml.lua:210: failed to check item data of [routes] err:property "methods" validation failed: wrong type: expected array, got string ,val: {"priority":0,"labels":{"api_type":"inbound","API_VERSION":"1","api_name":"api"},"name":"API Route","uri":"/inbound/api/*","upstream_id":"upstream_api","methods":"*common_methods","service_id":"service_api","status":1}, context: init_worker_by_lua*

I also tried:

include include/variables.yaml

routes:
  -
    uri: /inbound/api/*
    name: API Route
    methods:
      <<: *common_methods
    service_id: 'service_api'
    upstream_id: 'upstream_api'
    labels:
      API_VERSION: '1'
      api_name: api
      api_type: inbound
    status: 1

which results in:

[error] 35#35: *1 [lua] config_yaml.lua:210: failed to check item data of [routes] err:property "methods" validation failed: wrong type: expected array, got table ,val: {"priority":0,"service_id":"service_api","status":1,"name":"API Route","methods":{"<<":"*common_methods"},"uri":"/inbound/api/*","upstream_id":"upstream_api","labels":{"API_VERSION":"1","api_name":"api","api_type":"inbound"}}, context: init_worker_by_lua*

Any ideas? Thank you!

Environment

Using the official docker image from DockerHub: apache/apisix:3.9.1-debian

shreemaan-abhishek commented 2 months ago

this seems like a limitation from the yaml parser used by APISIX.