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

Generate Client Using Swagger #224

Open
toneill818 opened this issue Sep 22, 2022 · 5 comments
Open

Generate Client Using Swagger #224

toneill818 opened this issue Sep 22, 2022 · 5 comments

Comments

@toneill818
Copy link
Contributor

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?

@Jamess-Lucass
Copy link

Jamess-Lucass commented Nov 12, 2022

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

@migueleliasweb
Copy link

migueleliasweb commented Feb 23, 2023

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.

@ktrysmt
Copy link
Owner

ktrysmt commented Apr 16, 2023

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

@Jamess-Lucass @migueleliasweb Thanks for the information.

@mkyc
Copy link

mkyc commented Aug 24, 2023

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.

@migueleliasweb
Copy link

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

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

No branches or pull requests

5 participants