Skip to content

Using a reference in items of array results in error #464

New issue

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

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

Already on GitHub? # to your account

Open
pmhofman opened this issue Feb 15, 2023 · 3 comments · May be fixed by #470
Open

Using a reference in items of array results in error #464

pmhofman opened this issue Feb 15, 2023 · 3 comments · May be fixed by #470

Comments

@pmhofman
Copy link

When a reference is used in items: of an array, e.g. :

type: object
description: Model for response from call to GET products requiring an array of products to be returned.
title: GetProductResponse
properties:
  Products:
    type: array
    items:
      $ref: Product.yaml

and error is thrown while resolving the references:

$ java -jar openapi-diff-cli-2.1.0-beta.4-all.jar --error --fail-on-incompatible source/specification/openapi.yaml destination/specification/openapi.yaml
Unexpected exception. Reason: Invalid ref: ./common/models/Product.yaml
java.lang.IllegalArgumentException: Invalid ref: ./common/models/Product.yaml
        at org.openapitools.openapidiff.core.utils.RefPointer.getRefName(RefPointer.java:60)
        at org.openapitools.openapidiff.core.utils.RefPointer.resolveRef(RefPointer.java:16)
        at org.openapitools.openapidiff.core.compare.SchemaDiff.computeDiffForReal(SchemaDiff.java:337)
        at org.openapitools.openapidiff.core.model.deferred.DeferredSchemaCache.processSchemaQueue(DeferredSchemaCache.java:86)
        at org.openapitools.openapidiff.core.model.deferred.DeferredSchemaCache.process(DeferredSchemaCache.java:64)
        at org.openapitools.openapidiff.core.compare.OpenApiDiff.compare(OpenApiDiff.java:100)
        at org.openapitools.openapidiff.core.compare.OpenApiDiff.compare(OpenApiDiff.java:64)
        at org.openapitools.openapidiff.core.OpenApiCompare.fromSpecifications(OpenApiCompare.java:102)
        at org.openapitools.openapidiff.core.OpenApiCompare.fromLocations(OpenApiCompare.java:91)
        at org.openapitools.openapidiff.cli.Main.main(Main.java:175)

Files GetProductResponse.yaml and Product.yaml both reside in the same directory.

Attachment contains the source and destination folders, which contain a copy of the same openapi spec.
example.zip

@joschi
Copy link
Contributor

joschi commented Feb 26, 2023

@pmhofman Thanks for reporting this!

It looks like an issue with the reference resolution in the upstream project https://github.com/swagger-api/swagger-parser/.

Would you mind creating a bug report there and link it back to this issue?

@pmhofman
Copy link
Author

pmhofman commented Mar 1, 2023

swagger-api/swagger-parser#1889 created

@DrSatyr DrSatyr removed the bug label Jan 30, 2025
@DrSatyr
Copy link
Collaborator

DrSatyr commented Jan 30, 2025

I've just checked a codebase: org.openapitools.openapidiff.core.utils.RefPointer - is a openapi-diff implementation for resolving a references. But it does not support a lot of cases, in particular ref resolving from files. We already have #272 to address it.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants