Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Issue with the generated POJO's #76

Closed
rajkumar1979 opened this issue Apr 25, 2015 · 20 comments
Closed

Issue with the generated POJO's #76

rajkumar1979 opened this issue Apr 25, 2015 · 20 comments

Comments

@rajkumar1979
Copy link

are you following any standard for generating the POJO's from json schema,

My Json schema has a complex object of type

"paymentDetails":{

            "type": "object",
            "description": "Representation for the address associated with the customers payment.",
            "properties": {
                "type": {
                    "type": "string",
                    "description": "The method of payment."
                },
                "attribute": {
                    "type": "array",
                    "description": "Array of name/value pairs that correspond to the attributes required for the method of payment provided.",
                    "items": [
                        {
                            "type": "object",
                            "properties": {
                                "name": {
                                    "type": "string",
                                    "description": "Attribute name for a payment detail element."
                                },
                                "value": {
                                    "type": "string",
                                    "description": "Attribute value for a payment detail element."
                                }
                            },
                            "required": [
                                "name",
                                "value"
                            ]
                        }
                    ]
                },
                "paymentAddress": {
                    "type": "object",
                    "properties": {
                        "addressLine1": {
                            "type": "string",
                            "description": "First address line associated with the payment address"
                        },
                        "addressLine2": {
                            "type": "string",
                            "description": "Optional second address line"
                        },
                        "addressLine3": {
                            "type": "string",
                            "description": "Optional third address line"
                        },
                        "addressLine4": {
                            "type": "string",
                            "description": "Optional fourth address line"
                        },
                        "city": {
                            "type": "string",
                            "description": "Civic location"
                        },
                        "stateOrProvince": {
                            "type": "string",
                            "description": "State or province identifier. In the United States and Canada, this corresponds to a 2 letter code. Optional as not all countries have a sub-national region"
                        },
                        "postalCode": {
                            "type": "string",
                            "description": "Postal code or zip code. "
                        },
                        "country": {
                            "type": "string",
                            "description": "2 character ISO 3166-1 code for country"
                        }
                    },
                    "required": [
                        "addressLine1",
                        "city"
                    ]
                }
            }
        }

When I test the generated POJO's by passing a sample request, it allows an object that does not adhere to this schema.

In the past when we generated objects using JAXB, when we pass an object that does not adhere to an xml schema , jersey considers that as a invalid request, but in this case the request is allowed to pass through.

Example the malformed request that was used is, I had changed the request to use an element called attr which is not there in the schema , but jersey does not validate that.

{
"accountDetails": {
"accountID": "123145631722297",
"accountClassification": "SmallBusiness",
"accountSubClassification": "Regular",
"personaID": "123145631723942",
"authID": "123145631723942"
},
"offerID": "20000000",
"paymentDetails": {
"type": "CreditCard",
"attr": [
{
"name": "nameOnCard",
"value": "John"
},
{
"name": "cardNumber",
"value": "9919930747642032"
},
{
"name": "expirationMonth",
"value": "11"
},
{
"name": "expirationYear",
"value": "2015"
},
{
"name": "cvn",
"value": "123"
}
],
"paymentAddress": {
"addressLine1": "123 main str",
"addressLine2": "APT 122",
"addressLine3": "Near Macdonald",
"addressLine4": "OPP Gas station",
"city": "San Diego",
"stateOrProvince": "CA",
"postalCode": "92122",
"country": "US"
}
}
}

@ddossot
Copy link

ddossot commented Apr 25, 2015

There are two issues.

First, you are allowing extra properties to be added to your object because you miss the following property:

"additionalProperties": false

