Skip to content

OpenAPI: 'required' not working on 'allOf' related properties #785

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tobuh opened this issue Nov 16, 2018 · 4 comments
Closed

OpenAPI: 'required' not working on 'allOf' related properties #785

tobuh opened this issue Nov 16, 2018 · 4 comments

Comments

@tobuh
Copy link

tobuh commented Nov 16, 2018

Description

Using 'required' on properties from objects referenced by 'allOf' leads to error "connexion.exceptions.InvalidSpecification"

Expected behaviour

Using 'required' should not throw an error for properties from 'allOf'

Actual behaviour

Error thrown:

Traceback (most recent call last):
  File "test.py", line 4, in <module>
    app.add_api('restapitest.yaml')
  File "/home/tobias/.local/lib/python3.5/site-packages/connexion/apps/flask_app.py", line 54, in add_api
    api = super(FlaskApp, self).add_api(specification, **kwargs)
  File "/home/tobias/.local/lib/python3.5/site-packages/connexion/apps/abstract.py", line 155, in add_api
    options=api_options.as_dict())
  File "/home/tobias/.local/lib/python3.5/site-packages/connexion/apis/abstract.py", line 72, in __init__
    self.specification = Specification.load(specification, arguments=arguments)
  File "/home/tobias/.local/lib/python3.5/site-packages/connexion/spec.py", line 151, in load
    return cls.from_file(spec, arguments=arguments)
  File "/home/tobias/.local/lib/python3.5/site-packages/connexion/spec.py", line 108, in from_file
    return cls.from_dict(spec)
  File "/home/tobias/.local/lib/python3.5/site-packages/connexion/spec.py", line 146, in from_dict
    return OpenAPISpecification(spec)
  File "/home/tobias/.local/lib/python3.5/site-packages/connexion/spec.py", line 39, in __init__
    self._validate_spec(raw_spec)
  File "/home/tobias/.local/lib/python3.5/site-packages/connexion/spec.py", line 232, in _validate_spec
    raise InvalidSpecification.create_from(e)
connexion.exceptions.InvalidSpecification: Required list has not defined properties: ['name']

Steps to reproduce

restapitest.yaml

openapi: 3.0.0
info:
  description: Test    
  version: 0.1.0
  title: "Test API"

paths:
  /objects:
    get:
      summary: "Get all available objects"
      operationId: getObjects
      responses:
        200:
          description: "List of available objects"
          content:
            application/json:
              schema:
                type: "array"
                items:
                  allOf:
                  - $ref: '#/components/schemas/AnotherObject'
        default:
          description: "standard error"

components:
  schemas:
    Object:
      type: "object"
      properties:
        name:
          type: "string"
          example: "Testname"
          
    AnotherObject:
      required:
      - name
      allOf:
        - $ref: '#/components/schemas/Object'
        - type: "object"
          properties:
            anotherproperty:
              type: "string"

test.py

import connexion

app = connexion.App(__name__, specification_dir='./')
app.add_api('restapitest.yaml')
app.run(port=8080)

Additional info:

Output of the commands:

  • python3 --version = Python 3.5.2
  • pip3 show connexion | grep "^Version\:" = Version: 2.0.2
@dtkav
Copy link
Collaborator

dtkav commented Nov 16, 2018 via email

@tobuh
Copy link
Author

tobuh commented Nov 16, 2018

You pointed me in a good direction. It seems, thats it already mentioned there??

python-openapi/openapi-spec-validator#27

@tobuh
Copy link
Author

tobuh commented Nov 16, 2018

Ok, it seems that the syntax was not as expected. Now I'm using:

    AnotherObject:
      allOf:
        - $ref: '#/components/schemas/Object'
        - required:
          - name
        - type: "object"
          properties:
            anotherproperty:
              type: "string"

The error is gone. But editor.swagger.io accepted the former definition as well ... which was a bit misleading ...

Now my project is starting. Thank again for pointing me in the right direction ...

@dtkav
Copy link
Collaborator

dtkav commented Nov 19, 2018

sure thing @tobuh
I'm going to close this out for now. Thanks for linking the relevant ticket on that project.

@dtkav dtkav closed this as completed Nov 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants