{"id":16550309,"url":"https://github.com/sylhare/petshop","last_synced_at":"2025-06-25T05:39:35.366Z","repository":{"id":92385338,"uuid":"379768138","full_name":"sylhare/Petshop","owner":"sylhare","description":"🐶🛒 Kotlin spring-boot project using a generated API from a swagger file","archived":false,"fork":false,"pushed_at":"2021-07-26T13:12:13.000Z","size":44,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-11T23:52:18.669Z","etag":null,"topics":["gradle","kotlin","openapi","spring-boot","swagger"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sylhare.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2021-06-24T01:11:52.000Z","updated_at":"2024-01-19T15:39:19.000Z","dependencies_parsed_at":"2023-05-17T02:00:30.501Z","dependency_job_id":null,"html_url":"https://github.com/sylhare/Petshop","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sylhare/Petshop","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sylhare%2FPetshop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sylhare%2FPetshop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sylhare%2FPetshop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sylhare%2FPetshop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sylhare","download_url":"https://codeload.github.com/sylhare/Petshop/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sylhare%2FPetshop/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261814659,"owners_count":23213804,"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":["gradle","kotlin","openapi","spring-boot","swagger"],"created_at":"2024-10-11T19:33:49.276Z","updated_at":"2025-06-25T05:39:35.347Z","avatar_url":"https://github.com/sylhare.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Petshop\n\nKotlin springboot project using a generated API from a swagger file\n\n## Swagger code generation\n\nUsing the [petstore.yml](https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml) example.\nWe are going to use [openapi-generator](https://github.com/OpenAPITools/openapi-generator) which is a fork from the [swagger-codegen](https://swagger.io/tools/swagger-codegen/).\n\n### Create the API with only the swagger file\n\nYou need to install:\n\n```bash\nbrew install openapi-generator\n```\n\nThen run it using your swagger yaml file and if you have your config file. You can also specify some [global properties](https://openapi-generator.tech/docs/globals/#available-global-properties) as key=value pairs.\n(Find the configuration for [java](https://openapi-generator.tech/docs/generators/java/) and [kotlin](https://openapi-generator.tech/docs/generators/kotlin/))\n\n```bash\nopenapi-generator generate -i src/main/resources/swagger/petstore.yml -g kotlin-spring  --config src/main/resources/api-config.json\n# openapi-generator generate -i ../src/main/resources/swagger/petstore.yml -g kotlin-spring  --config ../src/main/resources/api-config.json --global-property apiTests=true,modelTests=true,apiDocs=true,modelDocs=true\n```\n\nThis will create the project with a `build.gradle.kts` (and also a `pom.xml` for maven).\n\nFor gradle, the wrapper won't be created automatically, you can do so by running:\n\n```bash\ngradle wrapper --gradle-version 4.8 --distribution-type all\n./gradlew assemble\n```\n\nThe syntax used in the generated build.gradle.kts is rather old and might not be compatible with gradle 7.0+.\nThen you need to create the `PetApiServiceImpl` that implements `PetApiService` and add it to the `PetApiController` implementing `PetApi`:\n\n```kotlin\n@RestController\nclass PetApiController : PetApi {\n\n    @Autowired\n    override lateinit var service: PetApiServiceImpl\n}\n```\n\nThis service is where you can start adding your own implementation of the Petshop.\n(Because the swagger yaml only generate the endpoints, it's not that magical!)\n\n\u003e The generated code is a bit lacking and will require some changes to be working and up to date.\n\nTo build the project using gradle, run:\n\n```bash\ngradle build \u0026\u0026 java -jar build/libs/openapi-spring-1.0.0.jar\n```\n\nIf all builds successfully, the server should run on [http://localhost:8080/](http://localhost:8080/)\n\n### With customization\n\nIf you want to customize or use the generated classes for something else.\nYou can use the [org.openapi.generator plugin](https://openapi-generator.tech/docs/plugins/) in your code like:\n\n```kotlin\nplugins {\n    id(\"org.openapi.generator\") version \"5.1.1\"\n}\n\nopenApiGenerate {\n    generatorName.set(\"spring\")\n    inputSpec.set(\"src/main/resources/petstore.yml\")\n    outputDir.set(\"$buildDir/generated\")\n    configFile.set(\"src/main/resources/api-config.json\")\n}\n\n// Add the generated sources to your project\njava.sourceSets[\"main\"].java.srcDir(\"$buildDir/generated/src/main/java\")\n```\n\nThe api-config can also be added directly within the `openApiGenerate` gradle task.\nThe `inputSpec` is the swagger file that the code will be generated from.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsylhare%2Fpetshop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsylhare%2Fpetshop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsylhare%2Fpetshop/lists"}