Skip to content
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

Option to parse schemas with cyclic references #158

Open
aquamatthias opened this issue Oct 17, 2023 · 0 comments
Open

Option to parse schemas with cyclic references #158

aquamatthias opened this issue Oct 17, 2023 · 0 comments

Comments

@aquamatthias
Copy link

I am trying to parse Azure rest API specs from the official azure-rest-api-specs repo. From a local clone I run those commands:

> pip install "prance[osv,cli]"
> python3
Python 3.11.6 (main, Oct  2 2023, 13:45:54) [Clang 15.0.0 (clang-1500.0.40.1)] on darwin
>>> from prance import ResolvingParser
>>> ResolvingParser("/Users/matthias/Documents/Work/someeng/azure-rest-api-specs/specification/network/resource-manager/Microsoft.Network/stable/2023-05-01/virtualNetwork.json")

The first Error I get is this:

prance.util.url.ResolutionError: Recursion reached limit of 1 trying to resolve "file:///Users/matthias/Documents/Work/someeng/azure-rest-api-specs/specification/network/resource-manager/Microsoft.Network/stable/2023-05-01/network.json#/definitions/CloudErrorBody"!
file:///Users/matthias/Documents/Work/someeng/azure-rest-api-specs/specification/network/resource-manager/Microsoft.Network/stable/2023-05-01/network.json#/definitions/CloudError
file:///Users/matthias/Documents/Work/someeng/azure-rest-api-specs/specification/network/resource-manager/Microsoft.Network/stable/2023-05-01/network.json#/definitions/CloudErrorBody
file:///Users/matthias/Documents/Work/someeng/azure-rest-api-specs/specification/network/resource-manager/Microsoft.Network/stable/2023-05-01/network.json#/definitions/CloudErrorBody

Where the definition looks like this (short version):

    "CloudErrorBody": {
      "properties": {
        "details": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/CloudErrorBody"
          },
          "description": "A list of additional details about the error."
        }
      }
    },

How can I convince prance to read this definition?

If I remove this property manually, I get more complex circular references. Example:

prance.util.url.ResolutionError: Recursion reached limit of 1 trying to resolve "file:///Users/matthias/Documents/Work/someeng/azure-rest-api-specs/specification/network/resource-manager/Microsoft.Network/stable/2023-05-01/networkSecurityGroup.json#/definitions/NetworkSecurityGroup"!
file:///Users/matthias/Documents/Work/someeng/azure-rest-api-specs/specification/network/resource-manager/Microsoft.Network/stable/2023-05-01/virtualNetwork.json#/definitions/VirtualNetwork
file:///Users/matthias/Documents/Work/someeng/azure-rest-api-specs/specification/network/resource-manager/Microsoft.Network/stable/2023-05-01/virtualNetwork.json#/definitions/VirtualNetworkPropertiesFormat
file:///Users/matthias/Documents/Work/someeng/azure-rest-api-specs/specification/network/resource-manager/Microsoft.Network/stable/2023-05-01/virtualNetwork.json#/definitions/Subnet
file:///Users/matthias/Documents/Work/someeng/azure-rest-api-specs/specification/network/resource-manager/Microsoft.Network/stable/2023-05-01/virtualNetwork.json#/definitions/SubnetPropertiesFormat
file:///Users/matthias/Documents/Work/someeng/azure-rest-api-specs/specification/network/resource-manager/Microsoft.Network/stable/2023-05-01/networkSecurityGroup.json#/definitions/NetworkSecurityGroup
file:///Users/matthias/Documents/Work/someeng/azure-rest-api-specs/specification/network/resource-manager/Microsoft.Network/stable/2023-05-01/networkSecurityGroup.json#/definitions/NetworkSecurityGroupPropertiesFormat
file:///Users/matthias/Documents/Work/someeng/azure-rest-api-specs/specification/network/resource-manager/Microsoft.Network/stable/2023-05-01/networkInterface.json#/definitions/NetworkInterface
file:///Users/matthias/Documents/Work/someeng/azure-rest-api-specs/specification/network/resource-manager/Microsoft.Network/stable/2023-05-01/networkInterface.json#/definitions/NetworkInterfacePropertiesFormat
file:///Users/matthias/Documents/Work/someeng/azure-rest-api-specs/specification/network/resource-manager/Microsoft.Network/stable/2023-05-01/networkSecurityGroup.json#/definitions/NetworkSecurityGroup

Maybe I need to do something differently.

Swagger can read the definition - so it seems valid Swagger 2.0 specs.

Expected Behaviour

prance can read Azure Rest API specs.

Minimal Example Spec

    "CloudErrorBody": {
      "properties": {
        "details": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/CloudErrorBody"
          },
          "description": "A list of additional details about the error."
        }
      }
    },

Actual Behaviour

Throwing an exception.

Steps to Reproduce

  • git clone https://github.com/Azure/azure-rest-api-specs.git
  • `p=ResolvingParser("azure-rest-api-specs/specification/network/resource-manager/Microsoft.Network/stable/2023-05-01/virtualNetwork.json")

Environment

  • OS: macos
  • Python version: 3.11.6
  • Swagger/OpenAPI version used: 2
  • Backend: I tried all 3: flex, swagger-spec-validator and openapi-spec-validator
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

1 participant