{"library":"apispec","code":"from apispec import APISpec\nfrom apispec.ext.marshmallow import MarshmallowPlugin\nfrom marshmallow import Schema, fields\nimport json\n\n# 1. Create an APISpec object\nspec = APISpec(\n    title=\"My Awesome API\",\n    version=\"1.0.0\",\n    openapi_version=\"3.0.2\",\n    info=dict(description=\"A minimal example of APISpec\"),\n    plugins=[\n        MarshmallowPlugin(),\n    ],\n)\n\n# 2. Define a Marshmallow Schema and register it as an OpenAPI component\nclass UserSchema(Schema):\n    id = fields.Int(dump_only=True)\n    name = fields.Str(required=True, description=\"The user's name\")\n    email = fields.Email(required=True, description=\"The user's email address\")\n\nspec.components.schema(\"User\", schema=UserSchema)\n\n# 3. Add a path with operations referencing the schema\nspec.path(\n    path=\"/users/{user_id}\",\n    operations=dict(\n        get=dict(\n            summary=\"Get user by ID\",\n            parameters=[\n                {\n                    \"in\": \"path\",\n                    \"name\": \"user_id\",\n                    \"schema\": {\"type\": \"integer\"},\n                    \"required\": True,\n                    \"description\": \"Numeric ID of the user to get\",\n                }\n            ],\n            responses={\n                200: {\n                    \"description\": \"User data\",\n                    \"content\": {\"application/json\": {\"schema\": {\"$ref\": \"#/components/schemas/User\"}}},\n                }\n            },\n        )\n    ),\n)\n\n# 4. Output the spec as JSON\nprint(json.dumps(spec.to_dict(), indent=2))","lang":"python","description":"This quickstart demonstrates how to initialize an `APISpec` object, define a Marshmallow schema, register it as an OpenAPI component, and then add a path with an operation that references the defined schema. Finally, it prints the generated OpenAPI specification in JSON format. This illustrates the basic programmatic API definition workflow using `apispec` and its Marshmallow plugin.","tag":null,"tag_description":null,"last_tested":"2026-04-24","results":[{"runtime":"python:3.10-alpine","exit_code":1},{"runtime":"python:3.10-slim","exit_code":1},{"runtime":"python:3.11-alpine","exit_code":1},{"runtime":"python:3.11-slim","exit_code":1},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":1},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":1},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":1}]}