oapi-codegen icon indicating copy to clipboard operation
oapi-codegen copied to clipboard

Using allOf with $ref to json schema errors with "unsupported reference"

Open octomad opened this issue 3 years ago • 0 comments

The generator fails to generate a spec when the schemas use a $ref that points to an external JSON schema. This was previously working in v1.11.0. Now broken in v1.12.x.

Sample spec file

openapi: 3.0.0
x-stoplight:
  id: hvun3hw84a2v8
info:
  title: ref-bug
  version: '1.0'
  description: yay
  contact:
    name: Example
servers:
  - url: 'http://localhost:3000'
paths:
  '/users/{userId}':
    parameters:
      - schema:
          type: integer
        name: userId
        in: path
        required: true
        description: Id of an existing user.
    get:
      summary: Get User Info by User ID
      tags: []
      responses:
        '200':
          description: User Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/User'
      operationId: get-users-userId
      description: Retrieve the information of the user with the matching user ID.
components:
  schemas:
    User:
      allOf:
        - $ref: 'https://edgio.github.io/hyperion/schema/node.json'
        - type: object
          additionalProperties: false
          properties:
            name:
              type: string
              description: User name
          required:
            - id
      title: user
      description: Represents a `user`

Results in Error message:

error generating code: error generating type definitions: error generating Go types for component schemas: error converting Schema User to Go type: error merging schemas: unsupported reference: https://edgio.github.io/hyperion/schema/node.json

octomad avatar Jan 26 '23 00:01 octomad