Skip to content

use $ref to point to pre-existing types and being able to import them #195

@dududko

Description

@dududko

I need to be able to reference in openapi to types, that pre-exist in some packages and I want to be able to import them in the generated code.

It is a very handy feature which I really need in my project. Without it I have to merge multiple openapi specs and write manually (or generate) type converters.

This feature is implemented in vanilla openapi-generator. They claim that it is posible to import existing types using option --import-mappings.
https://openapi-generator.tech/docs/usage/#target-external-models
Unfortunately this option seem to work proper only in java, I can confirm that it does not work for go and ts, and I found evidence that it also does not work for python and Kotlin. Also this feature lacks the examples. Nevertheless, I managed to implement this feature for ts generator by doing post-processing of generated files. It is important to point that I could achieve this only because vanilla openapi has option --skip-validate-spec.

I tried to find a solution for oapi-codegen to be able to introduce this feature. Unfortunately I almost instantly failed, because oapi-codegen always validates the spec. To be more precise, github.com/getkin/kin-openapi validates the spec when it parses the file. It means that to implement this feature, I will have to somehow generate a valid spec with valid imports which I later could modify by knowing which structs are external.

I would like to ask the community if anyone else need this feature ? Do you think that it should be implemented for deepmap/oapi ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions