{"id":18994025,"url":"https://github.com/swaggest/go-code-builder","last_synced_at":"2025-04-22T12:46:28.077Z","repository":{"id":11785457,"uuid":"86316861","full_name":"swaggest/go-code-builder","owner":"swaggest","description":"JSON Schema enabled Go code building abstraction for PHP ","archived":false,"fork":false,"pushed_at":"2022-09-15T08:12:55.000Z","size":750,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-13T22:53:22.947Z","etag":null,"topics":["code-generator","go","json-schema","json-schema-generator","php-library"],"latest_commit_sha":null,"homepage":"","language":"Go","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/swaggest.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-27T09:30:16.000Z","updated_at":"2022-01-02T16:17:27.000Z","dependencies_parsed_at":"2022-08-07T07:15:10.428Z","dependency_job_id":null,"html_url":"https://github.com/swaggest/go-code-builder","commit_stats":null,"previous_names":[],"tags_count":59,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swaggest%2Fgo-code-builder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swaggest%2Fgo-code-builder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swaggest%2Fgo-code-builder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swaggest%2Fgo-code-builder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/swaggest","download_url":"https://codeload.github.com/swaggest/go-code-builder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250243236,"owners_count":21398308,"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":["code-generator","go","json-schema","json-schema-generator","php-library"],"created_at":"2024-11-08T17:23:51.633Z","updated_at":"2025-04-22T12:46:28.060Z","avatar_url":"https://github.com/swaggest.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Swaggest JSON-schema enabled Go code builder\n\n[![Build Status](https://travis-ci.org/swaggest/go-code-builder.svg?branch=master)](https://travis-ci.org/swaggest/go-code-builder)\n[![codecov](https://codecov.io/gh/swaggest/go-code-builder/branch/master/graph/badge.svg)](https://codecov.io/gh/swaggest/go-code-builder)\n![Code lines](https://sloc.xyz/github/swaggest/go-code-builder/?category=code)\n![Comments](https://sloc.xyz/github/swaggest/go-code-builder/?category=comments)\n\nThis library generates Go mapping structures defined by [JSON schema](http://json-schema.org/).\n\n## Example\n\n[Generated code](tests/resources/go/swagger/entities.go) for [schema](tests/resources/swagger-schema.json).\n\n```php\n\u003c?php\nnamespace MyApp;\n\nuse Swaggest\\GoCodeBuilder\\JsonSchema\\GoBuilder;\nuse Swaggest\\GoCodeBuilder\\JsonSchema\\StructHookCallback;\nuse Swaggest\\GoCodeBuilder\\Templates\\GoFile;\nuse Swaggest\\GoCodeBuilder\\Templates\\Struct\\StructDef;\nuse Swaggest\\JsonSchema\\Schema;\n\nrequire_once __DIR__ . '/vendor/autoload.php';\n\n$schemaData = json_decode(file_get_contents(__DIR__ . '/swagger-schema.json'));\n$schema = Schema::import($schemaData);\n\n$builder = new GoBuilder();\n$builder-\u003estructCreatedHook = new StructHookCallback(function (StructDef $structDef, $path, $schema) use ($builder) {\n    if ('#' === $path) {\n        $structDef-\u003esetName('SwaggerSchema');\n    } elseif (0 === strpos($path, '#/definitions/')) {\n        $name = $builder-\u003ecodeBuilder-\u003eexportableName(substr($path, strlen('#/definitions/')));\n        $structDef-\u003esetName($name);\n    }\n});\n$builder-\u003egetType($schema);\n\n$goFile = new GoFile('swagger');\nforeach ($builder-\u003egetGeneratedStructs() as $generatedStruct) {\n    $goFile-\u003egetCode()-\u003eaddSnippet($generatedStruct-\u003estructDef);\n}\n$goFile-\u003egetCode()-\u003eaddSnippet($builder-\u003egetCode());\n```\n\n## API Documentation\n\nClasses [documentation](API.md).\n\n## Schema extensions\n\nMagic properties (vendor extensions) defined in schema enable special handling.\n\n### `x-go-type`\n\nCan have a value string or an object. Contains type reference that can be used instead of generated type.\n\nIf `$ignoreXGoType` option is `true` value of vendor extension is disregarded and type is generated.\n\nValue examples:\n\n* `\"[]myorg.com/go-null-types::nulltypes.NullString\"`\n* `\"myorg.com/my-app/order.Entity\"`\n* `\"float64\"`\n* `{\"import\": {\"package\": \"my-package/domain/orders\"}, \"type\": \"Order\"}`\n* `{\"import\": {\"package\": \"my-package\", \"alias\": \"mp\"}, \"type\": \"Order\"}`\n\n### `x-nullable`, `nullable`\n\nIf `true` schema type is converted to `[\u003ctype\u003e, \"null\"]`. Requires `$enableXNullable` option.\n\n### `x-omitempty`\n\nA `boolean` value to control `,omitempty` presence.\n\n### `x-generate`\n\nA `boolean` value to control whether property should be added to generated `struct`. \nProperty with `\"x-generate\": false` will be skipped.\nIf `GoBuilder` option `requireXGenerate` is set to `true` only properties with `\"x-generate\": true` will be generated. \n\n## CLI Tool\n\nYou can use [json-cli](https://github.com/swaggest/json-cli#gengo) to generate Go structures from command line.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswaggest%2Fgo-code-builder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fswaggest%2Fgo-code-builder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswaggest%2Fgo-code-builder/lists"}