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

fix(schema) fix errors when encoding default empty arrays #4257

Merged
merged 1 commit into from
Jan 30, 2019

Conversation

kikito
Copy link
Member

@kikito kikito commented Jan 29, 2019

Previously, a schema such as this:

{ type = "array",
  default = {},
  elements = { type = "string" },
}

Would be encoded in json as a {} instead of as a [] (the Lua table given for the default value would be copied, and its metatable would remain)

A similar thing would happen with sets.

This change sets the metatable to cjson.array_mt and also adds tests for other possible values given to the default (i.e. cjson.empty_array).

kong/db/schema/init.lua Outdated Show resolved Hide resolved
Previously, a schema such as this:
```
{ type = "array",
  default = {},
  elements = { type = "string" },
}
```
Would be encoded in json as a `{}` instead of as a `[]` (the Lua table given for the default value would be copied, and its metatable would remain)

A similar thing would happen with sets.

This change sets the metatable to `cjson.array_mt` and also adds tests for other possible values given to the default (i.e. `cjson.empty_array`).
@kikito kikito force-pushed the fix/schema-default-empty-array branch from 79282b8 to 055169f Compare January 29, 2019 19:02
Copy link
Member

@bungle bungle left a comment

Choose a reason for hiding this comment

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

LGTM

@kikito kikito merged commit a54e807 into master Jan 30, 2019
@kikito kikito deleted the fix/schema-default-empty-array branch January 30, 2019 16:31
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

Successfully merging this pull request may close these issues.

3 participants