{"id":25177477,"url":"https://github.com/gpbultz/apidocandmock","last_synced_at":"2026-02-08T06:36:57.870Z","repository":{"id":269187190,"uuid":"906175304","full_name":"gpbultz/ApiDocAndMock","owner":"gpbultz","description":"  🔧OpenApi extensions and Mocking objects using Bogus","archived":false,"fork":false,"pushed_at":"2025-01-08T20:33:51.000Z","size":198,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-08T23:35:38.472Z","etag":null,"topics":["api","bogus","minimalapi","mocking","net8","openapi","reflection"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gpbultz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-THIRD-PARTY.md","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":"2024-12-20T10:18:47.000Z","updated_at":"2025-01-08T20:27:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"01e90bd1-d819-4cad-bd01-0988909c6641","html_url":"https://github.com/gpbultz/ApiDocAndMock","commit_stats":null,"previous_names":["gpbultz/apidocandmock"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gpbultz%2FApiDocAndMock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gpbultz%2FApiDocAndMock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gpbultz%2FApiDocAndMock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gpbultz%2FApiDocAndMock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gpbultz","download_url":"https://codeload.github.com/gpbultz/ApiDocAndMock/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237963053,"owners_count":19394142,"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":["api","bogus","minimalapi","mocking","net8","openapi","reflection"],"created_at":"2025-02-09T14:25:25.706Z","updated_at":"2026-02-08T06:36:57.832Z","avatar_url":"https://github.com/gpbultz.png","language":"C#","readme":"\n# ApiMockDataFactory\n\nA comprehensive API mocking utility for .NET projects, leveraging the power of **Bogus** for seamless data generation.\n\n---\n\n## Installation\n\nInstall the package via NuGet:\n\n```bash\ndotnet add package ApiDocAndMock\n```\n\n---\n\n## Usage\n\n### Service Configuration\nIntegrate the package with your application by adding the required services:\n\n```csharp\n// Main service setup\nbuilder.Services.AddDocAndMock();\n\n// Optional: Add authentication for API mocking\nbuilder.Services.AddMockAuthentication();\n\n// Swagger integration for documentation and mock APIs\nbuilder.Services.AddMockSwagger(includeSecurity: true, includAnnotations: true);\n\n// Optional: Add an in-memory database for simulating CRUD operations\nbuilder.Services.AddMemoryDb();\n```\n\n### Application Middleware\nConfigure the application middleware to enable API documentation and mocking:\n\n```csharp\nvar app = builder.Build();\n\n// Enable API documentation and mock utilities\napp.UseApiDocAndMock(useAuthentication: true, useMockOutcome: true);\n\n// Enable Swagger for API visualization\napp.UseSwagger();\napp.UseSwaggerUI();\n```\n\n---\n\n## Configuration\n\n### Response Types\nCustomize default response types or add new ones for specific HTTP status codes:\n\n```csharp\nbuilder.Services.AddCommonResponseConfigurations(config =\u003e\n{\n    config.RegisterResponseExample(500, new ProblemDetails\n    {\n        Title = \"Custom Internal Server Error\",\n        Status = 500,\n        Detail = \"A custom error occurred. Please contact support.\"\n    });\n\n    config.RegisterResponseExample(403, new ProblemDetails\n    {\n        Title = \"Forbidden\",\n        Status = 403,\n        Detail = \"You do not have permission to access this resource.\"\n    });\n});\n```\n\n### Default Faker Rules\nDefine default faker rules to override existing rules and generate mock data for specific property names:\n\n```csharp\nbuilder.Services.AddDefaultFakerRules(rules =\u003e\n{\n    rules[\"Phone\"] = faker =\u003e \"+44 \" + faker.Phone.PhoneNumber(); \n});\n```\n\n### Mocking Configurations\nSet up custom mocking configurations to apply specific rules to request and response objects. This ensures that objects adhere to predefined formats, with fallback defaults provided by **Bogus**.\n\n```csharp\nbuilder.Services.AddMockingConfigurations(config =\u003e\n{\n    // Configure Booking object\n    config.RegisterConfiguration\u003cBooking\u003e(cfg =\u003e\n    {\n        cfg\n            .ForPropertyObject\u003cRoom\u003e(\"Room\")\n            .ForPropertyObject\u003cContact\u003e(\"PrimaryContact\");\n    });\n\n    // Configure Hotel object\n    config.RegisterConfiguration\u003cHotel\u003e(cfg =\u003e\n    {\n        cfg\n            .ForProperty(\"Name\", faker =\u003e faker.Company.CompanyName())\n            .ForPropertyObjectList\u003cRoom\u003e(\"Rooms\", 5)\n            .ForPropertyObjectList\u003cBooking\u003e(\"Bookings\", 5);\n    });\n});\n```\n\n### Notes on Mocking\n- **ForPropertyObject**: Applies rules to a specific nested object within a response.\n- **ForPropertyObjectList**: Configures a list of nested objects with a specified number of items.\n- If a property lacks an explicit rule, a default value is assigned based on its type. Undefined types default to `null`.\n\n[OpenApiExtensions For MinimalApi endpoints](./OpenApiExtensions%20For%20MinimalApi%20endpoints.md)  \n[OpenApiMockExtensions For MinimalApi Endpoints](./OpenApiMockExtensions%20For%20MinimalApi%20Endpoints.md)  \n[GetMockFromMemoryDb Usage](./GetMockFromMemoryDb%20Usage.md)  \n[UpdateMockWithMemoryDb Usage](./UpdateMockWIthMemoryDb%20Usage.md)  \n[CreateMockWithMemoryDb Usage](./CreateMockWithMemoryDb%20Usage.md)  \n[DeleteMockWithMemoryDb Usage](./DeleteMockWithMemoryDb%20Usage.md)  \n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgpbultz%2Fapidocandmock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgpbultz%2Fapidocandmock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgpbultz%2Fapidocandmock/lists"}