Giter VIP home page Giter VIP logo

Comments (5)

jamietanna avatar jamietanna commented on August 15, 2024

Thanks for the report - what's the use-case for having models that produce unexported fields?

Not saying that we won't fix it, but it's a a surprising use-case, so would be interested to hear why you're doing this @lukasbash

from oapi-codegen.

jamietanna avatar jamietanna commented on August 15, 2024

With the proposed code (from v2.1.0's behaviour), we end up receiving a go vet violation:

% go vet
# github.com/deepmap/oapi-codegen/v2/examples/extensions/x
./gen.go:14:2: struct field accountIdentifier has json tag but is not exported

from oapi-codegen.

lukasbash avatar lukasbash commented on August 15, 2024

@jamietanna We are using some unexported fields of models during internal processing which offers dynamic implementations on the server side. Sometimes we are using those fields for performance optimizations whereas the clients do not need those fields e.g. when the model is part of a JSON response.

Ironically - with regard to your latest reply - for those unexported fields we usually comply with omitting field tags like:

# ...
            x-oapi-codegen-extra-tags:
              json: "-"
              gorm: "-"
              foo: "-"
              bar: "-"
# ...

What implementation/usage do you suggest? Throwing an error on generation when an unexported field contains a tag? Or do you state that generated files might not be fully lint-compliant and people have to exclude those from linting?

EDIT: The vet violation was not present in v2.1.0? Strange, because I would guess that the tag implementation didn't change for this, did it?

from oapi-codegen.

jamietanna avatar jamietanna commented on August 15, 2024

The vet violation was not present in v2.1.0?

In the v2.1.0 code we didn't have any cases in the codebase which would rely on producing unexported fields, which is why we wouldn't have seen any violations. I can imagine that if we did, we would've fixed the violation.

It's not something I'd like to recommend is done by default, but I think it'd be OK to add it in as an opt-in feature - would that work for you?

If so, I'd be happy if you want to contribute it? Although we've not yet got a "howto" doc on doing this, af43038 is a recent example that should give a good indication of how to add it in?

from oapi-codegen.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.