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

External reference to relative file not working. #1045

Open
ainsleyclark opened this issue May 11, 2023 · 2 comments
Open

External reference to relative file not working. #1045

ainsleyclark opened this issue May 11, 2023 · 2 comments

Comments

@ainsleyclark
Copy link

ainsleyclark commented May 11, 2023

Hey,

Having problems to reference a schema in a separate file.

paths:
    "/domains":
        get:
            description: List all Domains
            operationId: ListDomains
            tags:
                - domains
            responses:
                202:
                    description: Test
                    content:
                        application/json:
                            schema:
                                $ref: "./schemas/Domain.yaml" #Doesn't work.
#                                $ref: "#/components/schemas/Domain" #Works
components:
    schemas:
        Domain:
            $ref: "./schemas/Domain.yaml"

Any ideas what I could be doing wrong? Ideally I would like to reference them relatively as I would like to put the paths in a separate folder under /resources. I.e

/resources/domains.yaml

get:
    description: List all Domains
    operationId: ListDomains
    tags:
        - domains
    responses:
        202:
            description: List Domain items.
            content:
                application/json:
                    schema:
                        $ref: "../schemas/Domain.yaml"
        default:
            $ref: '../responses/Error.yaml'
@awildeep
Copy link

I think this is related to my issue trying to build the client for: https://github.com/SpaceTradersAPI/api-docs/blob/main/reference/SpaceTraders.json

References are in the same project.

To reproduce I did the following:

  • git clone git@github.com:SpaceTradersAPI/api-docs.git
  • cd api-docs/reference
  • oapi-codegen -generate types -o space_traders.types.gen.go -package main api-docs/reference/SpaceTraders.json
  • oapi-codegen -generate client -o space_traders.client.gen.go -package main api-docs/reference/SpaceTraders.json

After generation, attempting to use the generated code yields many, many errors; like:

  • undefined: N200DataTraitsSymbol
  • undefined: N200DataType

@jamietanna
Copy link
Member

Hey, you may be needing to use the import-mapping config from https://github.com/deepmap/oapi-codegen#using-oapi-codegen ?

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

3 participants