Add it to your 3 object schemas (ie. paymentDetails, the one under items and paymentAddress.

Second, you use a "required" array instead of a "required" boolean for each property. This has just been added to JsonSchema2Pojo but the RAML->JAX-RS codegen plug-in hasn't been upgraded to 0.4.11 yet.

To fix this issue you can either switch to the draft-3 style of required properties or upgrade JsonSchema2Pojo to 0.4.11 and build and use your own version of the codegen plugin.

@petrochenko-pavel-a Please upgrade JsonSchema2Pojo to 0.4.11 😉

@rajkumar1979
Copy link
Author

Thanks for the feedback on additionalProperties.

How do I upgrade JsonSchema2Pojo ? I am just using the maven plugin to generate the Pojos in maven project.

Could you please share the details.

@petrochenko-pavel-a
Copy link
Contributor

Done, snapshot builds are now using 0.4.11

@rajkumar1979
Copy link
Author

I am using version 1.3.3 because I think we had issues on the one checked in the repository which I believe is the snapshot version.

Could you tell me where can I get the most stable build and what's the version?

@ddossot
Copy link

ddossot commented Apr 26, 2015

@rajkumar1979 Version 1.3.3 is the current stable release. See: http://search.maven.org/#search|ga|1|a%3A%22raml-jaxrs-maven-plugin%22

@rajkumar1979
Copy link
Author

Sorry ,

Its a little confusing.

I am using the version 1.3.3 to generated the raml to jaxrs classes, I thought you fixed 1.3.3 by upgrading to the latest JsonSchematoPojo, I thought you mentioned that you fixed it in the snapshot release,Could you please tell me the snapshot version of the plugin that I can use to generate these artifacts.

@petrochenko-pavel-a
Copy link
Contributor

Generally you need to use 1.3.4-SNAPSHOT. The snapshots are published at
sonatype as well as in mulesoft public repos.

Regards,
Pavel

On Mon, Apr 27, 2015 at 6:35 AM, rajkumar1979 [email protected]
wrote:

Sorry ,

Its a little confusing.

I am using the version 1.3.3 to generated the raml to jaxrs classes, I
thought you fixed 1.3.3 by upgrading to the latest JsonSchematoPojo, I
thought you mentioned that you fixed it in the snapshot release,Could you
please tell me the snapshot version of the plugin that I can use to
generate these artifacts.


Reply to this email directly or view it on GitHub
#76 (comment)
.

@rajkumar1979
Copy link
Author

After updating the 1.3.4-SNAPSHOT, when I print the response it displays the following json
{
"subscriptionID": 100,
"subscriptionState": null,
"offerID": 2220000,
"trialStartDate": null,
"trialEndDate": null,
"subscriptionStartDate": null,
"subscriptionEndDate": null,
"nextBillDate": null,
"effectiveCancellationDate": null,
"entitledProduct": [
{
"entitledProductID": 1,
"productType": null,
"entitledProductState": "ACTIVE",
"additionalProperties": {}
}
],
"additionalProperties": {}
}

I am not sure why its including an element named additionalProperties as part of every object in the response.

@rajkumar1979
Copy link
Author

I also tried to print the request that is being sent and tried to echo the same as response.

input to my service
{
"accountDetails": {
"accountID": "123145631722297",
"accountClassification": "SmallBusiness",
"accountSubClassification": "Regular",
"personaID": "123145631723942",
"authID": "123145631723942"
},
"offerID": "20000000",
"paymentDetails": {
"type": "CreditCard",
"attribute": [
{
"name": "nameOnCard",
"value": "John"
},
{
"name": "cardNumber",
"value": "9919930747642032"
},
{
"name": "expirationMonth",
"value": "11"
},
{
"name": "expirationYear",
"value": "2015"
},
{
"name": "cvn",
"value": "123"
}
],
"paymentAddress": {
"addressLine1": "123 main str",
"addressLine2": "APT 122",
"addressLine3": "Near Macdonald",
"addressLine4": "OPP Gas station",
"city": "San Diego",
"stateOrProvince": "CA",
"postalCode": "92122",
"country": "US"
}
}
}

Output

{
"accountDetails": {
"accountID": "123145631722297",
"accountClassification": "SmallBusiness",
"accountSubClassification": "Regular",
"personaID": "123145631723942",
"authID": "123145631723942",
"additionalProperties": {}
},
"offerID": "20000000",
"paymentDetails": {
"type": "CreditCard",
"attribute": [
{
"name": "nameOnCard",
"value": "John",
"additionalProperties": {}
},
{
"name": "cardNumber",
"value": "9919930747642032",
"additionalProperties": {}
},
{
"name": "expirationMonth",
"value": "11",
"additionalProperties": {}
},
{
"name": "expirationYear",
"value": "2015",
"additionalProperties": {}
},
{
"name": "cvn",
"value": "123",
"additionalProperties": {}
}
],
"paymentAddress": {
"addressLine1": "123 main str",
"addressLine2": "APT 122",
"addressLine3": "Near Macdonald",
"addressLine4": "OPP Gas station",
"city": "San Diego",
"stateOrProvince": "CA",
"postalCode": "92122",
"country": "US",
"additionalProperties": {}
},
"additionalProperties": {}
},
"additionalProperties": {}
}

It adds additionalProperties as part of every object.

this was not hapenning in 1.3.3

@ddossot
Copy link

ddossot commented Apr 28, 2015

What JSON provider do you use with JAX-RS? Jackson?

@rajkumar1979
Copy link
Author

I am using jackson.

Also My json schema does not have addiitonal properties, I tried without that and it still puts those aspart of every object

@ddossot
Copy link

ddossot commented Apr 28, 2015

Very strange, never seen this before. Can you show your latest plugin config and latest JSON schema?

@rajkumar1979
Copy link
Author

I added the plugin

org.raml.plugins
raml-jaxrs-maven-plugin
1.3.4-SNAPSHOT

${basedir}/src/main/resources/raml
com.intuit.platform.webs.subscription
2.0
false
jackson2
true




generate

generate-sources


I added the plugin repository as well

sonatype-public-repository https://oss.sonatype.org/content/groups/public true true

My raml definition
#%RAML 0.8
title: Create Subscription
version: v1
#baseUri: http://corp.intuit.net
#baseUri: http://mocksvc.mulesoft.com/mocks/0cb2e36d-c426-4720-9a0a-a177a3e4ac10
baseUri: http://mocksvc.mulesoft.com/mocks/ca9092b8-c563-43fe-ad7a-2bf20bdc2a27/mocks/0cb2e36d-c426-4720-9a0a-a177a3e4ac10
mediaType: application/json
schemas:

  • subscription: |
    {
    "$schema": "http://json-schema.org/draft-04/schema",
    "type": "object",
    "properties": {
    "subscriptionID": {
    "description": "This is the reference to the offering portfolio instance that the entitled offerings are under",
    "type": "integer"
    },
    "subscriptionState": {
    "description": "Indicates what status the entitled offering is in in terms of whether the customer is paying or is not. It drives what actions a user can take next in terms of changing their offering portfolio. Valid values can include: Trial, Trial Opted-in, Paid, Paid Cancel Pending, In Collection",
    "type": "string"
    },
    "offerID": {
    "description": "This is the unique identifier for the offer",
    "type": "integer"
    },
    "trialStartDate": {
    "description": "Start date of trial",
    "type": "null"
    },
    "trialEndDate": {
    "description": "End date of trial",
    "type": "null"
    },
    "subscriptionStartDate": {
    "description": "Start date of the paid subscription",
    "type": "null"
    },
    "subscriptionEndDate": {
    "description": "End date of the paid subscription",
    "type": "null"
    },
    "nextBillDate": {
    "description": "Date on which this entitled offering will next be billing (i.e. for recurring charges, accumulated usage charges)",
    "type": "null"
    },
    "effectiveCancellationDate": {
    "description": "Date when a cancel auto renew takes effect",
    "type": "null"
    },
    "entitledProduct": {
    "description": "http://jsonschema.net/entitledProduct",
    "type": "array",
    "items": {
    "type": "object",
    "properties": {
    "entitledProductID": {
    "description": "This is the reference to the current entitled product. From this EBP can derive the current offer the customer has and any other related entitled products associated to the current offer",
    "type": "integer"
    },
    "productType": {
    "description": "Product Type used by OII Grant. It is at the same level as the BRM service type. Example: 'QBO', 'Payroll'",
    "type": "string"
    },
    "entitledProductState": {
    "description": "The state for the Entitled Product. Valid values can include: ‘Active’, ‘Inactive’ where means customer only has read-only access, and ‘Closed’ which means no access. ",
    "type": "string"
    }
    }
    }
    }
    },
    "required": [
    "subscriptionID",
    "subscriptionState",
    "offerID",
    "entitledProduct"
    ]
    }

  • subscriptionRequest: |
    {
    "$schema": "http://json-schema.org/draft-04/schema",
    "type": "object",
    "properties": {
    "accountDetails": {
    "type": "object",
    "properties": {
    "accountID": {
    "type": "string",
    "description": "This is the standard Intuit company identifier - it is the same as the customerAccountID."
    },
    "accountClassification": {
    "type": "string",
    "description": "The Account Classification describes the relationship with Intuit that the account has that is being created. As an example in the Accountant-Client use case, the Classification can be one of SmallBusiness or Accountant. This information is important to determine offers, features, or pricing that may be available to the account."
    },
    "accountSubClassification": {
    "type": "string",
    "description": "The Account Sub Classification allows a further categorization of the relationship to Intuit for a given account. As an example in the Accountant-Client use case, the a Sub Classification for SmallBusiness can be Regular or Enterprise. Likewise for Accountant."
    },
    "personaID": {
    "type": "string",
    "description": "_Either personaID or authID is required, with personaID the preferred value (if available)."
    },
    "authID": {
    "type": "string",
    "description": "_authID is required if personaID is not provided. The value would be used in conjunction with the realmID to derive the personaID and associated PII info."
    }
    },
    "required": [
    "personaID",
    "accountID"
    ]
    },
    "offerID": {
    "type": "string",
    "description": "Offer ID representing the offer that the customer is getting."
    },
    "paymentDetails": {
    "type": "object",
    "description": "Representation for the address associated with the customers payment.",
    "properties": {
    "type": {
    "type": "string",
    "description": "The method of payment."
    },
    "attribute": {
    "type": "array",
    "description": "Array of name/value pairs that correspond to the attributes required for the method of payment provided.",
    "items":
    {
    "type": "object",
    "properties": {
    "name": {
    "type": "string",
    "description": "Attribute name for a payment detail element."
    },
    "value": {
    "type": "string",
    "description": "Attribute value for a payment detail element."
    }
    },
    "required": [
    "name",
    "value"
    ]
    }

                },
                "paymentAddress": {
                    "type": "object",
                    "properties": {
                        "addressLine1": {
                            "type": "string",
                            "description": "First address line associated with the payment address"
                        },
                        "addressLine2": {
                            "type": "string",
                            "description": "Optional second address line"
                        },
                        "addressLine3": {
                            "type": "string",
                            "description": "Optional third address line"
                        },
                        "addressLine4": {
                            "type": "string",
                            "description": "Optional fourth address line"
                        },
                        "city": {
                            "type": "string",
                            "description": "Civic location"
                        },
                        "stateOrProvince": {
                            "type": "string",
                            "description": "State or province identifier. In the United States and Canada, this corresponds to a 2 letter code. Optional as not all countries have a sub-national region"
                        },
                        "postalCode": {
                            "type": "string",
                            "description": "Postal code or zip code. "
                        },
                        "country": {
                            "type": "string",
                            "description": "2 character ISO 3166-1 code for country"
                        }
                    },
                    "required": [
                        "addressLine1",
                        "city"
                    ]
                }
            }
        }
    }
    

    }
    /subscription/sign-up:
    displayName: Subscription Signup
    post:
    headers:
    Accept:
    description:
    desc -- do we really need this to be required
    throw error if not provided, or unsupported media type
    type: string
    required: true
    example: example

    Authorization:
      description:
        desc
        throw error if not provided
      type: string
      required: true
      example: Intuit_IAM_Authentication intuit_token_type="IAM-Ticket",intuit_realmid="50000003",intuit_appid="Intuit.cto.api.gateway.simulator.test",intuit_token="V1-65-Q3y8elbiw74j5wdna2cei5",intuit_userid="100186433"
    
    Content-Type:
      description:
        here is the description
        throw error if not provided
      type: string
      required: true
      example: application/json; charset=utf-8
    
    User-Agent:
      description:
        des
      type: string
      required: false
      example: curl/7.30.0
    
    intuit_originatingip:
      description: des
        throw error if not provided
      type: string
      required: true
      example: 100.100.10.1
    
    intuit_webs_transaction_datetime:
      description: des
        in prod, set to current date time
        in pre-prod and the time-based testing flag is set to true, propagate date time if passed in, otherwise set to current date time
        in pre-prod with time-based testing flag set to false, set to current date time
      type: string
      required: false
      example: sss
    
    intuit_locale:
      description: 
        Here is the description for the header. 
        throw error if not provided
      type: string 
      required: true
      minLength: 5
      maxLength: 5
      example: en_US
    
    intuit_tid:
      description:
        desc
        throw error if not provided
      type: string
      required: true
      example: gw-7f501242-b7ab-43e7-a862-93027855347f
    
    intuit_assetalias:
      description: desc
        throw error if not provided
      type:  string
      required: true
      example: Intuit.cto.gateway-fabric.8
    
    intuit_assetid:
      description: desc
        throw error if not provided
      type: integer
      required: true
      example: 5189290262823711479
    

    description: Create Subscription API
    body:
    schema: subscriptionRequest
    example: |
    {
    "accountDetails": {
    "accountID": "123145631722297",
    "accountClassification": "SmallBusiness",
    "accountSubClassification": "Regular",
    "personaID": "123145631723942",
    "authID": "123145631723942"
    },
    "offerID": "20000000",
    "paymentDetails": {
    "type": "CreditCard",
    "attribute": [
    {
    "name": "nameOnCard",
    "value": "John"
    },
    {
    "name": "cardNumber",
    "value": "9919930747642032"
    },
    {
    "name": "expirationMonth",
    "value": "11"
    },
    {
    "name": "expirationYear",
    "value": "2015"
    },
    {
    "name": "cvn",
    "value": "123"
    }
    ],
    "paymentAddress": {
    "addressLine1": "123 main str",
    "addressLine2": "APT 122",
    "addressLine3": "Near Macdonald",
    "addressLine4": "OPP Gas station",
    "city": "San Diego",
    "stateOrProvince": "CA",
    "postalCode": "92122",
    "country": "US"
    }
    }
    }
    responses:
    201:
    body:
    schema: subscription
    example: |
    {
    "subscriptionID": 55245,
    "subscriptionState": "Paid",
    "offerID": 20000014,
    "trialStartDate": null,
    "trialEndDate": null,
    "subscriptionStartDate": null,
    "subscriptionEndDate": null,
    "nextBillDate": null,
    "effectiveCancellationDate": null,
    "entitledProduct": [
    {
    "entitledProductID": 55244,
    "productType": "Intuit.sbe.salsa.default",
    "entitledProductState": "Active"
    }
    ]
    }

@rajkumar1979
Copy link
Author

Schema Definition that I used

{
"$schema": "http://json-schema.org/draft-04/schema",
"type": "object",
"properties": {
"accountDetails": {
"type": "object",
"properties": {
"accountID": {
"type": "string",
"description": "This is the standard Intuit company identifier - it is the same as the customerAccountID."
},
"accountClassification": {
"type": "string",
"description": "The Account Classification describes the relationship with Intuit that the account has that is being created. As an example in the Accountant-Client use case, the Classification can be one of SmallBusiness or Accountant. This information is important to determine offers, features, or pricing that may be available to the account."
},
"accountSubClassification": {
"type": "string",
"description": "The Account Sub Classification allows a further categorization of the relationship to Intuit for a given account. As an example in the Accountant-Client use case, the a Sub Classification for SmallBusiness can be Regular or Enterprise. Likewise for Accountant."
},
"personaID": {
"type": "string",
"description": "_Either personaID or authID is required, with personaID the preferred value (if available)."
},
"authID": {
"type": "string",
"description": "_authID is required if personaID is not provided. The value would be used in conjunction with the realmID to derive the personaID and associated PII info."
}
},
"required": [
"personaID",
"accountID"
]
},
"offerID": {
"type": "string",
"description": "Offer ID representing the offer that the customer is getting."
},
"paymentDetails": {
"type": "object",
"description": "Representation for the address associated with the customers payment.",
"properties": {
"type": {
"type": "string",
"description": "The method of payment."
},
"attribute": {
"type": "array",
"description": "Array of name/value pairs that correspond to the attributes required for the method of payment provided.",
"items":
{
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "Attribute name for a payment detail element."
},
"value": {
"type": "string",
"description": "Attribute value for a payment detail element."
}
},
"required": [
"name",
"value"
]
}

                },
                "paymentAddress": {
                    "type": "object",
                    "properties": {
                        "addressLine1": {
                            "type": "string",
                            "description": "First address line associated with the payment address"
                        },
                        "addressLine2": {
                            "type": "string",
                            "description": "Optional second address line"
                        },
                        "addressLine3": {
                            "type": "string",
                            "description": "Optional third address line"
                        },
                        "addressLine4": {
                            "type": "string",
                            "description": "Optional fourth address line"
                        },
                        "city": {
                            "type": "string",
                            "description": "Civic location"
                        },
                        "stateOrProvince": {
                            "type": "string",
                            "description": "State or province identifier. In the United States and Canada, this corresponds to a 2 letter code. Optional as not all countries have a sub-national region"
                        },
                        "postalCode": {
                            "type": "string",
                            "description": "Postal code or zip code. "
                        },
                        "country": {
                            "type": "string",
                            "description": "2 character ISO 3166-1 code for country"
                        }
                    },
                    "required": [
                        "addressLine1",
                        "city"
                    ]
                }
            }
        }
    }
   }

