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

Reference resolution fails for project with mix of subfolders and classpath references #1891

Closed
douglasbgray opened this issue Mar 13, 2023 · 1 comment

Comments

@douglasbgray
Copy link

douglasbgray commented Mar 13, 2023

if a project is configured as follows ...

src/main/resources/
    ├── openapi.yaml
    ├── types/
        ├── local-types.yaml

... and a model in openapi.yaml has a reference to a model in local-types.yaml, and in turn, that model is an alias to a model found in a classpath resource, then the reference is not resolved.

Example

openapi.yaml (root contract)

LocalModel:
  type: object
  properties:
    sharedModelField:
      $ref: 'types/local-types.yaml#/components/schemas/TypesModel'

local-types.yaml (exists in types folder sibling to root contract)

TypesModel:
  $ref: '/shared-types.yaml#/components/schemas/SharedModel'

shared-types.yaml (this is in shared-types.yaml resource in the classpath, not in file system)

SharedModel:
  type: object
  properties:
    name:
      type: string

The parser attempts to find resolve the reference to /shared-types.yaml by prepending the path of the local types directory, so it looks for types/shared-types.yaml and does not find it. This leave the reference unresolved.

Since the parser is unable to resolve the references, this affects downstream code generation, which creates invalid types for some properties.

A project with a unit test demonstrating the issue is here - https://github.com/douglasbgray/cp-example

This is first observed in version 2.0.24 and still exists in the most recent version 2.1.12.

Here is a PR with a fix and corresponding test - #1892

@douglasbgray
Copy link
Author

PR was merged, issue was resolved. Closing.

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