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

Swagger docs for the REST API #141

Merged
merged 17 commits into from
Apr 26, 2024
Merged

Swagger docs for the REST API #141

merged 17 commits into from
Apr 26, 2024

Conversation

Maelkum
Copy link
Collaborator

@Maelkum Maelkum commented Apr 24, 2024

This PR adds swagger documentation for our REST API.

The OpenAPI specification can be found in /api/b7s-swagger.yaml.

To generate code from this we use https://github.com/deepmap/oapi-codegen. I've created a Makefile that supports creating three distinct things - models, server and client code, in three separate files - models.gen.go, server.gen.go and client.gen.go. I think this makes things more easily manageable and less noisy.

I opted to keep using our existing models (the ones we use internally to handle execution requests and all of that) as part of the public API. The downside is - if we start changing these, the public interface changes. Alternative is to create separate models for the REST API that can be more stable; however we'd have to duplicate everything we use internally, and our models are relatively deep. I didn't see much value in that at this point.

By default, any non-required parameter in the schema is generated as a pointer. E.g. if field is textual and not required, it will be rendered as a Field *string go type, as opposed to a regular string. IMO this makes Go codebase overly verbose and doesn't bring in much value (in most cases "" is as good as nil when determining what to do). Unfortunately to avoid the pointers, I had to add a x-go-type-skip-optional-pointer flag for each field. Ugly when reading swagger YAML, but doesn't show up when rendered and Go code is better.

@Maelkum Maelkum requested a review from dmikey April 24, 2024 16:19
@Maelkum Maelkum self-assigned this Apr 24, 2024
@dmikey dmikey merged commit 7902bc3 into main Apr 26, 2024
2 checks passed
@dmikey dmikey deleted the swagger-api branch May 13, 2024 15:39
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.

2 participants