go-bitbucket
go-bitbucket copied to clipboard
Generate Client Using Swagger
Since BitBucket provides a swagger document, we could generate the client using swaggers code gen. This would be a rewrite of the whole code base. Would this be something you are interested in?
I was interested in this as well. While I haven't spent much time on it I have encountered some errors while generating typescript
and go
sdks for https://bitbucket.org/api/swagger.json using https://github.com/OpenAPITools/openapi-generator
To generate the code I am running
docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli generate -i https://bitbucket.org/api/swagger.json --package-name bitbucket -g go -o /local/bitbucket-sdk-go
Every time this command is run it seems to regenerate a lot of the code and swap types round. Sometimes it was added new files.
If you are interested, this is how to replicate:
-
Generate code from open api generator
docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli generate -i https://bitbucket.org/api/swagger.json --package-name bitbucket -g go -o /local/bitbucket-sdk-go
-
Change the directory owner as it's
root
by default.sudo chown -R <user> bitbucket-sdk-go
-
To easily view changes that are being made setup git
cd bitbucket-sdk-go && git init
-
Commit the changes
git add . && git commit -m "init"
-
Run the generator again and you should see loads of files have been updated
Note the output location is going to be in your current directory
-o /local
docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli generate -i https://bitbucket.org/api/swagger.json --package-name bitbucket -g go -o /local
-
Check to see if/what files have changed
git status
I just stumbled across this and currently I'm getting errors when trying to generate the client from the swagger definitions.
swagger generate client -f https://api.bitbucket.org/swagger.json -A bitbucket-cloud-sdk --target pkg/bitbucket/client
validating spec https://api.bitbucket.org/swagger.json
The swagger spec at "https://api.bitbucket.org/swagger.json" is invalid against swagger specification 2.0. see errors :
- definition "team" contains duplicate properties: [team.links]
- definition "pipeline_selector" contains duplicate properties: [pipeline_selector.type]
- definition "user" contains duplicate properties: [user.links]
Has anyone got this working?
Note: I'm using the real swagger as it's the most stable generator I know.
@toneill818 I considered it several times in the past, but I gave up because it was easy to fail to generate from swagger and it was fragile. what about now? I might consider it, but I think it's better for everyone not to adopt it if there is a problem with stability. I would like to consider it again when I have time.
- Ref: https://github.com/ktrysmt/go-bitbucket/issues/96
@Jamess-Lucass @migueleliasweb Thanks for the information.
I spent last 2 days trying different approaches to generate client from their swagger.json (OAS2) or swagger.v3.json (OAS3) with no luck. Even when I manually fixed issues mentioned by @migueleliasweb there are problems on runtime because Atlassian is not updating OAS files immediately when they change API.
That's the saddest part of using Atlassian products in many ways. Very little support and adoption compared to other offerings on the market. 😔