Skip to content

Conversation

@sshniro
Copy link
Contributor

@sshniro sshniro commented Mar 16, 2020

Fix #8

@membphis the refactoring passes all test cases.

The code should be running in 5.1 as the function loadstring has been renamed to load after lua 5.2

@membphis
Copy link
Contributor

I rebased your PR with devel branch, and run the test case, I got error:

$ make test
LUA_PATH="./lib/?.lua;./deps/lib/lua/5.1/?.lua;./deps/share/lua/5.1/?.lua;;" LUA_CPATH="./deps/lib/lua/5.1/?.so;;" resty t/draft4.lua
ERROR: ./lib/jsonschema.lua:965: attempt to call method 'preface' (a nil value)
stack traceback:
	./lib/jsonschema.lua:977: in function 'generate_validator'
	t/draft4.lua:116: in function 'file_gen'
	init_worker_by_lua:45: in function <init_worker_by_lua:43>
	[C]: in function 'xpcall'
	init_worker_by_lua:52: in function <init_worker_by_lua:50>
make: *** [Makefile:32: test] Error 1

My steps:

git check devel
git pull
git checkout pr/13 -- checkout your PR
git rebase devel   -- rebase your branch

make dev  -- dev ENV
make test  -- run test case

@sshniro
Copy link
Contributor Author

sshniro commented Mar 16, 2020

Yes, with the rebased I'm also getting the same error. I tested with 5.3 with load command and it worked, let me debug this and getback.

@sshniro
Copy link
Contributor Author

sshniro commented Mar 17, 2020

Hi @membphis an open-ended question can I know what is the IDE the team uses to debug the code. I'm using Intelliji, lua plugin, and as the code is quite big the remote debugger does not connect to the code.

@membphis
Copy link
Contributor

I mainly use Visual Code + print log, I'm a log debugger.

I do not use any debugger plugin now, the Visual code is only a source code editor for me.

@sshniro
Copy link
Contributor Author

sshniro commented Mar 18, 2020

@membphis please check now, I have accidentally deleted a function when committing :|

Selection_710

@membphis
Copy link
Contributor

yes, it works fine now

-- load doesn't like at all empty string, but sometimes it is easier to add
-- some in the chunk buffer
local function yield_chunk(chunk)
local code_table = {}
Copy link
Contributor

Choose a reason for hiding this comment

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

In general, we do not recommend using global tables to cache data. It is very dangerous for multiple objects to share a global table.

We should put the code_table object inside self object.

Copy link
Contributor

@membphis membphis Mar 19, 2020

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@membphis I have refactored accordingly and passed the local variable _code_table to the generate function. self:insert_code(indent) is a bit tricky as it involves the child processes as well and insert_code is only available for the root element.

With the current refactoring, it should resolve the issue as we are passing the self. variable to the downwards functions.

Copy link
Contributor

@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.

nice job, I'll release a new version, then we can use it in APISIX.

@membphis membphis merged commit aa47406 into api7:devel Mar 19, 2020
@membphis
Copy link
Contributor

@sshniro apache/apisix#1302

I create an issue at Apache APISIX, would you like to do this job?

@sshniro
Copy link
Contributor Author

sshniro commented Mar 19, 2020

Nice, yea would love to do that.

@membphis
Copy link
Contributor

I have uploaded the new version to luarocks.org right now. you can do it when you have time

https://luarocks.org/modules/membphis/jsonschema

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.

feature: avoid using yield, which is not supported in some user cases.

2 participants