apiops icon indicating copy to clipboard operation
apiops copied to clipboard

APIOps Publisher adding the BaseUrl value to WebService Url if it is empty

Open rohit3d2003 opened this issue 2 years ago • 14 comments

Release version

APIOps v 3.0.1

Describe the bug

I have an API where Webservice URL is left empty and we are using 'set-backend-service' policy to add the backend dynamically. When we deploy the artifacts where apiInformation.json does not have 'serviceUrl' property, publisher is automatically using 'BaseUrl' value and adding it to 'Webservice Url' post deployment

Expected behavior

WebService url should be left empty

Actual behavior

Value from BaseUrl is assigned to Webservice url making both fields have the same value

Reproduction Steps

  1. Create a API
  2. Leave Webservice URL blank
  3. Run extractor and it will bring apiInformation.json with 'serviceUrl' property
  4. Run publisher and see the value of base url is now assigned to Webservice url

rohit3d2003 avatar Dec 09 '22 03:12 rohit3d2003

@rohit3d2003 - thanks, I was able to reproduce the behavior. Looks like the APIM REST API sets things to the base URL if you don't explicitly pass a null service URL.

Is that causing any issues for you? I would expect the set-backend-service policy to still override things correctly.

In any case, we'll have the extractor explicitly set serviceUrl: null if you don't pass a Web Service URL.

guythetechie avatar Dec 09 '22 16:12 guythetechie

@guythetechie - It's not causing an issue for us but my team members got confused seeing this on the portal. Love to have it fixed

rohit3d2003 avatar Dec 09 '22 17:12 rohit3d2003

It unfortunately looks like this behavior is by design in APIM. Our tool just provides an abstraction layer over the APIM REST APIs. We won't try to change their behavior.

Here's how to manually reproduce it:

  1. Create an API without a web service URL. image

  2. Export the API's specification file. image

  3. The generated specification file will include the server's base URL. image

  4. Import the generated specification file. image

  5. Once the import is complete, the API has the base service URL as its web service URL. image

guythetechie avatar Dec 18 '22 01:12 guythetechie

I noticed this issue after promoting to our QA environment. The Dev url is showing up in QA because it comes from the openAPI spec which is added by Azure APIM. Fortunately it can be overridden using a publish configuration (see below), but this issue is annoying because the backend url was already provided via a backend and now it needs to be specified in two places that are under control of two different teams. Rather than deal with that I removed the backend and am just specifying the backend url via the following:

apis:
- name: my-api-name
  properties:
    serviceUrl: https://my-api-backend-url

nathan-j-nd avatar Apr 11 '23 23:04 nathan-j-nd

why can't we use an empty string in the above sample? @waelkdouh / @nathan-j-nd

apis:
- name: my-api-name
  properties:
    serviceUrl: none, null, '' or ""

APIM Supports empty Web Service URL, manually you could remove it and save it, but when I am running the pipeline, it doesn't publish the changes, stating the error that the value for serviceUrl is invalid

vinilka8 avatar Dec 06 '23 20:12 vinilka8

@waelkdouh / @nathan-j-nd - any updates on this ticket?

vinilka8 avatar Feb 09 '24 01:02 vinilka8

Also interested in this.

validis-ad avatar Mar 05 '24 15:03 validis-ad

@waelkdouh / @nathan-j-nd - any updates on this ticket?

vinilka8 avatar Jun 11 '24 20:06 vinilka8

Just to be clear this is an open source project. Do you are opening an issue and not a ticket and this we can't give you any timelines. We are currently busy with v6 release. We will get to this issue when we get time.

waelkdouh avatar Jun 11 '24 21:06 waelkdouh

Will investigate. We might be reading serviceUrl: null as serviceUrl: "null" in configuration.

guythetechie avatar Jul 05 '24 17:07 guythetechie

following

zcarroll4 avatar Jul 23 '24 21:07 zcarroll4

subscribing

jaliyaudagedara avatar Aug 08 '24 04:08 jaliyaudagedara

@guythetechie Could this be because of JsonIgnore?

[JsonPropertyName("serviceUrl")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public string? ServiceUrl { get; init; }

jaliyaudagedara avatar Aug 08 '24 18:08 jaliyaudagedara

We've run into this issue and I have attempted a workaround but seem to still be running into issues. The extractor seems to omit serviceUrl if it is empty in API Management.

I used a bash script with this to check for the missing property and set it to null:

if ! $(yq '.properties | has("serviceUrl")' apiInformation.json); then
  yq -i '.properties.serviceUrl = null' apiInformation.json
fi

I confirmed that apiInformation.json is getting updated as I expected:

{
  "properties": {
    "path": "test",
    "apiRevision": "1",
    "authenticationSettings": {},
    "description": "",
    "isCurrent": true,
    "displayName": "Test",
    "protocols": [
      "https"
    ],
    "subscriptionKeyParameterNames": {
      "header": "Ocp-Apim-Subscription-Key",
      "query": "subscription-key"
    },
    "subscriptionRequired": false,
    "serviceUrl": null
  }
}

The APIOps publisher still exhibits the behaviour of setting "Web service URL" to the value of "Base URL" when publishing an API with serviceUrl: null.

I have resorted to setting a dummy value for serviceUrl to prevent this as the dev URL showing up in our test environment is causing unnecessary confusion as we onboard teams to the APIOps workflow.

gentlestfoot avatar Mar 06 '25 15:03 gentlestfoot