Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
Anonymous
Not applicable

OpenApi document swagger

Hi,

 

@dax  @ImkeF , I have a question

I am loading a swagger.json file using openApi.documet, which is fine.

But if I dont specify the host in swagger.json, the host should be picked up automatically where the swagger.json url is hosted.

 

eg: http://localhost/swagger/api/v2/bi-api.json

 

in the above url, localhost is my host, which i dont want to specify in bi-api.json. so the openapi.document must pick up localhost as the host value automatically, which is how it should work as per swagger -api docs.

 

seer below link for reference:

https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md

 

but its not happening. OpenApi.document throws this error on power bi:

DataSource.Error: Host name is not defined in the Open API document.

 

Any help on priority would be appreciated!

Thanks!

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

@ImkeF Found a solution after various thoughts!

 

read the whole json object from swagger and then append the host dynamically, before passing the json contents to the open API. document.

 

Here's the snippet:

 

swagger = Json.Document(Extension.Contents("swagger.json")),

swaggerRecord = Record.AddField(swagger, "host", biHost), // biHost eg: localhost:80

// OpenApi.Document will return a navigation table apiFunctionTable = OpenApi.Document(Binary.From(Json.FromValue(swaggerRecord)), DefaultOptions)

Thanks!

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

@ImkeF Found a solution after various thoughts!

 

read the whole json object from swagger and then append the host dynamically, before passing the json contents to the open API. document.

 

Here's the snippet:

 

swagger = Json.Document(Extension.Contents("swagger.json")),

swaggerRecord = Record.AddField(swagger, "host", biHost), // biHost eg: localhost:80

// OpenApi.Document will return a navigation table apiFunctionTable = OpenApi.Document(Binary.From(Json.FromValue(swaggerRecord)), DefaultOptions)

Thanks!

ImkeF
Community Champion
Community Champion

Not sure if my understanding is correct, but I fear that this might not be possible, to the static evaluation failing: https://blog.crossjoin.co.uk/2016/08/23/web-contents-m-functions-and-dataset-refresh-errors-in-power...

 

Would be great if you could crack that as well, though 😉

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Helpful resources

Announcements
December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.