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

Can't resolve reference on valid spec #940

Open
jtburchfield opened this issue Jun 27, 2024 · 0 comments
Open

Can't resolve reference on valid spec #940

jtburchfield opened this issue Jun 27, 2024 · 0 comments

Comments

@jtburchfield
Copy link

jtburchfield commented Jun 27, 2024

Describe the bug

I get an error sending a request into my express api. I have validated my schema and also the schema generated from @apidevtools/json-schema-ref-parser and both are valid. When I use @apidevtools/json-schema-ref-parser to generate a json bundle, using $refParser.bundle, the schema produced has an internal link from updatedAt to createdAt, which seems to be the issue.

To Reproduce
Use the following schema:

openapi.yaml

---
openapi: 3.0.0
info:
  version: 1.0.0
  title: My Service
paths:
  /test:
    get:
      operationId: GetTest
      responses:
        '200':
          description: OK.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ReturnData'

components:
  schemas:
    ReturnData:
      type: object
      required:
        - createdAt
      properties:
        createdAt:
          $ref: './types.yaml#/components/schemas/DateTime'
        updatedAt:
          $ref: './types.yaml#/components/schemas/DateTime'

types.yaml

---
openapi: 3.0.0
info:
  version: 0.1.0
  title: Date/Time Types
paths: {}
components:
  schemas:
    DateTime:
      type: string
      format: date-time

If I modify the openapi.yaml file and remove the reference to the types.yaml file and hard-code the date-time format everything works
as expected.

Actual behavior
Error: can't resolve reference #/components/schemas/ReturnData/properties/createdAt from id #/components/schemas/ReturnData

Expected behavior
Validation successful

Generated by $refParser.bundle

    "openapi": "3.0.0",
    "info": {
        "version": "1.0.0",
        "title": "My Service"
    },
    "paths": {
        "/test": {
            "get": {
                "operationId": "GetTest",
                "responses": {
                    "200": {
                        "description": "OK.",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/ReturnData"
                                }
                            }
                        }
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "ReturnData": {
                "type": "object",
                "required": [
                    "createdAt"
                ],
                "properties": {
                    "createdAt": {
                        "type": "string",
                        "format": "date-time"
                    },
                    "updatedAt": {
                        "$ref": "#/components/schemas/ReturnData/properties/createdAt"
                    }
                }
            }
        }
    }
}
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