External Service stubs not being created

Issue #2300 resolved
Adam Stepanek created an issue

Hi Scott,

based on swagger documentation, section Common Parameters in Different Paths, it is possible to have parameters defined in the top level of each path. Thus, this json swagger is accepted by Salesforce in the External Services Definition.

...
        },
        "/rest/asset/v1/channel/byName.json": {
            "parameters": [
                {
                    "$ref": "#/parameters/AuthorizationToken"
                }
            ],
            "get": {
...

But unfortunately the OST won’t be generated for such external service definition.

This is the output from debug log.

2023-01-04 12:14:02,191 [3173813]   FINE - #com.illuminatedcloud.symtab.ExternalServiceApexClassAdapter - Failed to adapt the following external service into an Apex class:
{
    "swagger": "2.0",
    ... removed for clarity
}
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 73 column 28 path $.paths..
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:270)
    at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:41)
    at com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter.read(MapTypeAdapterFactory.java:186)
    at com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter.read(MapTypeAdapterFactory.java:144)
    at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:41)
    at com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter.read(MapTypeAdapterFactory.java:186)
    at com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter.read(MapTypeAdapterFactory.java:144)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:161)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:266)
    at com.google.gson.Gson.fromJson(Gson.java:1058)
    at com.google.gson.Gson.fromJson(Gson.java:1016)
    at com.google.gson.Gson.fromJson(Gson.java:959)
    at com.google.gson.Gson.fromJson(Gson.java:927)
    at com.illuminatedcloud.symtab.ExternalServiceApexClassAdapter.adapt(SourceFile:107)
    at com.illuminatedcloud.symtab.ExternalServiceApexClassAdapter.adaptExternalService(SourceFile:81)
    at com.illuminatedcloud.symtab.OfflineSymbolTable.lambda$loadExternalServiceClasses$36(SourceFile:4157)
    at com.illuminatedcloud.symtab.OfflineSymbolTable.runActivity(SourceFile:722)
    at com.illuminatedcloud.symtab.OfflineSymbolTable.runActivity(SourceFile:754)
    at com.illuminatedcloud.symtab.OfflineSymbolTable.loadExternalServiceClasses(SourceFile:4138)
    at com.illuminatedcloud.symtab.OfflineSymbolTable.generateOfflineSymbolTable(SourceFile:956)
    at com.illuminatedcloud.intellij.settings.project.OfflineSymbolTableGenerator$2.run(SourceFile:222)
    at com.intellij.openapi.progress.impl.CoreProgressManager.startTask(CoreProgressManager.java:423)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.startTask(ProgressManagerImpl.java:114)
    at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcessWithProgressAsynchronously$6(CoreProgressManager.java:474)
    at com.intellij.openapi.progress.impl.ProgressRunner.lambda$submit$3(ProgressRunner.java:252)
    at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:188)
    at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeProcessUnderProgress$13(CoreProgressManager.java:589)
    at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:664)
    at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:620)
    at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:588)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:60)
    at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:175)
    at com.intellij.openapi.progress.impl.ProgressRunner.lambda$submit$4(ProgressRunner.java:252)
    at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:702)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:699)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:699)
    at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 73 column 28 path $.paths..
    at com.google.gson.stream.JsonReader.beginObject(JsonReader.java:395)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:259)
    ... 40 more
2023-01-04 12:14:02,192 [3173814]   INFO - #com.illuminatedcloud.intellij.settings.project.OfflineSymbolTableGenerator - Completed activity Loading external services in 125 ms.

Looks like the ExternalServiceApexClassAdapter does not allow array of objects in the “parameters” section.

Comments (8)

  1. Scott Wells repo owner

    Thanks for attaching the service definition, Adam. I imagine it’s just something simple with IC2’s assumptions about how these documents should deserialize when generating the OST. I won’t get a chance to look at this until the beginning of next week, but hopefully it should be trivial to reproduce and fix for the next official build. I’ll keep you posted on progress here.

  2. Scott Wells repo owner

    Nothing to report yet. This week was spent readying Python support for Salesforce Functions which was released yesterday. This is already slotted into my TODO list for early next week. I’ll let you know what I find.

  3. Scott Wells repo owner

    FYI, this has been fixed for inclusion in the next build (likely Thursday morning):

  4. Scott Wells repo owner

    Delivered in 2.2.5.4. You'll need to regenerate your OST after updating. Please let me know if you see any issues with the generated stubs for any and all registered external services now.

  5. Scott Wells repo owner

    Very glad to hear that. As stated in the release notes, there’s not a first-class API for retrieving the Salesforce-generated stubs. I’ve spoken with them about that and hopefully it’ll be addressed at some point in the near future, but right now I’m using a bit of a hack to get them. My guess is that it will be just fine for the required interim period until a real API is offered, but if you do see it start to act improperly, please let me know.

  6. Log in to comment