Skip to content

This is a project I'm going to make generator Objective-C entities and services described in WADL file.

License

Notifications You must be signed in to change notification settings

dzhurov/wadl2objc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wadl2objc

This is console tool for generating Objective-C code based on WADL and XSD protocols files About WADL

Install

Build

To build and run the project you need:

  1. Clone the project git clone https://github.com/dzhurov/wadl2objc
  2. Prepare your .wadl and .xsd files
  3. In the schema settings set related path to .wadl and .xsd files Schema settings

Use binary

To use ready build you need copy Build Folder whenever you whant. There are no gem or any package management, so I'd advice you to add wadl2objc folder insied your target project folder to make it available to all contributors of your project. Also it would be nice to add some generateObjCSources.sh file somwhere in repo. Up to you.

Usage

First of all you need to provide output dir path using parameter: --output-dir:. There are two options to provide .wadl and .xsd files

Use local files

In this case use two parameters --xsd: and --wadl: with related paths to .wadl and .xsd files.

Use remote files

In this case use parameters: --wadlURL: and --xsdURL: with URLs to needed files.

What you get

Base classes:

  • XSDBaseEntity class. Is a Base Entity class wich has implemented:
    • NSCopying protocol for all inheritors including copying of machine classes properties
    • Mapping from/to NSDictionary and NSArray<NSDictionary*>
    • Default NSDateFormatters for xs:date and xs:dateTime
    • Setting NSDictionary without loosing existing human class data
  • WADLAbstractServerAPI abstract singleton class.
    • This class will handle all generated services. You'll be able to access services as static methods, like this: [MyServerAPI.someService doSomethingWithCompletion:...]
    • And that is it. This class has has minimum implementation. And requires implementation in child class. Main requirement for inheritor is confirmation of protocol WADLServerAPIInheritor and implementation of -makeRequest:resource:forURLPath:queryParameters:bodyObject:HTTPHeaderParameters:outputClass:responseBlock: method, wich should do a real work. It gives you freedom to implement server interaction using any instruments you'd like (AFNetworking, NSURLSession, etc.)
  • WADLServicesResource base class for service containder.
  • WADLRequestTask defines macro WADLRequestTask wich is associates with request operation. By default is NSURLSessionTask*. It has flexibility to change on any class (RACSignal, AFHTTPRequestOperation, etc.)
  • XSDTypes — there are two fake classes to determine different xsd types: xs:date and xs:dateTime

What will be generated:

  • All Data Transfer Objects. Every entity implemented by two classes Human and Machine classes. Inspired by mogenerator

    • Human class inherits from Machine class, generates only once and never overrides. It's a best place for custom logic and handling setters.
    • Machine class inherits from XSDBaseEntity or another Dtat Transfer Object if hierarchy described in XSD file. It's name has "_" prefix. It has list of properties reflects fields from xsd object. Also will be generated implementations of methods: +mappedKeys, +enumNameForMappedField:, +classNameOfMembersForMappedField:
  • Services classes — WADLServicesResource inheritor. It contains a number of requests joined by first url path. For instance we have four requests:

    • /auth
    • /auth/manager
    • /customer
    • /customer/search

    For those requests will be generated two Services:

    • WADLAuthService
    • WADLCustomerService

    You can access them by your WADLAbstractServerAPI inheritor: [MyServerAPI.auth authenticateUser:user withResponseBlock:^(AuthUserDto *response, NSError *error) {}]

  • Enums. You will get all enums declared in .xsd file in Objective-C style. All enums located in [XSDEnums.h](wadl2objc/wadl2objc/Resources/XSDEnums_h. It also contains two static methods for mapping server enums to client ObjC scalar values and reverse: +enumValueForObject:enumName:, +objectForEnumValue:enumName:.

  • APIConsts — there are all requests url path templates. E.g.:

// Auth
#define kWADLServiceAuthURLPath @"auth"
#define kWADLServiceAuthManagerURLPath @"auth/manager"

// Customer
#define kWADLServiceCustomerURLPath @"customer/%@"
#define kWADLServiceCustomerSearchURLPath @"customer/search"

Bonus:

Only today you will get an example of WADLServerAPI class that implements request mechanism based on NSURLSession JUST FOR FREE!

Need more flexibility?

wadl2objc aslo supports namespaces and fields name conversion. To manage them you need to configurate WADL_mapping.plist. And of course you can modify wadl2objc source code and add whatever you whant :)

In distant Future

  • Make things really work. Add good sample project with sample protocol.
  • Swift support.
  • Support Swagger and OpenAPI protocols.
  • Generating Java for Android.
  • Migrate to Ruby.
  • Create gem.

About

This is a project I'm going to make generator Objective-C entities and services described in WADL file.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published