@petrochenko-pavel-a
Copy link
Contributor

Hi, I have no bandwidth right now, but promise to dedicate time in nearest days probably Friday or Satarday to dig deep into this.

@ddossot
Copy link

ddossot commented Apr 28, 2015

@rajkumar1979 Your comments are unreadable. Can you please format them?

Also, I don't see additionalProperties in your JSON Schema.

@rajkumar1979
Copy link
Author

I dont have additionalProperties in my schema, thats why I am surprised as why it gets included in the response.

How can I attach a file to this?

@ddossot
Copy link

ddossot commented Apr 28, 2015

If you do not have additionalProperties set to false in your schema, you will get the additionalProperties catch-all field.

You can not attach files: edit your previous comments and format them with Markdown (see https://help.github.com/articles/github-flavored-markdown/ for syntax).

@rajkumar1979
Copy link
Author

Hi ,

The Key was additionalProperties, I set it to false and it works now.

Thanks for all the help and assistance.

Thanks

Raj.

@gr423
Copy link

gr423 commented Aug 13, 2018

Hi ,

I do face the same issue .
The required fields are not marked with required annotation, and hence it is accepting the payload without mandatory fields , which is not expected.
Please could help me here.

<plugin>
<groupId>org.raml.jaxrs</groupId>
<artifactId>raml-to-jaxrs-maven-plugin</artifactId>
	<version>3.0.1</version>
	<executions>
	<execution>
	<id>GenerateAdminV2</id>
	<goals>
		<goal>generate</goal>
			</goals>
			<phase>generate-sources</phase>
			<configuration>
							<ramlFile>${basedir}/src/main/resources/raml/v1/MAS_api.raml</ramlFile>
							<resourcePackage>com.nagra.opentv.mas.v1.resource</resourcePackage>
<modelPackage>com.some.st.mas.v1.model</modelPackage>
<removeOldOutput>true</removeOldOutput>
	<generateTypesWith>
		<value>jackson2</value>
   </generateTypesWith>
<jsonMapperConfiguration>
	<includeToString>true</includeToString>
</jsonMapperConfiguration>
</configuration>
</execution>
</executions>
</plugin>

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants