question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Publishing OpenAPI v3 JSON fails - publishing the same specifications in YAML works

See original GitHub issue

Release version

4.1.0

Describe the bug

In my APIM lab I have a sample API called Echo API. I exported the API through the Azure Portal and chose the OpenAPI v3 JSON format, deleted the API and tried to publish the API with APIOps through a pipeline in Azure DevOps. I get an error message in the pipeline. See below for details.

If I try the same thing, but choosing to export OpenAPI v3 YAML and publishing with APIOps, it works.

If I try to import the JSON file to APIM through Azure Portal the import works as expected.

Expected behavior

APIOps should treat JSON and YAML the same.

Actual behavior

When trying to publish the API with the JSON file, the publisher gives the following error in the pipeline (resource names replaced with ***):

crit: Publisher[0]
      System.Net.Http.HttpRequestException: HTTP request to URI https://management.azure.com/subscriptions/***/resourceGroups/***/providers/Microsoft.ApiManagement/service/***/apis/echo-api?api-version=2022-04-01-preview&asyncId=6411cd42217d200cac3f6dff&asyncCode=201 failed with status code 400. Content is '{"error":{"code":"ValidationError","message":"One or more fields contain incorrect values:","details":[{"code":"ValidationError","target":"path","message":"'path' must not be empty."}]}}'.
         at common.HttpPipelineExtensions.Validate(Response response, Uri requestUri)
         at common.HttpPipelineExtensions.WaitForLongRunningOperation(HttpPipeline pipeline, Response response, CancellationToken cancellationToken)
         at common.HttpPipelineExtensions.PutResource(HttpPipeline pipeline, Uri uri, JsonObject resource, CancellationToken cancellationToken)
         at publisher.Program.<>c__DisplayClass12_0.<<GetPutRestResource>b__0>d.MoveNext()
      --- End of stack trace from previous location ---
         at publisher.Api.PutApi(ApiName apiName, ApiInformationFile apiInformationFile, ApiSpecificationFile specificationFile, JsonObject configurationApiJson, ServiceUri serviceUri, PutRestResource putRestResource, ILogger logger, CancellationToken cancellationToken)
         at publisher.Api.<>c__DisplayClass23_0.<<ProcessArtifactsToPut>b__4>d.MoveNext()
      --- End of stack trace from previous location ---
         at System.Threading.Tasks.Parallel.<>c__50`1.<<ForEachAsync>b__50_0>d.MoveNext()
      --- End of stack trace from previous location ---
         at common.IEnumerableExtensions.ForEachParallel[T](IEnumerable`1 enumerable, Func`2 action, CancellationToken cancellationToken)
         at publisher.Api.ProcessArtifactsToPut(IReadOnlyCollection`1 files, JsonObject configurationJson, ServiceDirectory serviceDirectory, ServiceUri serviceUri, PutRestResource putRestResource, ILogger logger, CancellationToken cancellationToken)
         at publisher.Service.ProcessArtifactsToPut(IReadOnlyCollection`1 files, JsonObject configurationJson, ServiceDirectory serviceDirectory, ServiceUri serviceUri, ListRestResources listRestResources, PutRestResource putRestResource, DeleteRestResource deleteRestResource, ILogger logger, CancellationToken cancellationToken)
         at publisher.Publisher.ProcessCommitIdFilesToPut(IReadOnlyCollection`1 commitIdFilesToPut, CancellationToken cancellationToken)
         at publisher.Publisher.RunWithCommitId(CommitId commitId, CancellationToken cancellationToken)
         at publisher.Publisher.Run(CancellationToken cancellationToken)
         at publisher.Publisher.ExecuteAsync(CancellationToken cancellationToken)
info: Microsoft.Hosting.Lifetime[0]
      Application is shutting down...
fail: Microsoft.Extensions.Hosting.Internal.Host[9]
      BackgroundService failed

When formatting the error message from the text above it’s a bit more readable:

{
  "error": {
    "code": "ValidationError",
    "message": "One or more fields contain incorrect values:",
    "details": [
      {
        "code": "ValidationError",
        "target": "path",
        "message": "'path' must not be empty."
      }
    ]
  }
}

Reproduction Steps

Try to publish the following file JSON file: https://gist.github.com/robertbrandso/01d5a5f40876956b24a2b191357eb368

Try to publish the following YAML file: https://gist.github.com/robertbrandso/01bb4c3ec776dfe64788aea17bddbef1

The following apiInformation.json were used: https://gist.github.com/robertbrandso/62dd66880a35d9d8f88b53f2a57ef981

Issue Analytics

  • State:closed
  • Created 6 months ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
waelkdouhcommented, May 24, 2023

@waelkdouh @guythetechie I wasn’t sure on how to reach you, so I’ll try to post it here as it is partly related on what we discussed in the thread.

Just wanted to let you know I have created an alternative APIOps, which is declarative, highly inspired by your APIOps project🙂 Thank you for great inspiration. Feel free check it out here:

https://github.com/robertbrandso/terraform-azurerm-apim-apiops/wiki

Just a slight correction. Can you please update your repository to state that the APIOPS is actually created as an open source project by people who happen to work at Microsoft and it’s by no means supported by the product team.

0reactions
robertbrandsocommented, May 24, 2023

@waelkdouh @guythetechie I wasn’t sure on how to reach you, so I’ll try to post it here as it is partly related on what we discussed in the thread.

Just wanted to let you know I have created an alternative APIOps, which is declarative, highly inspired by your APIOps project🙂 Thank you for great inspiration. Feel free check it out here:

https://github.com/robertbrandso/terraform-azurerm-apim-apiops/wiki

Read more comments on GitHub >

github_iconTop Results From Across the Web

OpenAPI file wrongly interpreted as json · Issue #7488
I was writing an openapi schema in yaml and when I tried to use path templating suddenly it was giving me json parsing...
Read more >
OpenAPI 3.0 Tutorial | SwaggerHub Documentation
In this tutorial, we will guide you through building a simple API while covering all the important aspects of the OpenAPI Specification.
Read more >
OpenAPI Specification v3.1.0 | Introduction, Definitions, & ...
An OpenAPI document that conforms to the OpenAPI Specification is itself a JSON object, which may be represented either in JSON or YAML...
Read more >
Open API with separate files not working properly : IDEA-284305
Hi. When defining an Open API specification for a given API in YAML using different files using $ref (as per ...
Read more >
WebApi Core / Swagger: "failed to load API definition" error
The dev tools in Edge was showing me that it was trying to access swagger.json but it was getting an HTTP 500 error....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found