bravado-core icon indicating copy to clipboard operation
bravado-core copied to clipboard

Add support for allOf which enables model inheritance and composition

Open analogue opened this issue 10 years ago • 15 comments

https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#composition-and-inheritance-polymorphism

analogue avatar Apr 15 '15 22:04 analogue

Just ran into this issue. Any word on this?

seanfarley avatar Dec 11 '15 22:12 seanfarley

For what it's worth, I attend the Python meet-ups at Yelp if I could help out with implementing this.

seanfarley avatar Dec 11 '15 23:12 seanfarley

No one has requested or needed this feature yet. Feel free to submit a well unit tested PR.

analogue avatar Dec 11 '15 23:12 analogue

Eek, that's a bit out of scope for my work (this is just a side project for me). I can try to help but my main goal is to just have a client library for Bitbucket:

https://api.bitbucket.org/swagger.json

seanfarley avatar Dec 11 '15 23:12 seanfarley

+1 - if no one has volunteered I will give it a shot

@seanfarley you might try turning off models in the config something like so for the time being - it works for me.

From http://bravado.readthedocs.org/en/latest/quickstart.html

client = SwaggerClient.from_url(
    'http://petstore.swagger.io/v2/swagger.json',
    config={'use_models': False})

captin411 avatar Dec 24 '15 06:12 captin411

Well, the whole point of using this was to get models to work. For the time being, I won't have any time to work on this. Please feel free to pick it up.

seanfarley avatar Dec 24 '15 22:12 seanfarley

@seanfarley take a look at my pull request #63 - hope that works for you. It works in the case I needed.

edit: for what it's worth, I opted to skip modeling the class hierarchy and chose instead to just flatten the attributes recursively into each type - to be honest I didn't really feel like going "super meta"

captin411 avatar Dec 29 '15 05:12 captin411

@seanfarley I also took a look at the bitbucket swagger specification and they use the "discriminator" property quite extensively ... I did not implement support for that though I could at a later time.

captin411 avatar Dec 29 '15 06:12 captin411

Cool, I'll try to take a look later :-)

seanfarley avatar Dec 29 '15 20:12 seanfarley

:+1:

ashtonmeuser avatar Jul 14 '16 00:07 ashtonmeuser

#110 added allOf support for schemas, but not for response objects directly. As an example, the PagerDuty API composes their response objects for components using allOf:

        "/schedules": {
            "get": {
                "tags": [
                    "Schedules"
                ],
                "description": "List the on-call schedules.",
                "summary": "List schedules",
                "parameters": [
                    {
                        "name": "query",
                        "in": "query",
                        "description": "Filters the result, showing only the schedules whose name matches the query.",
                        "type": "string"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "A paginated array of schedule objects.",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/Pagination"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "schedules": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/definitions/Schedule"
                                            }
                                        }
                                    },
                                    "required": [
                                        "schedules"
                                    ]
                                }
                            ]
                        },

Is anyone continuing to look at this feature? I too am trying to use this for a side project and completely fixing this by going "full meta" is probably out of scope.

jakedt avatar Dec 07 '16 16:12 jakedt

Any update on this? This is a major deviation from the Swagger and OpenAPI spec.

advance512 avatar Jan 28 '17 15:01 advance512

@advance512 We have support for allOf, just not in response objects. While this is regrettable it should not be too hard to implement, given that we have schema support for allOf. Patches are highly welcome.

sjaensch avatar Jan 29 '17 18:01 sjaensch

@sjaensch - PR #135 has the code. However, no tests. Maybe I'll add some later if I have time..

advance512 avatar Jan 31 '17 16:01 advance512

Thanks for the pull request! This gets me closer to using bitbucket's swagger file but still throws an error:

from bravado.client import SwaggerClient
client = SwaggerClient.from_url('http://api.bitbucket.org/swagger.json')
repos = client.repositories.get_repositories_username(username='seanfarley')
repos.result()

Error:

Traceback (most recent call last):
  File "test.py", line 4, in <module>
    repos.result()
  File "/Users/sean/.virtualenvs/b/lib/python2.7/site-packages/bravado/http_future.py", line 77, in result
    self.response_callbacks)
  File "/Users/sean/.virtualenvs/b/lib/python2.7/site-packages/bravado/http_future.py", line 115, in unmarshal_response
    operation)
  File "/Users/sean/sandbox/bravado-core/bravado_core/response.py", line 107, in unmarshal_response
    validate_schema_object(op.swagger_spec, content_spec, content_value)
  File "/Users/sean/sandbox/bravado-core/bravado_core/validate.py", line 39, in validate_schema_object
    validate_object(swagger_spec, one_schema, value)
  File "/Users/sean/sandbox/bravado-core/bravado_core/validate.py", line 82, in validate_object
    resolver=swagger_spec.resolver).validate(value)
  File "/Users/sean/.virtualenvs/b/lib/python2.7/site-packages/jsonschema/validators.py", line 123, in validate
    raise error
jsonschema.exceptions.ValidationError: Additional properties are not allowed (u'branches', u'tags' were unexpected)

seanfarley avatar Feb 05 '17 03:02 seanfarley