Skip to content

Have an option to create directories if they don't already exist #1052

Closed

Description

@renxinhe

I'm getting the following error, because my repo currently only has "pkg/entity", and "oapimodel/" doesn't already exist.

//go:generate oapi-codegen -package oapimodel -generate types,skip-prune -o pkg/entity/oapimodel/oapimodel.gen.go openapi_spec.yaml

error writing generated code to file: open pkg/entity/oapimodel/oapimodel.gen.go: no such file or directory

I'm wonder if we can quickly support some input flag, or modify the default behavior, to create the necessary directories to support any destination path?

Activity

  1. jamietanna commented on Jun 29, 2023

    @jamietanna
    Member

    I would recommend probably something like the following in the short term:

    //go:generate mkdir -p pkg/entity/oapimodel
    //go:generate oapi-codegen -package oapimodel -generate types,skip-prune -o pkg/entity/oapimodel/oapimodel.gen.go openapi_spec.yaml
    

    This appears to be the first time I've seen this happen, usually the codegen is done to the same location as the go:generate directives.

    This is something I think that we'd be happy to get a PR raised for, but in the meantime, feel free to use a hacky solution like above 😁

  2. added
    enhancement
    help wanted
    on Jun 29, 2023
  3. renxinhe commented on Jun 29, 2023

    @renxinhe
    Author

    Thanks @jamietanna! That's exactly what I did. Not the prettiest, but hey it works! Hope to see a quality-of-life improvement in a future release!

  4. added
    bug
    and removed
    enhancement
    on Jul 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bughelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions