Comments (5)
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.
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.
@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.
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)
- Enum constants not prefixed with type name
- chore(tests): add better coverage of `mergeOpenapiSchemas`
- Make possible use values other than strings as discriminator
- requestBody with oneOf does not generate marshal/unmarshal union data
- Bug: Header parameter parsing with fiber generator
- Generating Struct with Embedded Imported Type
- swaggerSpec updated even when no spec changes HOT 1
- field std-http-server not found in type codegen.GenerateOptions HOT 2
- docs: warn when using `std-http-server` but /not/ using Go 1.22 HOT 4
- Config to generate server interface only HOT 2
- Support two dimensional query parameters
- docs(examples): how to use context keys with middleware HOT 1
- feat: make enum union/intersection generation more configurable
- chore: bump minimum Go version
- Support multiple authentication schemes for a single endpoint HOT 6
- response during file download error HOT 1
- Problems installing v2.2.0 HOT 5
- From and To paths are the same
- feat: Server/Global prefix/suffix cli option
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from oapi-codegen.