GithubHelp home page GithubHelp logo

python-oas's People

Contributors

dependabot[bot] avatar grktsh avatar sisp avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

sisp bdangit

python-oas's Issues

Unmarshaler for `additionalProperties` with object value incorrect?

If I'm not mistaken, the unmarshaler for additionalProperties with an object value is incorrect.

The unit test tests the following value assigned to additionalProperties:

{
  "additionalProperties": {
    "x": {
      "type": "string"
    }
  }
}

The JSON Schema Draft 4 states:

The value of "additionalProperties" MUST be a boolean or an object. If it is an object, it MUST also be a valid JSON Schema.

An example from Draft 7 (I didn't find one for Draft 4, but I think there is no difference in this case) looks like this:

{
  "additionalProperties": { "type": "string" }
}

I think the problem is that the unmarshaler treats additionalProperties the same way as properties when additionalProperties is an object/dict:

if isinstance(additional_properties, dict):
properties = dict(additional_properties, **properties)

Instead, I think properties should be unmarshaled as it's done now, but any remaining instance properties should be unmarshaled using the additionalProperties subschema, if present, using SchemaUnmarshaler::_unmarshal. The results of both unmarshalers should then be merged. Do you agree?

'JsonRef' object has no attribute 'cache' / jsonref.JsonRefError: Unresolvable JSON pointer

I have an OpenAPI3 spec that looks like this:

openapi.yaml
openapi: 3.0.1
info:
  title: Contact
  version: 1.0.0
  description: Simple API to capture contact details.
  contact:
    email: [email protected]
servers:
  - url: 'https://lshjsdfhjs.execute-api.eu-west-1.amazonaws.com/'
    description: AWS API Gateway
paths:
  /contact:
    post:
      summary: New contact from a user.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/contactDetails'
      responses:
        202:
          $ref: '#/components/responses/202'
        400:
          $ref: '#/components/responses/400'
components:
  responses:
    202:
      description: Successful POST
      content:
        application/json:
          schema:
            type: object
            properties:
              message:
                type: string
          example:
            message: Success
    400:
      description: Invalid POST data
      content:
        application/json:
          schema:
            type: object
            properties:
              message:
                type: string
              errors:
                type: object
          example:
            message: Invalid POST
            errors:
              missing_fields:
                - givenName
                - email
  schemas:
    contactDetails:
      type: object
      required:
        - givenName
        - familyName
        - email
      properties:
        givenName:
          type: string
          description: Personal/given name
        familyName:
          type: string
          description: Family name
        email:
          type: string
          format: email
          description: Work/business email address
        phone:
          type: string
          description: Contact phone number
      example:
        givenName: Scrooge
        familyName: McDuck
        email: [email protected]
        phone: +1 555-123-1234

This is valid OpenAPI3 according to the Swagger editor, but when I try to use it with OAS I get the errors in the title:

import oas
import yaml

with open('openapi.yaml') as f: 
    spec = oas.create_spec_from_dict(yaml.safe_load(f))                                                                                                                                            
Full traceback
Traceback (most recent call last):
  File "/home/bjmc/Sandbox/lambdas/contact/.venv/lib/python3.8/site-packages/proxytypes.py", line 252, in __subject__
    return self.cache
  File "/home/bjmc/Sandbox/lambdas/contact/.venv/lib/python3.8/site-packages/proxytypes.py", line 176, in __getattribute__
    return _oga(self, attr)
AttributeError: 'JsonRef' object has no attribute 'cache'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/bjmc/Sandbox/lambdas/contact/.venv/lib/python3.8/site-packages/jsonref.py", line 217, in resolve_pointer
    document = document[part]
KeyError: '202'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "test.py", line 5, in <module>
    spec = oas.create_spec_from_dict(yaml.safe_load(f))  
  File "/home/bjmc/Sandbox/lambdas/contact/.venv/lib/python3.8/site-packages/oas/spec.py", line 21, in create_spec_from_dict
    return Spec(copy.deepcopy(deref_spec_dict))
  File "/usr/lib/python3.8/copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "/usr/lib/python3.8/copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib/python3.8/copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "/usr/lib/python3.8/copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib/python3.8/copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "/usr/lib/python3.8/copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib/python3.8/copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "/usr/lib/python3.8/copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib/python3.8/copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "/usr/lib/python3.8/copy.py", line 230, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/usr/lib/python3.8/copy.py", line 151, in deepcopy
    copier = getattr(x, "__deepcopy__", None)
  File "/home/bjmc/Sandbox/lambdas/contact/.venv/lib/python3.8/site-packages/proxytypes.py", line 175, in __getattribute__
    return getattr(self.__subject__, attr)
  File "/home/bjmc/Sandbox/lambdas/contact/.venv/lib/python3.8/site-packages/proxytypes.py", line 176, in __getattribute__
    return _oga(self, attr)
  File "/home/bjmc/Sandbox/lambdas/contact/.venv/lib/python3.8/site-packages/proxytypes.py", line 134, in wrapper
    return method(self, *args, **kwargs)
  File "/home/bjmc/Sandbox/lambdas/contact/.venv/lib/python3.8/site-packages/proxytypes.py", line 254, in __subject__
    self.cache = super(LazyProxy, self).__subject__
  File "/home/bjmc/Sandbox/lambdas/contact/.venv/lib/python3.8/site-packages/proxytypes.py", line 134, in wrapper
    return method(self, *args, **kwargs)
  File "/home/bjmc/Sandbox/lambdas/contact/.venv/lib/python3.8/site-packages/proxytypes.py", line 240, in __subject__
    return self.callback()
  File "/home/bjmc/Sandbox/lambdas/contact/.venv/lib/python3.8/site-packages/proxytypes.py", line 134, in wrapper
    return method(self, *args, **kwargs)
  File "/home/bjmc/Sandbox/lambdas/contact/.venv/lib/python3.8/site-packages/jsonref.py", line 174, in callback
    result = self.resolve_pointer(self.store[uri], fragment)
  File "/home/bjmc/Sandbox/lambdas/contact/.venv/lib/python3.8/site-packages/proxytypes.py", line 134, in wrapper
    return method(self, *args, **kwargs)
  File "/home/bjmc/Sandbox/lambdas/contact/.venv/lib/python3.8/site-packages/jsonref.py", line 219, in resolve_pointer
    self._error("Unresolvable JSON pointer: %r" % pointer, cause=e)
  File "/home/bjmc/Sandbox/lambdas/contact/.venv/lib/python3.8/site-packages/proxytypes.py", line 134, in wrapper
    return method(self, *args, **kwargs)
  File "/home/bjmc/Sandbox/lambdas/contact/.venv/lib/python3.8/site-packages/jsonref.py", line 223, in _error
    raise JsonRefError(
jsonref.JsonRefError: Unresolvable JSON pointer: '/components/responses/202'

The initial error seems to be:
AttributeError: 'JsonRef' object has no attribute 'cache'

Not sure if this user error on my part (do I need to set a cache somewhere?) or a bug with OAS. I'm happy to help with any debugging. Thanks for splitting this library out from Falcon.

Error installing dev dependencies with pipenv

I'm getting an error while trying to install development dependencies using pipenv:

$ pipenv install --dev
Installing dependencies from Pipfile.lock (284880)…
An error occurred while installing -e .[format,test]! Will try again.
  🐍   β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰β–‰ 45/45 β€” 00:00:08
Installing initially failed dependencies…
[pipenv.exceptions.InstallError]:   File "~/.local/lib/python3.6/site-packages/pipenv/core.py", line 1874, in do_install
[pipenv.exceptions.InstallError]:       keep_outdated=keep_outdated
[pipenv.exceptions.InstallError]:   File "~/.local/lib/python3.6/site-packages/pipenv/core.py", line 1253, in do_init
[pipenv.exceptions.InstallError]:       pypi_mirror=pypi_mirror,
[pipenv.exceptions.InstallError]:   File "~/.local/lib/python3.6/site-packages/pipenv/core.py", line 859, in do_install_dependencies
[pipenv.exceptions.InstallError]:       retry_list, procs, failed_deps_queue, requirements_dir, **install_kwargs
[pipenv.exceptions.InstallError]:   File "~/.local/lib/python3.6/site-packages/pipenv/core.py", line 763, in batch_install
[pipenv.exceptions.InstallError]:       _cleanup_procs(procs, not blocking, failed_deps_queue, retry=retry)
[pipenv.exceptions.InstallError]:   File "~/.local/lib/python3.6/site-packages/pipenv/core.py", line 681, in _cleanup_procs
[pipenv.exceptions.InstallError]:       raise exceptions.InstallError(c.dep.name, extra=err_lines)
[pipenv.exceptions.InstallError]: ['Obtaining file://~/git/github.com/sisp/python-oas']
[pipenv.exceptions.InstallError]: ['ERROR: Error installing \'file://~/git/github.com/sisp/python-oas\': editable mode is not supported for pyproject.toml-style projects. This project is being processed as pyproject.toml-style because it has a pyproject.toml file with a "build-backend" key in the "build_system" value. See PEP 517 for the relevant specification.']

If I downgrade pip to v18 manually, it works fine. It seems something was changed in v19 that causes this issue: https://discuss.python.org/t/pip-19-1-and-installing-in-editable-mode-with-pyproject-toml/1553

User documentation

It would be nice to provide an example of user code in the README. If you give me the appropriate pointers into the code, I could come up with an example and make a PR.

Unmarshaler for `additionalProperties` with value `true` incorrect

I believe the unmarshaler for additionalProperties when {"additionalProperties": true} is incorrect because the unmarshaler only unmarshals properties stated in properties:

for name, sub_schema in iteritems(properties):

If {"additionalProperties": true} all remaining properties not stated in properties or matched by patternProperties (see #6) should be extracted without a schema, too.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.