NexdApp / nexd-backend

MIT License
38 stars 3 forks source link

Validate generated swagger file #124

Closed f10l closed 4 years ago

f10l commented 4 years ago

If we mess something up, the generated swagger file is not valid and no message is shown.

We need a test to validate the generated swagger file.

qndrey commented 4 years ago

Could you describe a bit more?

f10l commented 4 years ago

Sure :-)

In case we mess up some swagger decorators (I think setting a type that does not exist), the generated swagger json is invalid (in the swagger ui, the corresponding section is not working and the console shows an error). The json can not be used by openapi parsers. We can probably validate the swagger output file directly. I am not sure where the best place is.

qndrey commented 4 years ago

Is there a way to generate json/yaml schema with nestjs/swagger? I didn't find anything, but I found a schema validation module.

So idea was to add a pre-commit hook which will generate a swagger json/yaml file and validate it, it will slow down a bit commit speed.

Another option is we can integrate it to ci pipeline before start testing.

f10l commented 4 years ago

I would prefer to add this to the (non existing) tests in the pipeline. I think it is enough, if the test fails, once a PR is added.

https://github.com/nestjs/swagger/issues/57#issuecomment-368238060

This one works. We should exclude this file from git then, to avoid a stale definition.