Skip to content

Use Yaml for parcelgen descriptions #1

@Pretz

Description

@Pretz

I am currently working on a heavy reworking of object descriptions to separate the API specific properties of an object from the application specific properties of an object. In the process I am moving from json to yaml for parcelable descriptions.

For instance, the Business.json included in the example project currently looks like this:

{
    "do_json": true,
    "package": "com.yelp.parcelgen",
    "json_map": {
        "uri": "url",
        "mobileUri": "mobile_url"
    },
    "props": {
        "Uri": [
            "uri",
            "mobileUri"
        ],
        "String": [
            "id",
            "name",
            "imageUrl",
            "phone",
            "displayPhone",
            "ratingImageUrl",
            "ratingImageUrlSmall",
            "snippetText",
            "snippetImageUrl"
        ],
        "int": [
            "reviewCount"
        ],
        "double": [
            "distance"
        ],
        "Location": [
            "location"
        ] 
    }
}

I'd like to change it to the following yaml description, which includes documentation for each property:

Location:
  location: Location data for this business
Float:
  distance: >
      Distance that business is from search location in meters, if a latitude/longitude
      is specified.
  rating: Rating for this business (value ranges from 1, 1.5, ... 4.5, 5)
Integer:
  review_count: Number of reviews for this business
String:
  display_phone: Phone number for this business formatted for display
  id: Yelp ID for this business
  name: Name of this business
  phone: Phone number for this business with international dialing code (e.g. +442079460000)
  snippet_text: Snippet text associated with this business
Url:
  url: URL for business page on Yelp
  image_url: URL of photo for this business
  mobile_url: URL for mobile business page on Yelp
  rating_img_url: URL to star rating image for this business (size = 84x17)
  rating_img_url_large: URL to large version of rating image for this business (size = 166x30)
  rating_img_url_small: URL to small version of rating image for this business (size = 50x10)
  snippet_image_url: URL of snippet image associated with this business

Note that the new yaml description uses the json properties as keys rather than the intended Java property names. Parcelgen will convert from underscore_separated to javaCamelCase when generating Java code.

Additionally, the implementation specific aspects of the parcelable description can be stored in a project level config file which will be used when generating Java code:

Target:
  language: java
  directory: src
  default_package: com.yelp.parcelgen
Config:
  Business:
    implement:
      - Serializable
    rename:
      url: uri
      mobile_url: mobileUri

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions