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

Don't resolve internal reference #423

Closed
mneumegen opened this issue Jun 23, 2020 · 1 comment
Closed

Don't resolve internal reference #423

mneumegen opened this issue Jun 23, 2020 · 1 comment

Comments

@mneumegen
Copy link

mneumegen commented Jun 23, 2020

I'm encountering what I believe is a bug (or maybe it's intended behavior) where I'm locally referencing a component which will be in the resolved output. Instead of keeping the local reference, speccy is changing it to an empty object.

Here's my test case:

# test.yml
---
openapi: 3.0.1
info: 
  title: My API
  version: v1
  contact:
    name: API Support
    url: https://example.com
    email: support@example.com
paths:
  "/users":
    "$ref": ./paths/users.yml
servers:
- url: https://api.example.com
components:
  schemas:
    user:
       "$ref": ./schemas/user.yml
# schemas/user.yml
---
type: object
properties:
  id:
    type: integer
    example: 4
  first_name:
    type: string
    example: Gandalf
  surname:
    type: string
    example: McKellen
  email:
    type: string
    format: email
    example: gandalf@example.com
  country:
    type: string
    example: The Shire
# paths/users.yml
---
get:
  summary: Gets the current user
  operationId: get-user
  responses:
    '200':
      description: ok
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/user'

My expected/desired output:

openapi: 3.0.1
info:
  title: My API
  version: v1
  contact:
    name: API Support
    url: https://example.com
    email: support@example.com
paths:
  /users:
    get:
      summary: Gets the current user
      operationId: get-user
      responses:
        "200":
          description: ok
          content:
            application/json:
              schema: '#/components/schemas/user'
servers:
  - url: https://api.example.com
components:
  schemas:
    user:
      type: object
      properties:
        id:
          type: integer
          example: 4
        first_name:
          type: string
          example: Gandalf
        surname:
          type: string
          example: McKellen
        email:
          type: string
          format: email
          example: gandalf@example.com
        country:
          type: string
          example: The Shire

Actual output running speccy resolve test.yml:

openapi: 3.0.1
info:
  title: My API
  version: v1
  contact:
    name: API Support
    url: https://example.com
    email: support@example.com
paths:
  /users:
    get:
      summary: Gets the current user
      operationId: get-user
      responses:
        "200":
          description: ok
          content:
            application/json:
              schema: {}
servers:
  - url: https://api.example.com
components:
  schemas:
    user:
      type: object
      properties:
        id:
          type: integer
          example: 4
        first_name:
          type: string
          example: Gandalf
        surname:
          type: string
          example: McKellen
        email:
          type: string
          format: email
          example: gandalf@example.com
        country:
          type: string
          example: The Shire

I want to define user once in components/schemas and reference it in many different paths. What would be the best way to achieve this?

@MikeRalphson
Copy link
Contributor

MikeRalphson commented Jun 24, 2020

This is definitely intended behaviour.

#/components/schemas/user is not in scope in paths/user.yml change it to a $ref to . /schemas/user.yml.

PS speccy is unmaintained.

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

2 participants