This is console tool for generating Objective-C code based on WADL and XSD protocols files About WADL
To build and run the project you need:
- Clone the project
git clone https://github.com/dzhurov/wadl2objc
- Prepare your .wadl and .xsd files
- In the schema settings set related path to .wadl and .xsd files
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.
First of all you need to provide output dir path using parameter: --output-dir:
.
There are two options to provide .wadl and .xsd files
In this case use two parameters --xsd:
and --wadl:
with related paths to .wadl and .xsd files.
In this case use parameters: --wadlURL:
and --xsdURL:
with URLs to needed files.
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
andNSArray<NSDictionary*>
- Default
NSDateFormatter
s 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.)
- This class will handle all generated services. You'll be able to access services as static methods, like this:
WADLServicesResource
base class for service containder.WADLRequestTask
defines macroWADLRequestTask
wich is associates with request operation. By default isNSURLSessionTask*
. 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
-
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"
Only today you will get an example of WADLServerAPI
class that implements request mechanism based on NSURLSession
JUST FOR FREE!
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 :)