-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
sebgl/oapi-codegen
#1Description
I am trying to split my specs into multiple files in order be able to produce different output files within the same package. As oapi-codegen considers any external file reference to be an "externalRef" I must supply an import mapping for this. As the generated files are in the same package this leads to attempting to import the current package which is not allowed in go.
Here is an example that reproduces the issue:
- a.yaml:
openapi: 3.0.0
info:
title: a
version: 0.0.1
paths: {}
components:
schemas:
A:
properties:
foo:
type: string- b.yaml
openapi: 3.0.0
info:
title: b
version: 0.0.1
paths: {}
components:
schemas:
B:
$ref: a.yaml#/components/schemas/AWithout import mapping supplied:
$ oapi-codegen -package scratch -generate types,skip-prune b.yaml > b.gen.go
error generating code: error generating type definitions: error generating Go types for component schemas: error converting Schema B to Go type: error turning reference (a.yaml#/components/schemas/A) into a Go type: unrecognized external reference 'a.yaml'; please provide the known import for this reference using option --import-mapping
With import mapping supplied:
$ oapi-codegen -import-mapping a.yaml:scratch -package scratch -generate types,skip-prune b.yaml > b.gen.go
$ go build
package scratch
imports scratch: import cycle not allowed
I was able to get this working modifying codegen/utils.go to check whether a remote component referred to a file within the same directory & treating it as a local ref. I was wondering if you would like me to make a PR to fix this.
Thanks
duffn, sebgl, bn-k, jabielecki, ysulyma and 6 more
Metadata
Metadata
Assignees
Labels
No labels