gnostic icon indicating copy to clipboard operation
gnostic copied to clipboard

Improve handling of references.

Open timburks opened this issue 9 years ago • 2 comments

OpenAPI descriptions with large numbers of repeated $refs can take a long time to resolve. This is because we explicitly expand all $refs.

For example, this runs much faster with --keep_refs than without it: openapic --sample_out=- https://api.apis.guru/v2/specs/bitbucket.org/2.0/swagger.yaml --keep_refs

A better approach would be to keep $refs in place but still expand each unique $ref and store the expansion in the compiled protos so it could be easily used in client code when needed.

timburks avatar Dec 21 '16 17:12 timburks

This will be required to handle recursive definitions like this one (in the bitbucket spec linked above):

  base_commit:
    allOf:
      - $ref: '#/definitions/object'
      - additionalProperties: true
        description: The common base type for both repository and snippet commits.
        properties:
          author:
            $ref: '#/definitions/account'
          date:
            format: date-time
            type: string
          hash:
            pattern: '[0-9a-f]{7,}?'
            type: string
          message:
            type: string
          parents:
            items:
              $ref: '#/definitions/base_commit'
            minItems: 0
            type: array
        type: object

Fortunately, $refs are limited to objects in the "definitions" area, which may already have the parsed protos that we need to resolve $refs at application run time.

timburks avatar Dec 21 '16 18:12 timburks

As a partial improvement, --keep_refs has been replaced by --resolve_refs and automatic reference resolution is no longer the default behavior.

timburks avatar Dec 21 '16 18:12 timburks