go-bitbucket icon indicating copy to clipboard operation
go-bitbucket copied to clipboard

Generate Client Using Swagger

Open toneill818 opened this issue 2 years ago • 5 comments

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?

toneill818 avatar Sep 22 '22 15:09 toneill818

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:

  1. 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
    
  2. Change the directory owner as it's root by default.

    sudo chown -R <user> bitbucket-sdk-go
    
  3. To easily view changes that are being made setup git

    cd bitbucket-sdk-go && git init
    
  4. Commit the changes

    git add . && git commit -m "init"
    
  5. 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
    
  6. Check to see if/what files have changed

    git status
    

Jamess-Lucass avatar Nov 12 '22 01:11 Jamess-Lucass

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.

migueleliasweb avatar Feb 23 '23 11:02 migueleliasweb

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

ktrysmt avatar Apr 16 '23 21:04 ktrysmt

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.

mkyc avatar Aug 24 '23 09:08 mkyc

That's the saddest part of using Atlassian products in many ways. Very little support and adoption compared to other offerings on the market. 😔

migueleliasweb avatar Aug 24 '23 09:08 migueleliasweb