Skip to content

Reference error when using import-mapping #511

@valensto

Description

@valensto

Hi, hope you all are fine!

Trying to use a common schema for my project, but I've an error in swagger UI:

Resolver error at paths./users.post.responses.default.content.application/json.schema.$ref Could not resolve reference: undefined undefined

When I put all in the same file spec.yaml and generate it all work but if I try to separe Error schema to a common package I got this err

  • common
  • user

in a common folder I've only

components:
  schemas:
    Error:
      type: object
      properties:
        message:
          type: string

In user one

...
paths:
  /users:
    post:
      ...
      responses:
        '201':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/User'
        default:
          content:
            application/json:
              schema:
                $ref: '../common/spec.yaml#/components/schemas/Error'

components:
  schemas:
    User:
      type: object
      properties:
        id:
          type: integer
          format: int32
        lastname:
          type: string
        firstname:
          type: string
        created_at:
          type: string
          format: date-time

the User schema work but not the Error one, I don't have error when I generate only in the UI

the command line for user spec.yaml
oapi-codegen -generate types,skip-prune,spec,chi-server -package user -o ./user/openapi_types.gen.go --import-mapping=../common/spec.yaml:distrustia.com/main_api/api/common ./user/spec.yaml

the command line for the common spec.yaml

oapi-codegen -generate types,skip-prune,spec -package common -o ./common/openapi_types.gen.go ./common/spec.yaml

I tried to use the example provide about external ref but same problem

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions