Happy Business Starts Here

Valued Scholar

Error generating java code library from Zuora OpenAPI Spec

Hi,

 

I used following command to generate java-library from Zuora OpenAPI spec:

curl -X POST -H "Content-Type: application/json" -d '{"swaggerUrl":"https://assets.zuora.com/zuora-documentation/swagger.yaml"}' https://generator.swagger.io/api/gen/clients/java

 

When I am trying to run mvn build for generated library, I am getting following compilation error:

[ERROR] /Users/rkotecha/temp/java-client/src/main/java/io/swagger/client/model/SubscriptionProductFeatureObjectCustomFields.java:[19,31] cannot find symbol

[ERROR]   symbol:   class ERRORUNKNOWN

[ERROR]   location: package io.swagger.client.model

[ERROR] /Users/rkotecha/temp/java-client/src/main/java/io/swagger/client/model/SubscriptionProductFeatureObjectCustomFields.java:[28,83] cannot find symbol

[ERROR]   symbol: class ERRORUNKNOWN

 

Can someone help me with this? Am I missing anything here?

 

Tags (2)
6 REPLIES 6
Zuora Documentation

Re: Error generating java code library from Zuora OpenAPI Spec

Hi @Ridhima, thanks for posting about this issue.

 

It looks like the issue you are seeing may be similar to a previously-known issue with generated Java libraries. Please see this post for a potential workaround:

https://community.zuora.com/t5/Developers/Java-SDK/gpm-p/23662/highlight/true#M130

 

We will do further investigation and get back to you.

Zuora Documentation

Re: Error generating java code library from Zuora OpenAPI Spec

Hi @Ridhima,

 

After further investigation, it looks like swagger-codegen is not handling additionalProperties blocks correctly. In the Zuora OpenAPI spec, there are several additionalProperties blocks that look like this:

 

    additionalProperties:
      description: 'Custom fields of the Subscription Product Feature object. The
        name of each custom field has the form <code>*customField*__c</code>. Custom
        field names are case sensitive. See [Manage Custom Fields](https://knowledgecenter.zuora.com/BB_Introducing_Z_Business/Manage_Custom_Fields)
        for more information.

        '

 

These additionalProperties blocks do not have a type specified, which is causing swagger-codegen to insert ERRORUNKNOWN into the corresponding Java classes. For example:

 

public class SubscriptionProductFeatureObjectCustomFields extends HashMap<String, ERRORUNKNOWN>

 

Instead, I believe that the classes should extend HashMap<String, Object>.

 

It should be possible to work around this issue by modifying the OpenAPI spec, adding type: object inside every additionalProperties block that doesn't have a type specified. Like this:

 

    additionalProperties:
      type: object
      description: 'Custom fields of the Subscription Product Feature object. The
        name of each custom field has the form <code>*customField*__c</code>. Custom
        field names are case sensitive. See [Manage Custom Fields](https://knowledgecenter.zuora.com/BB_Introducing_Z_Business/Manage_Custom_Fields)
        for more information.

        '

 

For convenience, I have created a test spec that includes this workaround:

https://raw.githubusercontent.com/davidwzuora/swagger-codegen-test/master/zuora-swagger-2019-03-27-j...

 

Please can you try this spec instead of https://assets.zuora.com/zuora-documentation/swagger.yaml and let me know the outcome?

Highlighted
Valued Scholar

Re: Error generating java code library from Zuora OpenAPI Spec

This is working for me! Thanks for your help David!

Will https://assets.zuora.com/zuora-documentation/swagger.yaml be updated to reflect the same? 

 

More suggestions for swagger:

Can we add "reasons" and "processId" to "CommonResponseType", this will help us log issues with our response objects.

Zuora Documentation

Re: Error generating java code library from Zuora OpenAPI Spec

Hi again @Ridhima,

 

After further investigation into your issue, it seems like there's a regression in swagger-codegen that's causing the issue. We have logged the issue with the swagger-codegen developers (here) and are now providing a separate Swagger spec that has the workaround applied:

https://assets.zuora.com/zuora-documentation/swagger-codegen-workaround.yaml

 

Please use this spec instead of the test spec I sent previously.

 

At this time, we don't plan to update https://assets.zuora.com/zuora-documentation/swagger.yaml with the workaround.

 

Regarding your request about CommonResponseType - I've logged this request internally so that our Documentation team can investigate. The internal reference number is DOC-2534.

Zuora Documentation

Re: Error generating java code library from Zuora OpenAPI Spec

Hi @Ridhima,

 

It appears that the swagger-codegen developers have fixed the ERRORUNKNOWN issue in the latest version of swagger-codegen 2.x (version 2.4.5). So you should now be able to use this Swagger file without any modifications:

https://assets.zuora.com/zuora-documentation/swagger.yaml

 

Please let us know if you still experience any errors.

 

Thanks!

David

Zuora Documentation

Re: Error generating java code library from Zuora OpenAPI Spec

Hi @Ridhima , 

 

We have added the reasons and processId to CommonResponseType in the yaml file since version 2019-05-08. See https://www.zuora.com/developer/api-reference/

 

You can refer to the API changelog for the affected 200 response schemas. 

 

Yingying