Use Azure Devops Git Api to view UML file in browser

456 views Asked by At

In our team, we follow the docs-as-code approach, and have some plantUML files in our git repository, which is hosted by an azure devops server (i.e., on premise). Now we want to serve the UML diagrams as hyperlinks on another website. The idea is that if the users browse with chrome, and have the plantUML viewer extension installed, they can view the diagram in the browser by clicking on the link.

We use the REST API for interacting with the git repository as follows:

https://tfs.contoso.com/tfs/DefaultCollection/foo/_apis/git/repositories/bar/Items?path=%2Fdocs%2Fdiagram%2FContainerDiagram.uml&versionDescriptor%5BversionOptions%5D=0&versionDescriptor%5BversionType%5D=0&versionDescriptor%5Bversion%5D=develop&download=false&resolveLfs=true&api-version=5.0-preview.1

Here of course tfs.contoso.com is replaced with our azure devops server host, foo with the id or name of the team project and bar with the id or name of the repository.

Unfortunately, Chrome downloads the file instead of displaying it in the browser. My guess is that the extension, although installed, does not get a chance to render the content. How can I achieve that the content gets displayed instead of downloaded?

1

There are 1 answers

1
Leo Liu On BEST ANSWER

Use Azure Devops Git Api to view UML file in browser

I will get the same result "Chrome downloads the file instead of displaying it in the browser" if I use the same REST API Items - Get as you.

To resolve this issue, please try to use the REST API Source Providers - Get File Contents:

GET https://dev.azure.com/{organization}/{project}/_apis/sourceProviders/{providerName}/filecontents?&repository={repository}&commitOrBranch={commitOrBranch}&path={path}&api-version=5.0-preview.1

Note:

  • Skipping serviceEndpointId.
  • For providerName. In short, you could use TfsGit. You could got this value from the list of source providers.

You could refer this answer for some more details.

My test result:

enter image description here