-
Notifications
You must be signed in to change notification settings - Fork 21
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
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
andclient
code, in three separate files -models.gen.go
,server.gen.go
andclient.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 aField *string
go type, as opposed to a regularstring
. IMO this makes Go codebase overly verbose and doesn't bring in much value (in most cases""
is as good asnil
when determining what to do). Unfortunately to avoid the pointers, I had to add ax-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.