https://github.com/timakro/apispec-swaggerinherit
Plugin for apispec adding support for Swagger-style inheritance using `allOf`
https://github.com/timakro/apispec-swaggerinherit
apispec inheritance marshmallow openapi swagger
Last synced: 3 months ago
JSON representation
Plugin for apispec adding support for Swagger-style inheritance using `allOf`
- Host: GitHub
- URL: https://github.com/timakro/apispec-swaggerinherit
- Owner: timakro
- License: mit
- Created: 2018-06-12T15:15:57.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-02-13T19:57:39.000Z (almost 5 years ago)
- Last Synced: 2025-03-04T05:35:17.483Z (11 months ago)
- Topics: apispec, inheritance, marshmallow, openapi, swagger
- Language: Python
- Homepage: https://pypi.org/project/apispec-swaggerinherit/
- Size: 20.5 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# apispec-swaggerinherit
Plugin for apispec adding support for Swagger-style inheritance using `allOf`
## Example
```python
from apispec import APISpec
from marshmallow import Schema, fields
class PetBaseSchema(Schema):
name = fields.Str(required=True)
class DogSchema(PetBaseSchema):
barks = fields.Bool(required=True)
class CatSchema(PetBaseSchema):
cuteness = fields.Int(required=True)
spec = APISpec(
title='Pet shop',
version='1.0.0',
plugins=[
'apispec.ext.marshmallow',
'apispec_swaggerinherit'
]
)
spec.definition('PetBase', schema=PetBaseSchema)
spec.definition('Dog', schema=DogSchema)
spec.definition('Cat', schema=CatSchema)
print(spec.to_yaml())
```
Resulting OpenAPI spec:
```yaml
definitions:
Cat:
allOf:
- {$ref: '#/definitions/PetBase'}
- properties:
cuteness: {format: int32, type: integer}
required: [cuteness]
type: object
Dog:
allOf:
- {$ref: '#/definitions/PetBase'}
- properties:
barks: {type: boolean}
required: [barks]
type: object
PetBase:
properties:
name: {type: string}
required: [name]
type: object
info: {title: Pet shop, version: 1.0.0}
parameters: {}
paths: {}
swagger: '2.0'
tags: []
```
## Installation
pip install apispec-swaggerinherit