Skip to content

Conversation

SkyeYoung
Copy link
Member

@SkyeYoung SkyeYoung commented Jun 17, 2025

Description

What

Support JSON as configuration format in standalone file mode

How

Extend apisix/core/config_yaml.lua.

Therefore, without modifying config_provider: yaml, it is compatible with the JSON format.

While this is a bit weird at the moment, I think we can change yaml to file or other more appropriate words in the future, rather than providing a new option.

Because as you can see from the code, the only difference is how to read different configuration files. The current method helps us support other different formats in the future, such as toml or other file formats that users prefer.

Why

Yaml parsing is much slower than JSON.

Test Cases

All cases are copy and changed from t/config-center-yaml/*.t.

Which issue(s) this PR fixes:

Fixes #

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

@SkyeYoung SkyeYoung marked this pull request as ready for review June 18, 2025 06:41
@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. enhancement New feature or request labels Jun 18, 2025
@SkyeYoung SkyeYoung changed the title feat(standalone): support json format feat(standalone): support JSON format Jun 18, 2025
Copilot

This comment was marked as outdated.

membphis
membphis previously approved these changes Jun 20, 2025
Copy link
Member

@membphis membphis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mainly checked the Lua code, it seems good to me

pls fix one minor issue

@SkyeYoung
Copy link
Member Author

I tried to use yarn start:website of apisix-website locally for preview, and it also works without changing to mdx:

image

Well, the style is very ugly, but it works. 😅

@kayx23
Copy link
Member

kayx23 commented Jun 20, 2025

I tried to use yarn start:website of apisix-website locally for preview, and it also works without changing to mdx:

image Well, the style is very ugly, but it works. 😅

The changes look ok to me. However if you have any constructive suggestion, please bring it forward.

@SkyeYoung
Copy link
Member Author

The changes look ok to me. However if you have any constructive suggestion, please bring it forward.

I'm just saying these CSS styles are making my eyes hurt.

If I had time, I'd rather rebuild the APISIX website docs part from scratch to solve a lot of the existing problems.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR extends the standalone file mode to support JSON as an alternative configuration format, in addition to the existing YAML support. The changes include adding new JSON-based test cases, updating configuration file parsing logic (in apisix/core/config_yaml.lua), and adjusting CLI schema and file resolution to incorporate the new "json" provider.

  • Introduce tests for JSON configurations (stream-route, ssl, route, plugin, etc.)
  • Modify configuration file reading and parsing logic to support the "json" file type.
  • Update CLI schema and file handling to reflect the new "json" config provider.

Reviewed Changes

Copilot reviewed 16 out of 18 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
t/config-center-json/*.t Added new test cases based on JSON configuration format
APISIX.pm Updated file resolution to include JSON configuration files
apisix/core/config_yaml.lua Extended config parsing to handle JSON and YAML, using file_type switch
apisix/core.lua Adjusted config module loading to set file_type based on provider ("json")
apisix/cli/schema.lua, apisix/cli/file.lua Updated to include "json" in the acceptable config_provider enums
Comments suppressed due to low confidence (1)

apisix/core.lua:32

  • Add a clarifying comment explaining why 'file_type' is being set to 'json' here, as this behavior influences the config parsing logic. This will help future maintainers understand the conditions for JSON configuration selection.
    config.file_type = "json"

Copy link
Member

@membphis membphis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM now

Copy link
Contributor

@bzp2010 bzp2010 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code looks good

@SkyeYoung SkyeYoung merged commit 20481ab into apache:master Jun 21, 2025
31 of 33 checks passed
@SkyeYoung SkyeYoung deleted the young/feat/support-json-in-standalone-mode branch June 21, 2025 10:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants