swagger-api / swagger-api/swagger-parser

Nested references are not resolved for local files

Open
#764 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
867
Forks
560
Avg merge
2d 21h
Merged PRs (30d)
7

Description

If #454 testcases are changed to use a relative file reference, the nested definitions are not resolved.

tags:
- name: admins
  description: Secured Admin-only calls
- name: developers
  description: Operations available to regular developers
paths:
  /inventory:
    get:
      summary: searches inventory test
      operationId: searchInventory
      responses:
        200:
          description: search results matching criteria
        default:
          $ref: './issue-454-file-components.yaml#/responses/GeneralError'
definitions:
  ModelWithNestedProperties:
    properties:
      remoteProperty:
        $ref: './issue-454-file-components.yaml#/definitions/RemoteComponent'

Test case:

    @Test
    public void testNestedFileRefs() {
        Swagger swagger = new SwaggerParser().read("src/test/resources/nested-file-references/issue-454-file.yaml",
                null, true);

        assertNotNull(swagger.getDefinitions().get("ErrorModel"));
        assertNotNull(swagger.getDefinitions().get("ModelWithNestedProperties"));

        ModelImpl model = (ModelImpl)swagger.getDefinitions().get("ModelWithNestedProperties");
        Property property = model.getProperties().get("remoteProperty");
        assertNotNull(property);
        assertTrue(property instanceof RefProperty);
        RefProperty ref = (RefProperty) property;
        assertEquals(ref.get$ref(), "#/definitions/RemoteComponent");
        assertNotNull(swagger.getDefinitions().get("NestedProperty"));

        ModelImpl nestedModel = (ModelImpl)swagger.getDefinitions().get("NestedProperty");
        assertNotNull(nestedModel);
        assertNotNull(nestedModel.getProperties().get("name"));
        assertTrue(nestedModel.getProperties().get("name") instanceof StringProperty);
    }

The attached tar ball contains a testcase and test data to reproduce the issue.
test.tar.gz

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the nested-file-references/issue-454-file.yaml fixture and run SwaggerParser.read as shown in testNestedFileRefs. Compare the resolved definitions and remoteProperty reference with the assertions in the test; done means the nested references resolve and all listed assertions pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, yaml
Domain
backend-api-design
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.