{"id":20492587,"url":"https://github.com/redmadrobot/core-parser-generator","last_synced_at":"2025-03-05T17:41:26.691Z","repository":{"id":75660490,"uuid":"112442499","full_name":"RedMadRobot/core-parser-generator","owner":"RedMadRobot","description":null,"archived":false,"fork":false,"pushed_at":"2018-08-29T07:16:35.000Z","size":137,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-01-16T05:55:06.486Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RedMadRobot.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-11-29T07:35:17.000Z","updated_at":"2018-11-17T08:52:48.000Z","dependencies_parsed_at":"2023-06-07T07:00:25.532Z","dependency_job_id":null,"html_url":"https://github.com/RedMadRobot/core-parser-generator","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RedMadRobot%2Fcore-parser-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RedMadRobot%2Fcore-parser-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RedMadRobot%2Fcore-parser-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RedMadRobot%2Fcore-parser-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RedMadRobot","download_url":"https://codeload.github.com/RedMadRobot/core-parser-generator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242073771,"owners_count":20067901,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-15T17:29:43.221Z","updated_at":"2025-03-05T17:41:26.667Z","avatar_url":"https://github.com/RedMadRobot.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ParserGenerator\n\n\u003e Binary file can be installed via cocoapods ([link](https://github.com/RedMadRobot/cocoapods-specs)).\n\n\u003e Each time you update repository ensure to draft new release, info can be found [here](https://github.com/RedMadRobot/cocoapods-specs/blob/master/README.md).\n\nThis utility generates parsers from model objects. Only works for [Core Parser](https://github.com/RedMadRobot/core-parser).\n\n## Example\n\nYou have entity class\n\n```swift\n/** \n @model\n */\nclass Client {\n\n    /**     \n     @json full_name\n     */\n    var fullName: String\n    \n    /**     \n     @json\n     */\n    var phone: String\n    \n    \n    init(\n        fullName: String,\n        phone: String)\n    {\n        self.fullName = fullName\n        self.phone = phone\n    }\n        \n}\n```\n\nAnd this utility generates parser for this\n\n```swift\nclass ClientParser: JSONParser\u003cClient\u003e\n{\n    override func parseObject(_ data: JSON) -\u003e Client?\n    {\n        printAbsentFields(in: data)\n\n        guard\n            let fullName: String = data[\"full_name\"]?.string,\n            let phone: String = data[\"phone\"]?.string\n        else { return nil }\n\n        let object = Client(\n            fullName: fullName,\n            phone: phone\n        )\n        return object\n    }\n\n    override class func modelFields() -\u003e Fields\n    {\n        return Fields(\n            mandatory: Set([\n                \"phone\", \"full_name\", \n            ]),\n            optional: Set([\n                \n            ])\n        )\n    }\n}\n\n```\n\nParser checks mandatory fields and recursively loop through you JSON. For more info read about our [Core Parser](https://github.com/RedMadRobot/core-parser).\n\nAfter you get responce from server, just call\n\n```swift\nlet client = ClientParser().parse(data).first\n```\n\n## Setup steps\n\nAdd git submodule:\n\n`git@github.com:RedMadRobot/parser-generator.git`\n\nAfter submodule is cloned, you need to build the project. You can call `build.command` (folder `Source/ParserGenerator`).\n\nAfter this add Run Script Phase to you target:\n\n```bash\nPARSER_GENERATOR_PATH=ParserGenerator/Source/ParserGenerator/build/ParserGenerator\n\nif [ -f  $PARSER_GENERATOR_PATH]\nthen\n    echo \"ParserGenerator executable found\"\nelse\n    osascript -e 'tell app \"Xcode\" to display dialog \"Parser generator not Found: \\nSource/ParserGenerator\" buttons {\"OK\"} with icon caution'\nfi\n\n$PARSER_GENERATOR_PATH \\\n-project_name $PROJECT_NAME \\\n-input \"./$PROJECT_NAME/Classes/Model\" \\\n-output \"./$PROJECT_NAME/Generated/Classes/Parser\"\n```\n\nYou need to insert correct path to parser generator executable file, project name, input folder of model classes and output folder for parsers.\n`-debug` argument is optional.\n\n## Supported annotations\n\n* `@model` — annotation for model class, parser should be generated for. If some class inherit another, parent should include annotations also.\n* `@abstract` — class annotation, parser should **not** be generated for. Ignored if class doesn't include @model.\n* `@json key` — property annotation, that JSON includes. `key` is JSON field key. You can omit `key`, so property name will be the field key.\n* `@parser ParserName` — annotation for property class type. Generates `let value = ParserName().parse(body: data[\"key\"]).first` for single object type and `let value = ParserName().parse(body: data[\"key\"])` for array types.\n\n## Restrictions\n\n* Only support classes\n\n## Author\nEgor Taflanidi, et@redmadrobot.com\n\n## Support team\nIvan Vavilov, iv@redmadrobot.com\n\nAndrey Rozhkov, ar@redmadrobot.com\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredmadrobot%2Fcore-parser-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fredmadrobot%2Fcore-parser-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredmadrobot%2Fcore-parser-generator/lists"}